39 lines
687 B
V
39 lines
687 B
V
module main
|
|
|
|
[table: 'Score']
|
|
struct ScoreRes {
|
|
mut:
|
|
id i64 [primary; sql: serial]
|
|
player string [nonull]
|
|
score int [nonull]
|
|
time i64 [nonull]
|
|
}
|
|
|
|
fn (mut app App) create_tables() {
|
|
sql app.db {
|
|
create table 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
|
|
}
|
|
}
|
|
|
|
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) {
|
|
sql app.db {
|
|
delete from ScoreRes where id == score_id
|
|
}
|
|
}
|