tutorials: fix blog code
parent
7bcc5afbb6
commit
0c77bdf8f6
|
@ -117,7 +117,7 @@ jobs:
|
|||
- name: Test v tutorials
|
||||
run: |
|
||||
cd tutorials/code/blog
|
||||
v .
|
||||
../../../v .
|
||||
|
||||
|
||||
# Alpine docker pre-built container
|
||||
|
|
|
@ -7,6 +7,7 @@ import json
|
|||
|
||||
struct App {
|
||||
vweb.Context
|
||||
mut:
|
||||
db sqlite.DB
|
||||
}
|
||||
|
||||
|
@ -31,8 +32,12 @@ pub fn (app &App) index() vweb.Result {
|
|||
}
|
||||
|
||||
pub fn (mut app App) init_once() {
|
||||
db := sqlite.connect('blog.db') or { panic(err) }
|
||||
app.db = db
|
||||
app.db = sqlite.connect('blog.db') or { panic(err) }
|
||||
app.db.exec('create table if not exists article (' +
|
||||
'id integer primary key, ' +
|
||||
"title text default ''," +
|
||||
"text text default ''" +
|
||||
');')
|
||||
}
|
||||
|
||||
pub fn (mut app App) init() {
|
||||
|
@ -42,6 +47,8 @@ pub fn (mut app App) new() vweb.Result {
|
|||
return $vweb.html()
|
||||
}
|
||||
|
||||
[post]
|
||||
['/new_article']
|
||||
pub fn (mut app App) new_article() vweb.Result {
|
||||
title := app.form['title']
|
||||
text := app.form['text']
|
||||
|
@ -53,6 +60,7 @@ pub fn (mut app App) new_article() vweb.Result {
|
|||
title: title
|
||||
text: text
|
||||
}
|
||||
println('posting article')
|
||||
println(article)
|
||||
sql app.db {
|
||||
insert article into Article
|
||||
|
|
|
@ -150,7 +150,6 @@ pub fn (db DB) exec(query string) ([]Row, int) {
|
|||
}
|
||||
rows << row
|
||||
}
|
||||
|
||||
C.sqlite3_finalize(stmt)
|
||||
return rows, res
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue