Created
January 31, 2022 13:51
-
-
Save xy3/47bf1f61af6cc46ab58dcf2da57e8f96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import vweb | |
| import sqlite | |
| struct App { | |
| vweb.Context | |
| pub mut: | |
| db sqlite.DB | |
| } | |
| fn main() { | |
| mut app := App{ | |
| db: sqlite.connect(':memory:') or { panic(err) } | |
| } | |
| sql app.db { | |
| create table Movie | |
| } | |
| vweb.run(app, 8081) | |
| } | |
| struct Movie { | |
| id int [primary; sql: serial] | |
| name string | |
| rating f32 | |
| tagline string | |
| summary string | |
| description string | |
| hash string | |
| imdbid int | |
| tmdbid int | |
| video_id int | |
| } | |
| ['/movie/:id'] | |
| fn (mut app App) movie(id int) vweb.Result { | |
| return app.json(sql app.db { | |
| select from Movie where id == id | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment