Adding 'updated' column to games and using it for sorting.

leave-game
Thomas Hintz 5 years ago
parent 70d8b50ac3
commit 7ba6f19133

@ -13,7 +13,7 @@
(with-db (db)
(exec (sql db "create table users(id INTEGER PRIMARY KEY, username TEXT, email TEXT, password TEXT, salt TEXT);"))
(exec (sql db "create table sessions(bindings TEXT, session_id TEXT PRIMARY KEY);"))
(exec (sql db "create table games(id INTEGER PRIMARY KEY, status TEXT, object TEXT);"))
(exec (sql db "create table games(id INTEGER PRIMARY KEY, status TEXT, object TEXT, updated INTEGER);"))
(exec (sql db "create table players(id INTEGER PRIMARY KEY, object TEXT);"))
(exec (sql db "create table user_games(user_id INTEGER, game_id INTEGER);"))))
@ -70,14 +70,14 @@
(define (db-add-game status object)
(with-db (db)
(exec (sql db "insert into games(status, object) values (?, ?);")
status (alist->string object))
(exec (sql db "insert into games(status, object, updated) values (?, ?, ?);")
status (alist->string object) (current-seconds))
(last-insert-rowid db)))
(define (db-update-game id status object)
(with-db (db)
(exec (sql db "replace into games(id, status, object) values (?, ?, ?);")
id status (alist->string object))))
(exec (sql db "replace into games(id, status, object, updated) values (?, ?, ?, ?);")
id status (alist->string object) (current-seconds))))
(define (db-fetch-game id)
(string->alist
@ -91,7 +91,7 @@
string->alist
(with-db (db)
(query fetch-column
(sql db "select object from games where status=?;")
(sql db "select object from games where status=? order by updated desc;")
"pre-game"))))
(define (db-fetch-game-row id)
@ -130,5 +130,5 @@
(define (db-fetch-user-games user-id)
(with-db (db)
(query fetch-column
(sql db "select game_id from user_games join games on user_games.game_id=games.id where user_games.user_id=? and not games.status=?;")
(sql db "select game_id from user_games join games on user_games.game_id=games.id where user_games.user_id=? and not games.status=? order by updated desc;")
user-id "finished")))

Loading…
Cancel
Save