diff options
| author | ivar <i@oiee.no> | 2025-12-10 00:17:27 +0100 |
|---|---|---|
| committer | ivar <i@oiee.no> | 2025-12-10 00:17:27 +0100 |
| commit | 57861411f37a07af3cd8fcf1520843e5a5e44bfc (patch) | |
| tree | 86fdb1024fdadfcf6551cbb5da274beb791499d9 /app/src/lib/server/db | |
| download | sparebank1-actualbudget-57861411f37a07af3cd8fcf1520843e5a5e44bfc.tar.xz sparebank1-actualbudget-57861411f37a07af3cd8fcf1520843e5a5e44bfc.zip | |
Initial commit
Diffstat (limited to 'app/src/lib/server/db')
| -rw-r--r-- | app/src/lib/server/db/index.ts | 10 | ||||
| -rw-r--r-- | app/src/lib/server/db/schema.ts | 28 |
2 files changed, 38 insertions, 0 deletions
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) +})) |
