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