highscore-server/src/database.v

34 lines
677 B
V

module main
struct ScoreRes {
pub mut:
id int [primary; sql: serial]
player string
score int
time i64
}
fn (mut app App) create_tables() bool {
return app.db.exec_none(
"CREATE TABLE IF NOT EXISTS ScoreRes (
id INTEGER PRIMARY KEY,
player TEXT NOT NULL,
score INTEGER NOT NULL,
time SQLITE_INT64_TYPE NOT NULL
)"
) == 0
}
fn (mut app App) insert_score(score ScoreRes) {
sql app.db { insert score into ScoreRes }
}
fn (mut app App) get_scores() []ScoreRes {
scores := sql app.db { select from ScoreRes order by score desc }
return scores
}
fn (mut app App) delete_score(score_id int) {
sql app.db { delete from ScoreRes where id == score_id }
}