tutorials: fix blog code

pull/7792/head
Alexander Medvednikov 2021-01-01 20:38:22 +01:00
parent 7bcc5afbb6
commit 0c77bdf8f6
3 changed files with 11 additions and 4 deletions

View File

@ -117,7 +117,7 @@ jobs:
- name: Test v tutorials
run: |
cd tutorials/code/blog
v .
../../../v .
# Alpine docker pre-built container

View File

@ -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

View File

@ -150,7 +150,6 @@ pub fn (db DB) exec(query string) ([]Row, int) {
}
rows << row
}
C.sqlite3_finalize(stmt)
return rows, res
}