mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tutorials: fix blog code
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user