Change vlang build image, use latest V ORM returning Results
This commit is contained in:
parent
e6f94b8e3b
commit
674aa90c49
5 changed files with 18 additions and 19 deletions
|
@ -1,4 +1,4 @@
|
|||
FROM thevlang/vlang:alpine AS build
|
||||
FROM git.snrd.eu/sunred/vlang:alpine AS build
|
||||
|
||||
WORKDIR /tmp/app
|
||||
COPY . .
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}!
|
||||
}
|
||||
|
|
11
src/main.v
11
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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue