import Dexie from 'dexie'; import {DatabaseService} from './database.service'; export abstract class Model { public static dbService?: DatabaseService; public id?: number; public static getSchema(): string { throw new TypeError('Child class must implement.'); } public static getTableName(): string { throw new TypeError('Child class must implement.'); } public abstract getDatabase(): Dexie.Table; public abstract getSaveRecord(): any; public staticClass() { return (this.constructor as typeof Model); } public exists() { return !!this.id; } public async save() { this.id = await this.getDatabase().put(this.getSaveRecord()); } }