summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hintz <t@thintz.com>2020-04-18 11:45:18 -0700
committerThomas Hintz <t@thintz.com>2020-04-18 11:45:18 -0700
commit7ba6f19133377113d2521f3bcd790e16a35b21b3 (patch)
treeb19171a50fdc4b2fdbdee613cc835a640db76624
parent70d8b50ac3741de71cf1131284bba6344c637725 (diff)
downloadfarm-7ba6f19133377113d2521f3bcd790e16a35b21b3.tar.gz
Adding 'updated' column to games and using it for sorting.
-rw-r--r--src/server/db.scm14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/server/db.scm b/src/server/db.scm
index da3a800..17138e6 100644
--- a/src/server/db.scm
+++ b/src/server/db.scm
@@ -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")))