@ -13,7 +13,7 @@
( with-db ( db )
( 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 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 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 players(id INTEGER PRIMARY KEY, object TEXT);" ) )
( exec ( sql db "create table user_games(user_id INTEGER, game_id INTEGER);" ) ) ) )
( exec ( sql db "create table user_games(user_id INTEGER, game_id INTEGER);" ) ) ) )
@ -70,14 +70,14 @@
( define ( db-add-game status object )
( define ( db-add-game status object )
( with-db ( db )
( with-db ( db )
( exec ( sql db "insert into games(status, object ) values (?, ?);")
( exec ( sql db "insert into games(status, object , updated ) values (?, ?, ?);")
status ( alist->string object ) )
status ( alist->string object ) ( current-seconds ) )
( last-insert-rowid db ) ) )
( last-insert-rowid db ) ) )
( define ( db-update-game id status object )
( define ( db-update-game id status object )
( with-db ( db )
( with-db ( db )
( exec ( sql db "replace into games(id, status, object ) values (?, ?, ?);")
( exec ( sql db "replace into games(id, status, object , updated ) values (?, ?, ?, ?);")
id status ( alist->string object ) ) ) )
id status ( alist->string object ) ( current-seconds ) ) ) )
( define ( db-fetch-game id )
( define ( db-fetch-game id )
( string->alist
( string->alist
@ -91,7 +91,7 @@
string->alist
string->alist
( with-db ( db )
( with-db ( db )
( query fetch-column
( 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" ) ) ) )
"pre-game" ) ) ) )
( define ( db-fetch-game-row id )
( define ( db-fetch-game-row id )
@ -130,5 +130,5 @@
( define ( db-fetch-user-games user-id )
( define ( db-fetch-user-games user-id )
( with-db ( db )
( with-db ( db )
( query fetch-column
( 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" ) ) )
user-id "finished" ) ) )