This commit is contained in:
Dimas Wiese
2026-03-15 23:34:23 +01:00
parent 4275cbd795
commit 6b0f87199c
63 changed files with 22786 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
/**
* database.ts
* Dexie (IndexedDB) singleton for the P2P Survey App.
*
* All survey data — surveys, participant tokens, and responses — lives
* exclusively in the creator's browser. Dexie wraps the raw IndexedDB API
* with a clean, Promise-based interface and live-query support.
*
* Usage (inject via InjectionToken, see main.ts):
* constructor(@Inject(DATABASE_TOKEN) private db: AppDatabase) {}
*/
import Dexie, { type Table } from 'dexie';
import type { Survey, Participant, Response } from '../shared/models/survey.models';
/** Typed Dexie database class */
export class AppDatabase extends Dexie {
/** All surveys created by this user */
surveys!: Table<Survey, string>;
/**
* Pre-generated participant tokens.
* Primary key: token (UUID string).
*/
participants!: Table<Participant, string>;
/**
* Submitted responses.
* Primary key: id (UUID string).
*/
responses!: Table<Response, string>;
constructor() {
super('P2PSurveyDB');
this.version(1).stores({
// Indexed fields: primary key first, then fields used in queries
surveys: 'id, status, createdAt',
participants: 'token, surveyId, locked',
responses: 'id, surveyId, participantToken, submittedAt',
});
}
}
/** Module-level singleton — import this wherever you need direct DB access */
export const db = new AppDatabase();