|
|
|
@ -19,17 +19,19 @@ db.exec(`
|
|
|
|
|
);
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
|
|
// db.exec(`
|
|
|
|
|
// CREATE TABLE IF NOT EXISTS game_actions (
|
|
|
|
|
// id INTEGER PRIMARY KEY,
|
|
|
|
|
// room_id TEXT NOT NULL,
|
|
|
|
|
// created_at TEXT NOT NULL,
|
|
|
|
|
|
|
|
|
|
// data TEXT NOT NULL,
|
|
|
|
|
db.exec(`
|
|
|
|
|
CREATE TABLE IF NOT EXISTS deleted_rooms (
|
|
|
|
|
id TEXT PRIMARY KEY,
|
|
|
|
|
deleted_at TEXT NOT NULL
|
|
|
|
|
);
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
|
|
// FOREIGN KEY (room_id) REFERENCES rooms (id)
|
|
|
|
|
// );
|
|
|
|
|
// `)
|
|
|
|
|
db.exec(`
|
|
|
|
|
CREATE TABLE IF NOT EXISTS sessions (
|
|
|
|
|
sid TEXT PRIMARY KEY,
|
|
|
|
|
room_id TEXT NOT NULL
|
|
|
|
|
);
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
|
|
export function databaseStatus(): string {
|
|
|
|
|
return 'ok'
|
|
|
|
@ -66,6 +68,15 @@ export function updateRoom(id: string, data: RoomData): void {
|
|
|
|
|
).run(JSON.stringify(data), id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function deleteRoom(id: string): void {
|
|
|
|
|
db.prepare<[string, string]>(
|
|
|
|
|
`
|
|
|
|
|
INSERT INTO deleted_rooms (id, deleted_at)
|
|
|
|
|
VALUES (?, ?);
|
|
|
|
|
`
|
|
|
|
|
).run(id, new Date().toISOString())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getRoom(id: string): RoomData | null {
|
|
|
|
|
const row = db
|
|
|
|
|
.prepare<
|
|
|
|
@ -77,6 +88,9 @@ export function getRoom(id: string): RoomData | null {
|
|
|
|
|
}
|
|
|
|
|
>('SELECT * FROM rooms WHERE id = ?')
|
|
|
|
|
.get(id)
|
|
|
|
|
|
|
|
|
|
console.log(row)
|
|
|
|
|
|
|
|
|
|
if (!row) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
@ -108,7 +122,14 @@ export function getRooms(): Room[] {
|
|
|
|
|
id: string
|
|
|
|
|
data: string
|
|
|
|
|
}
|
|
|
|
|
>('SELECT id, data FROM rooms')
|
|
|
|
|
>(
|
|
|
|
|
`
|
|
|
|
|
SELECT rooms.id, rooms.data
|
|
|
|
|
FROM rooms
|
|
|
|
|
LEFT JOIN deleted_rooms ON rooms.id = deleted_rooms.id
|
|
|
|
|
WHERE deleted_rooms.id IS NULL
|
|
|
|
|
`
|
|
|
|
|
)
|
|
|
|
|
.all()
|
|
|
|
|
|
|
|
|
|
return rows.map(row => ({
|
|
|
|
|