add created timestamp to leaderboard
This commit is contained in:
parent
9d1c43e593
commit
06a95f0f9d
14
index.ts
14
index.ts
|
@ -17,9 +17,15 @@ declare module "express-session" {
|
||||||
const dbVersion: { version: number } | undefined
|
const dbVersion: { version: number } | undefined
|
||||||
= await dbGet("SELECT version FROM version;");
|
= await dbGet("SELECT version FROM version;");
|
||||||
|
|
||||||
if (dbVersion && dbVersion.version === 1) {
|
if (dbVersion) {
|
||||||
console.log("skip db setup")
|
if (dbVersion.version === 2) {
|
||||||
return;
|
console.log("skip db setup")
|
||||||
|
return;
|
||||||
|
} else if (dbVersion.version === 1) {
|
||||||
|
await dbRun("ALTER TABLE highScores ADD COLUMN created TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
|
||||||
|
await dbRun("UPDATE version SET version = 2");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await dbRun(`CREATE TABLE IF NOT EXISTS users (
|
await dbRun(`CREATE TABLE IF NOT EXISTS users (
|
||||||
|
@ -53,7 +59,7 @@ app.get("/leaderboard", async (req: Request, res: Response) => {
|
||||||
const { limit = 100, offset = 0 } = req.query;
|
const { limit = 100, offset = 0 } = req.query;
|
||||||
|
|
||||||
const leaders = await dbAll(`
|
const leaders = await dbAll(`
|
||||||
select h.score, u.name
|
select h.score, u.name, h.created
|
||||||
from highScores h
|
from highScores h
|
||||||
join main.users u on u.id = h.user
|
join main.users u on u.id = h.user
|
||||||
order by score desc
|
order by score desc
|
||||||
|
|
Loading…
Reference in New Issue