aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/db/settings.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/db/settings.ts')
-rw-r--r--src/main/db/settings.ts28
1 files changed, 28 insertions, 0 deletions
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}