diff --git a/src/lib/idb.ts b/src/lib/idb.ts index 3129f2e..251aaba 100644 --- a/src/lib/idb.ts +++ b/src/lib/idb.ts @@ -12,6 +12,10 @@ export class IDB { return openDB(name, 1, {}) } + public static openDB(name: string) { + return openDB(name) + } + public static addObjectStore(db: any, storeName: string) { const version = db.version + 1 return openDB(db.name, version, { diff --git a/src/lib/sdk.ts b/src/lib/sdk.ts index 6cc0195..449a670 100644 --- a/src/lib/sdk.ts +++ b/src/lib/sdk.ts @@ -1,5 +1,6 @@ import { $plugins } from "./plugins" import { toast } from "sonner" +import { IDB } from "@/lib/idb" // interface Setting { // pluginId: string @@ -59,4 +60,30 @@ export class SDK { } }, } + + public db = { + + // todo future: Store DB somewhere, no need to reference store every time, can just use .get(key) + create: () => { + let db = IDB.createDB(this.id) + return db + }, + + get: (key: string) => { + let store = IDB.openDB(this.id) + console.log(`[${this.id}] Getting db value for key ${key}`); + const value = IDB.store(store).get(key).then((value) => { + console.log(`[${this.id}] Got db value for key ${key}: ${value}`); + }) + return value + }, + set: (key: string, value: string) => { + let store = IDB.openDB(this.id) + console.log(`[${this.id}] Setting db value for key ${key} to ${value}`); + IDB.store(store).set(key, value).then(() => { + console.log(`[${this.id}] Set db value for key ${key} to ${value}`); + }) + return value + }, + } } diff --git a/src/styles.css b/src/styles.css index 5551681..5f62114 100644 --- a/src/styles.css +++ b/src/styles.css @@ -3,6 +3,7 @@ @tailwind utilities; @layer base { + /* Todo: More themes & Switching */ :root { --background: 0 0% 100%; --foreground: 240 10% 3.9%;