modelling/lib/DatabaseModel.ts
2020-05-02 20:00:41 +02:00

35 lines
868 B
TypeScript

/*
* 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 <timo@scode.ovh>, May 2020
*/
export abstract class DatabaseModel {
protected data: Record<string, string|number|boolean> = {};
public get id (): number {
return this.data.id;
}
public set id (val: number) {
this.data.id = val;
}
public static async get<T extends DatabaseModel> (
id: number,
constructor: new () => T
): Promise<T> {
const dbm = (new constructor);
dbm.id = id;
await dbm.read ();
return dbm;
}
public abstract get(key: string): string|number|boolean;
public abstract set(key: string, value: string|number|boolean);
public abstract read(): Promise<void>;
public abstract write(): Promise<void>;
}