better structure

This commit is contained in:
Timo Hocker 2020-05-02 20:00:41 +02:00
parent 4530ec9c39
commit de5c397ed3

View File

@ -6,7 +6,15 @@
*/
export abstract class DatabaseModel {
protected id?: number;
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,
@ -18,14 +26,8 @@ export abstract class DatabaseModel {
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 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>;