modelling/lib/DatabaseModel.ts

26 lines
607 B
TypeScript
Raw Normal View History

2020-04-23 17:09:14 +02:00
export abstract class DatabaseModel {
protected id?: number;
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 get object (): Record<string, number | string | undefined> {
const obj = { id: this.id };
return obj;
}
public set object (obj: Record<string, number | string | undefined>) {
this.id = obj.id as number | undefined;
}
public abstract read(): Promise<void>;
public abstract write(): Promise<void>;
}