Skip to content

Commit b80dcaf

Browse files
author
Georg Hartmann
authored
tutorials: always add the filename as first comment in example files (#10594)
1 parent 9651a97 commit b80dcaf

File tree

1 file changed

+12
-0
lines changed
  • tutorials/building_a_simple_web_blog_with_vweb

1 file changed

+12
-0
lines changed

tutorials/building_a_simple_web_blog_with_vweb/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Vweb often uses convention over configuration and adding a new action requires
9999
no routing rules either:
100100

101101
```v oksyntax
102+
// blog.v
102103
import vweb
103104
import time
104105
@@ -138,6 +139,7 @@ Let's return an HTML view instead. Create `index.html` in the same directory:
138139
and update our `index()` action so that it returns the HTML view we just created:
139140

140141
```v ignore
142+
// blog.v
141143
pub fn (mut app App) index() vweb.Result {
142144
message := 'Hello, world from Vweb!'
143145
return $vweb.html()
@@ -185,6 +187,7 @@ We'll be using V's builtin ORM and a SQLite database.
185187

186188
Create a SQLite file with the schema:
187189
```sql
190+
-- blog.sqlite
188191
drop table if exists Article;
189192

190193
create table Article (
@@ -210,6 +213,7 @@ Run the file with `sqlite3 blog.db < blog.sqlite`.
210213
Add a SQLite handle to `App`:
211214

212215
```v oksyntax
216+
// blog.v
213217
import sqlite
214218
import vweb
215219
@@ -225,6 +229,7 @@ mut:
225229
Add the `init_server()` method where we'll connect to a database:
226230

227231
```v oksyntax
232+
// blog.v
228233
pub fn (mut app App) init_server() {
229234
db := sqlite.connect(':memory:') or { panic(err) }
230235
db.exec('create table `Article` (id integer primary key, title text default "", text text default "")')
@@ -260,6 +265,7 @@ pub fn (app &App) find_all_articles() []Article {
260265
Let's fetch the articles in the `index()` action:
261266

262267
```v ignore
268+
// blog.v
263269
pub fn (app &App) index() vweb.Result {
264270
articles := app.find_all_articles()
265271
return $vweb.html()
@@ -292,6 +298,8 @@ The built-in V ORM uses a syntax very similar to SQL. The queries are built with
292298
For example, if we only wanted to find articles with ids between 100 and 200, we'd do:
293299

294300
```v oksyntax
301+
// article.v
302+
295303
return sql app.db {
296304
select from Article where id >= 100 && id <= 200
297305
}
@@ -300,6 +308,7 @@ return sql app.db {
300308
Retrieving a single article is very simple:
301309

302310
```v oksyntax
311+
// article.v
303312
pub fn (app &App) retrieve_article() ?Article {
304313
return sql app.db {
305314
select from Article limit 1
@@ -311,6 +320,7 @@ V ORM uses V's optionals for single values, which is very useful, since
311320
bad queries will always be handled by the developer:
312321

313322
```v oksyntax
323+
// article.v
314324
article := app.retrieve_article(10) or {
315325
app.text('Article not found')
316326
return
@@ -338,6 +348,7 @@ Create `new.html`:
338348
```
339349

340350
```v oksyntax
351+
// article.v
341352
import vweb
342353
343354
pub fn (mut app App) new_article() vweb.Result {
@@ -376,6 +387,7 @@ to render everything on the client or need an API, creating JSON endpoints
376387
in V is very simple:
377388

378389
```v oksyntax
390+
// article.v
379391
import vweb
380392
import json
381393

0 commit comments

Comments
 (0)