blowater/UI/dexie-db.ts
2023-08-28 17:58:05 +00:00

26 lines
696 B
TypeScript

import * as dexie from "https://unpkg.com/dexie@3.2.3/dist/modern/dexie.mjs";
import { NostrEvent } from "../lib/nostr-ts/nostr.ts";
export class DexieDatabase extends dexie.Dexie {
// 'friends' is added by dexie when declaring the stores()
// We just tell the typing system this is the case
// @ts-ignore
events!: dexie.Table<NostrEvent>;
constructor() {
super("Events");
this.version(6).stores({
events: "&id, created_at, kind, tags, pubkey", // indices
});
}
}
export function NewIndexedDB(): DexieDatabase | Error {
try {
const db = new DexieDatabase();
return db;
} catch (e) {
return e;
}
}