extremely claude-assisted go game based on atproto! working on cleaning up and giving a more unique design, still has a bit of a slop vibe to it.
1import { Kysely } from 'kysely';
2import { D1Dialect } from 'kysely-d1';
3import type { App } from '@sveltejs/kit';
4
5export interface GameRecord {
6 id: string; // AT URI (game_at_uri)
7 rkey: string; // Record key (TID)
8 creator_did: string; // DID of whoever created the game (owns the ATProto record)
9 player_one: string | null;
10 player_two: string | null;
11 board_size: number;
12 status: 'waiting' | 'active' | 'completed';
13 action_count: number;
14 last_action_type: string | null;
15 winner: string | null;
16 handicap: number;
17 created_at: string;
18 updated_at: string;
19}
20
21export interface Database {
22 games: GameRecord;
23}
24
25export function getDb(platform: App.Platform | undefined): Kysely<Database> {
26 // Production: Use Cloudflare D1
27 if (platform?.env?.DB) {
28 return new Kysely<Database>({
29 dialect: new D1Dialect({ database: platform.env.DB }),
30 });
31 }
32
33 // No D1 configured
34 throw new Error(
35 'Database not configured. In Cloudflare, set up D1 and bind it as "DB". ' +
36 'For local development, use `wrangler pages dev` with D1 bindings.'
37 );
38}