highscore-server/src/database.v

39 lines
687 B
Coq
Raw Normal View History

2023-01-07 13:00:00 +01:00
module main
[table: 'Score']
2023-01-07 13:00:00 +01:00
struct ScoreRes {
mut:
id i64 [primary; sql: serial]
player string [nonull]
score int [nonull]
time i64 [nonull]
2023-01-07 13:00:00 +01:00
}
fn (mut app App) create_tables() {
sql app.db {
create table ScoreRes
}
2023-01-07 13:00:00 +01:00
}
fn (mut app App) insert_score(score ScoreRes) ScoreRes {
2023-01-11 19:08:24 +01:00
sql app.db {
insert score into ScoreRes
}
last_id := app.db.last_id() as int
2023-01-11 19:08:24 +01:00
return sql app.db {
select from ScoreRes where id == last_id
2023-01-11 19:08:24 +01:00
}
2023-01-07 13:00:00 +01:00
}
fn (mut app App) get_scores() []ScoreRes {
2023-01-11 19:08:24 +01:00
return sql app.db {
select from ScoreRes order by score desc limit 1000
2023-01-11 19:08:24 +01:00
}
2023-01-07 13:00:00 +01:00
}
fn (mut app App) delete_score(score_id int) {
2023-01-11 19:08:24 +01:00
sql app.db {
delete from ScoreRes where id == score_id
}
2023-01-07 13:00:00 +01:00
}