From 57861411f37a07af3cd8fcf1520843e5a5e44bfc Mon Sep 17 00:00:00 2001 From: ivar Date: Wed, 10 Dec 2025 00:17:27 +0100 Subject: Initial commit --- app/src/lib/server/db/index.ts | 10 ++++++++++ app/src/lib/server/db/schema.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 app/src/lib/server/db/index.ts create mode 100644 app/src/lib/server/db/schema.ts (limited to 'app/src/lib/server') diff --git a/app/src/lib/server/db/index.ts b/app/src/lib/server/db/index.ts new file mode 100644 index 0000000..b3c877b --- /dev/null +++ b/app/src/lib/server/db/index.ts @@ -0,0 +1,10 @@ +import { drizzle } from 'drizzle-orm/better-sqlite3'; +import Database from 'better-sqlite3'; +import * as schema from './schema'; +import { env } from '$env/dynamic/private'; + +if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set'); + +const client = new Database(env.DATABASE_URL); + +export const db = drizzle(client, { schema }); diff --git a/app/src/lib/server/db/schema.ts b/app/src/lib/server/db/schema.ts new file mode 100644 index 0000000..c1bea43 --- /dev/null +++ b/app/src/lib/server/db/schema.ts @@ -0,0 +1,28 @@ +import { relations } from 'drizzle-orm'; +import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core'; + +export const syncSession = sqliteTable("session", { + id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()), + authzState: text("authzState"), + accessTokenCreated: int("accessTokenCreated"), + refreshTokenCreated: int("refreshTokenCreated"), + tokens: text("tokens") +}) + +export const syncLog = sqliteTable("session_log", { + id: text("id").primaryKey(), + sessionId: text("session_id"), + dateTime: text("date_time"), + msg: text("msg") +}) + +export const syncLogRelation = relations(syncLog, ({ one }) => ({ + author: one(syncSession, { + fields: [syncLog.sessionId], + references: [syncSession.id], + }) +})) + +export const syncSessionLogRelation = relations(syncSession, ({ many }) => ({ + logs: many(syncLog) +})) -- cgit v1.3