Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 1x 1x | import { Draft } from './draft.model';
import Dexie, { Table } from 'dexie';
/**
* Dexie database wrapper for draft storage.
* DB name: 'drevo-drafts', compound PK: [userId+route].
*/
export class DraftDatabase extends Dexie {
drafts!: Table<Draft, [string, string]>;
constructor() {
super('drevo-drafts');
this.version(1).stores({
drafts: '[userId+route], userId, time',
});
}
async saveDraft(draft: Draft): Promise<void> {
await this.drafts.put(draft);
}
async getDraft(userId: string, route: string): Promise<Draft | undefined> {
return this.drafts.get([userId, route]);
}
async getAllDrafts(userId: string): Promise<Draft[]> {
return this.drafts.where('userId').equals(userId).reverse().sortBy('time');
}
async countDrafts(userId: string): Promise<number> {
return this.drafts.where('userId').equals(userId).count();
}
async deleteDraft(userId: string, route: string): Promise<void> {
await this.drafts.delete([userId, route]);
}
async deleteAllDrafts(userId: string): Promise<void> {
await this.drafts.where('userId').equals(userId).delete();
}
}
|