26 lines
607 B
TypeScript
26 lines
607 B
TypeScript
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>;
|
|
}
|