diff --git a/Dockerfile b/Dockerfile index dca6007..b6f26cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM thevlang/vlang:alpine AS build +FROM git.snrd.eu/sunred/vlang:alpine AS build WORKDIR /tmp/app COPY . . diff --git a/docker.bake.hcl b/docker-bake.hcl similarity index 100% rename from docker.bake.hcl rename to docker-bake.hcl diff --git a/src/database.v b/src/database.v index c7ef6d7..e0cc7ab 100644 --- a/src/database.v +++ b/src/database.v @@ -9,30 +9,30 @@ mut: time i64 [nonull] } -fn (mut app App) create_tables() { +fn (mut app App) create_tables() ! { sql app.db { create table ScoreRes - } + }! } -fn (mut app App) insert_score(score ScoreRes) ScoreRes { +fn (mut app App) insert_score(score ScoreRes) !ScoreRes { sql app.db { insert score into ScoreRes - } + }! last_id := app.db.last_id() as int return sql app.db { 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 { 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 { delete from ScoreRes where id == score_id - } + }! } diff --git a/src/main.v b/src/main.v index 5f38925..6409910 100644 --- a/src/main.v +++ b/src/main.v @@ -34,13 +34,10 @@ fn main() { panic(err) } - app.create_tables() - - // orm does not yet return Results - // if sqlite.is_error(sql_code) { - // println('Could not create tables!') - // panic('Error code ' + sql_code.str()) - // } + app.create_tables() or { + println('Could not create database tables!') + panic(err) + } mut host := '::' if app_config.host.len != 0 { diff --git a/src/web.v b/src/web.v index 57389d4..b74b368 100644 --- a/src/web.v +++ b/src/web.v @@ -29,7 +29,9 @@ pub fn (mut app App) score_list() vweb.Result { 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) } @@ -64,7 +66,7 @@ pub fn (mut app App) score_submit() vweb.Result { player: body.player score: body.score time: time.now().unix_time() - }) + }) or { return app.json(Status{500, 'A database error occurred while inserting score'}) } return app.json(score) }