Skip to content

Commit

Permalink
sdk: expost db
Browse files Browse the repository at this point in the history
Expose "db" method in sdk to manage a keyval db
  • Loading branch information
Cattn committed Nov 14, 2024
1 parent c01e3ec commit 5cee0bc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib/idb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
27 changes: 27 additions & 0 deletions src/lib/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { $plugins } from "./plugins"
import { toast } from "sonner"
import { IDB } from "@/lib/idb"

// interface Setting {
// pluginId: string
Expand Down Expand Up @@ -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
},
}
}
1 change: 1 addition & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@tailwind utilities;

@layer base {
/* Todo: More themes & Switching */
:root {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
Expand Down

0 comments on commit 5cee0bc

Please sign in to comment.