aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/db')
-rw-r--r--src/main/db/schema.ts5
-rw-r--r--src/main/db/settings.ts28
2 files changed, 33 insertions, 0 deletions
diff --git a/src/main/db/schema.ts b/src/main/db/schema.ts
index 39ee567..4c24c6a 100644
--- a/src/main/db/schema.ts
+++ b/src/main/db/schema.ts
@@ -30,6 +30,11 @@ export function initSchema(db: Database.Database) {
30 created_at INTEGER NOT NULL DEFAULT (unixepoch()) 30 created_at INTEGER NOT NULL DEFAULT (unixepoch())
31 ); 31 );
32 32
33 CREATE TABLE IF NOT EXISTS settings (
34 key TEXT PRIMARY KEY,
35 value TEXT NOT NULL
36 );
37
33 CREATE INDEX IF NOT EXISTS idx_sessions_project ON sessions(project_id); 38 CREATE INDEX IF NOT EXISTS idx_sessions_project ON sessions(project_id);
34 CREATE INDEX IF NOT EXISTS idx_messages_session ON messages(session_id); 39 CREATE INDEX IF NOT EXISTS idx_messages_session ON messages(session_id);
35 `); 40 `);
diff --git a/src/main/db/settings.ts b/src/main/db/settings.ts
new file mode 100644
index 0000000..1f86a9a
--- /dev/null
+++ b/src/main/db/settings.ts
@@ -0,0 +1,28 @@
1import { getDb } from "./index";
2
3export function getSetting(key: string): string | null {
4 const row = getDb()
5 .prepare("SELECT value FROM settings WHERE key = ?")
6 .get(key) as { value: string } | undefined;
7 return row ? row.value : null;
8}
9
10export function getSettings(keys: string[]): Record<string, string | null> {
11 const result: Record<string, string | null> = {};
12 for (const key of keys) {
13 result[key] = getSetting(key);
14 }
15 return result;
16}
17
18export function setSetting(key: string, value: string): void {
19 getDb()
20 .prepare("INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)")
21 .run(key, value);
22}
23
24export function deleteSetting(key: string): void {
25 getDb()
26 .prepare("DELETE FROM settings WHERE key = ?")
27 .run(key);
28}