Files
chinese-family-tree-2/lib/db.ts
T
freedakgmail 626d7dddde 0.0.0.5
2025-11-23 00:49:16 +08:00

51 lines
1.3 KiB
TypeScript

import Dexie, { type Table } from "dexie"
import type { FamilyMember } from "@/types/family"
export interface GlobalSettings {
key: string
value: any
}
export interface StoredImage {
id: string
blob: Blob
mimeType: string
createdAt: string
}
export interface ActivityLog {
id: string
action: "create" | "update" | "delete" | "import" | "export"
entityType: "member" | "photo" | "story" | "settings"
entityId?: string
entityName?: string
changes?: any
timestamp: string
userId?: string
userName?: string
}
export class FamilyTreeDB extends Dexie {
members!: Table<FamilyMember>
settings!: Table<GlobalSettings>
images!: Table<StoredImage>
activityLogs!: Table<ActivityLog>
constructor() {
super("FamilyTreeDB")
this.version(1).stores({
members: "id, fullName, fatherId, motherId, [fatherId+motherId]", // Index for searching
settings: "key", // Key-value store for rootId etc.
images: "id", // Store images by ID
})
this.version(2).stores({
members: "id, fullName, fatherId, motherId, [fatherId+motherId]", // Index for searching
settings: "key", // Key-value store for rootId etc.
images: "id", // Store images by ID
activityLogs: "id, timestamp, action, entityType, entityId",
})
}
}
export const db = new FamilyTreeDB()