mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tutorials: blog fixes (#5652)
This commit is contained in:
parent
765ffa37eb
commit
56ad6cef54
@ -8,6 +8,6 @@ struct Article {
|
|||||||
|
|
||||||
pub fn (app &App) find_all_articles() []Article {
|
pub fn (app &App) find_all_articles() []Article {
|
||||||
return sql app.db {
|
return sql app.db {
|
||||||
select from Article
|
select from Article
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import json
|
|||||||
struct App {
|
struct App {
|
||||||
pub mut:
|
pub mut:
|
||||||
vweb vweb.Context
|
vweb vweb.Context
|
||||||
db sqlite.DB
|
db sqlite.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -25,28 +25,30 @@ fn (app &App) index_html() {
|
|||||||
$vweb.html()
|
$vweb.html()
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fn (app &App) index() vweb.Result {
|
fn (app &App) index() vweb.Result {
|
||||||
articles := app.find_all_articles()
|
articles := app.find_all_articles()
|
||||||
return $vweb.html()
|
return $vweb.html()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut app App) init_once() {
|
pub fn (mut app App) init_once() {
|
||||||
db := sqlite.connect(':memory:') or { panic(err) }
|
db := sqlite.connect(':memory:') or {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
db.exec('create table `Article` (id integer primary key, title text default "", text text default "")')
|
||||||
app.db = db
|
app.db = db
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut app App) init() {
|
pub fn (mut app App) init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut app App) new() vweb.Result{
|
pub fn (mut app App) new() vweb.Result {
|
||||||
return $vweb.html()
|
return $vweb.html()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut app App) new_article() vweb.Result {
|
pub fn (mut app App) new_article() vweb.Result {
|
||||||
title := app.vweb.form['title']
|
title := app.vweb.form['title']
|
||||||
text := app.vweb.form['text']
|
text := app.vweb.form['text']
|
||||||
if title == '' || text == '' {
|
if title == '' || text == '' {
|
||||||
app.vweb.text('Empty text/titile')
|
app.vweb.text('Empty text/titile')
|
||||||
return vweb.Result{}
|
return vweb.Result{}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user