diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-09-22 15:46:45 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-10-05 15:08:49 +0200 |
commit | 47b5c03d286eb047b62f6d03dddf7d6bc6b3978e (patch) | |
tree | f11981a35f6953a8052a45e85df4965b4cdb5aad /server.js | |
parent | 93c7a6e1443d19e8f924ba0bdaeffb3c755c4d7f (diff) | |
download | server-47b5c03d286eb047b62f6d03dddf7d6bc6b3978e.tar.gz |
Avoid "natural" joins for future proofing schema changes.
Diffstat (limited to 'server.js')
-rw-r--r-- | server.js | 24 |
1 files changed, 13 insertions, 11 deletions
@@ -1194,7 +1194,7 @@ const SQL_SELECT_REPLAY = SQL(` json_object('role', role, 'name', name) ) from players - natural join users + join users using(user_id) where game_id = :game_id ), 'state', @@ -2729,48 +2729,49 @@ app.get('/stats', function (req, res) { const SQL_USER_STATS = SQL(` select - title_name, + titles.title_name, scenario, role, sum(role=result) as won, count(*) as total from players - natural join game_view - natural join titles + join game_view using(game_id) + join titles using(title_id) where not is_symmetric and user_id = ? and is_opposed and ( status = ${STATUS_FINISHED} or status = ${STATUS_ARCHIVED} ) group by - title_name, + titles.title_name, scenario, role union select - title_name, + titles.title_name, scenario, null as role, sum(role=result) as won, count(*) as total from players - natural join game_view - natural join titles + join game_view using(game_id) + join titles using(title_id) where is_symmetric and user_id = ? and is_opposed and ( status = ${STATUS_FINISHED} or status = ${STATUS_ARCHIVED} ) group by - title_name, + titles.title_name, scenario `) const SQL_USER_RATINGS = SQL(` select title_name, rating, count, date(last) as last - from ratings natural join titles + from ratings + join titles using(title_id) where user_id = ? and count >= 5 order by rating desc @@ -2778,7 +2779,8 @@ const SQL_USER_RATINGS = SQL(` const SQL_GAME_RATINGS = SQL(` select name, rating, count, date(last) as last - from ratings natural join users + from ratings + join users using(user_id) where title_id = ? and rating >= 1600 and count >= 10 order by rating desc limit 50 |