Change vlang build image, use latest V ORM returning Results

This commit is contained in:
Manuel 2023-04-07 10:48:02 +02:00
parent e6f94b8e3b
commit 674aa90c49
Signed by: Manuel
GPG key ID: 4085037435E1F07A
5 changed files with 18 additions and 19 deletions

View file

@ -1,4 +1,4 @@
FROM thevlang/vlang:alpine AS build FROM git.snrd.eu/sunred/vlang:alpine AS build
WORKDIR /tmp/app WORKDIR /tmp/app
COPY . . COPY . .

View file

@ -9,30 +9,30 @@ mut:
time i64 [nonull] time i64 [nonull]
} }
fn (mut app App) create_tables() { fn (mut app App) create_tables() ! {
sql app.db { sql app.db {
create table ScoreRes create table ScoreRes
} }!
} }
fn (mut app App) insert_score(score ScoreRes) ScoreRes { fn (mut app App) insert_score(score ScoreRes) !ScoreRes {
sql app.db { sql app.db {
insert score into ScoreRes insert score into ScoreRes
} }!
last_id := app.db.last_id() as int last_id := app.db.last_id() as int
return sql app.db { return sql app.db {
select from ScoreRes where id == last_id select from ScoreRes where id == last_id
} }![0] or { ScoreRes{} }
} }
fn (mut app App) get_scores() []ScoreRes { fn (mut app App) get_scores() ![]ScoreRes {
return sql app.db { return sql app.db {
select from ScoreRes order by score desc limit 1000 select from ScoreRes order by score desc limit 1000
} }!
} }
fn (mut app App) delete_score(score_id int) { fn (mut app App) delete_score(score_id int) ! {
sql app.db { sql app.db {
delete from ScoreRes where id == score_id delete from ScoreRes where id == score_id
} }!
} }

View file

@ -34,13 +34,10 @@ fn main() {
panic(err) panic(err)
} }
app.create_tables() app.create_tables() or {
println('Could not create database tables!')
// orm does not yet return Results panic(err)
// if sqlite.is_error(sql_code) { }
// println('Could not create tables!')
// panic('Error code ' + sql_code.str())
// }
mut host := '::' mut host := '::'
if app_config.host.len != 0 { if app_config.host.len != 0 {

View file

@ -29,7 +29,9 @@ pub fn (mut app App) score_list() vweb.Result {
return app.json(Status{401, 'Access token is wrong or missing'}) return app.json(Status{401, 'Access token is wrong or missing'})
} }
scores := app.get_scores() scores := app.get_scores() or {
return app.json(Status{500, 'An error occurred while retrieving score list'})
}
return app.json(scores) return app.json(scores)
} }
@ -64,7 +66,7 @@ pub fn (mut app App) score_submit() vweb.Result {
player: body.player player: body.player
score: body.score score: body.score
time: time.now().unix_time() time: time.now().unix_time()
}) }) or { return app.json(Status{500, 'A database error occurred while inserting score'}) }
return app.json(score) return app.json(score)
} }