aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/lib
diff options
context:
space:
mode:
authorivar <i@oiee.no>2025-12-10 00:17:27 +0100
committerivar <i@oiee.no>2025-12-10 00:17:27 +0100
commit57861411f37a07af3cd8fcf1520843e5a5e44bfc (patch)
tree86fdb1024fdadfcf6551cbb5da274beb791499d9 /app/src/lib
downloadsparebank1-actualbudget-57861411f37a07af3cd8fcf1520843e5a5e44bfc.tar.xz
sparebank1-actualbudget-57861411f37a07af3cd8fcf1520843e5a5e44bfc.zip
Initial commit
Diffstat (limited to 'app/src/lib')
-rw-r--r--app/src/lib/server/db/index.ts10
-rw-r--r--app/src/lib/server/db/schema.ts28
-rw-r--r--app/src/lib/ui/button.svelte41
3 files changed, 79 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)
+}))
diff --git a/app/src/lib/ui/button.svelte b/app/src/lib/ui/button.svelte
new file mode 100644
index 0000000..313cd90
--- /dev/null
+++ b/app/src/lib/ui/button.svelte
@@ -0,0 +1,41 @@
+<script lang="ts">
+ import type { HTMLButtonAttributes } from "svelte/elements";
+ import { Spinner } from "phosphor-svelte";
+ let { children, loading, type = "button", ...restProps }: Props = $props();
+
+ type Props = {
+ loading?: boolean;
+ } & HTMLButtonAttributes;
+</script>
+
+<button {...restProps} {type}>
+ {@render children?.()}
+ {#if loading}
+ <Spinner />
+ {/if}
+</button>
+
+<style>
+ button {
+ border: 1px solid rgba(0, 0, 0, 0.3);
+ background-color: rgba(0, 0, 0, 0.1);
+ align-items: center;
+ border-radius: 3px;
+ padding: 2px 4px;
+ cursor: pointer;
+ display: flex;
+ gap: 3px;
+ transition: 0.1s all ease;
+
+ &:hover,
+ &:focus {
+ background-color: rgba(0, 0, 0, 0.15);
+ }
+
+ &:active {
+ background-color: rgba(0, 0, 0, 0.2);
+ transform: scale(0.96);
+ transition: 0.2s all ease;
+ }
+ }
+</style>