/* * Copyright (C) Sapphirecode - All Rights Reserved * This file is part of Modelling which is released under MIT. * See file 'LICENSE' for full license details. * Created by Timo Hocker , May 2020 */ import { Persistent } from './Persistent'; export abstract class DatabaseModel extends Persistent { public get id (): number { return this.get ('id') as number; } public constructor (id?: number) { super (); this.properties.id = 'number'; for (const prop of Object.keys (this.properties)) { if ([ 'string', 'number', 'boolean' ].indexOf (this.properties[prop]) < 0) { throw new Error ( 'property types have to be either string, number or boolean' ); } } if (typeof id !== 'undefined') this.set ('id', id); } public get (key: string): string|number|boolean { return super.get (key) as string|number|boolean; } public set (key: string, value: string|number|boolean): void { super.set (key, value); } public to_object (): Record { return super.to_object () as Record; } public abstract async read(): Promise; public abstract async write(): Promise; public abstract async delete(): Promise; }