From 56ad6cef543fee684a13299c23f143bd8cfac145 Mon Sep 17 00:00:00 2001 From: Louis Schmieder Date: Sat, 4 Jul 2020 11:38:47 +0200 Subject: [PATCH] tutorials: blog fixes (#5652) --- tutorials/code/blog/article.v | 2 +- tutorials/code/blog/blog.v | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tutorials/code/blog/article.v b/tutorials/code/blog/article.v index 66f86520f2..1db3e025f8 100644 --- a/tutorials/code/blog/article.v +++ b/tutorials/code/blog/article.v @@ -8,6 +8,6 @@ struct Article { pub fn (app &App) find_all_articles() []Article { return sql app.db { - select from Article + select from Article } } diff --git a/tutorials/code/blog/blog.v b/tutorials/code/blog/blog.v index a31273473c..2774fcb51d 100644 --- a/tutorials/code/blog/blog.v +++ b/tutorials/code/blog/blog.v @@ -8,7 +8,7 @@ import json struct App { pub mut: vweb vweb.Context - db sqlite.DB + db sqlite.DB } fn main() { @@ -25,28 +25,30 @@ fn (app &App) index_html() { $vweb.html() } */ - fn (app &App) index() vweb.Result { articles := app.find_all_articles() return $vweb.html() } 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 } 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() } pub fn (mut app App) new_article() vweb.Result { title := app.vweb.form['title'] text := app.vweb.form['text'] - if title == '' || text == '' { + if title == '' || text == '' { app.vweb.text('Empty text/titile') return vweb.Result{} }