workspace with decoupled nostr package
This commit is contained in:
42
packages/app/src/Db/index.ts
Normal file
42
packages/app/src/Db/index.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import Dexie, { Table } from "dexie";
|
||||
import { TaggedRawEvent, u256 } from "@snort/nostr";
|
||||
import { MetadataCache } from "State/Users";
|
||||
import { hexToBech32 } from "Util";
|
||||
|
||||
export const NAME = "snortDB";
|
||||
export const VERSION = 3;
|
||||
|
||||
export interface SubCache {
|
||||
id: string;
|
||||
ids: u256[];
|
||||
until?: number;
|
||||
since?: number;
|
||||
}
|
||||
|
||||
const STORES = {
|
||||
users: "++pubkey, name, display_name, picture, nip05, npub",
|
||||
events: "++id, pubkey, created_at",
|
||||
feeds: "++id",
|
||||
};
|
||||
|
||||
export class SnortDB extends Dexie {
|
||||
users!: Table<MetadataCache>;
|
||||
events!: Table<TaggedRawEvent>;
|
||||
feeds!: Table<SubCache>;
|
||||
|
||||
constructor() {
|
||||
super(NAME);
|
||||
this.version(VERSION)
|
||||
.stores(STORES)
|
||||
.upgrade(async tx => {
|
||||
await tx
|
||||
.table("users")
|
||||
.toCollection()
|
||||
.modify(user => {
|
||||
user.npub = hexToBech32("npub", user.pubkey);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const db = new SnortDB();
|
Reference in New Issue
Block a user