better structure
This commit is contained in:
parent
4530ec9c39
commit
de5c397ed3
@ -6,7 +6,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export abstract class DatabaseModel {
|
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> (
|
public static async get<T extends DatabaseModel> (
|
||||||
id: number,
|
id: number,
|
||||||
@ -18,14 +26,8 @@ export abstract class DatabaseModel {
|
|||||||
return dbm;
|
return dbm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get object (): Record<string, number | string | undefined> {
|
public abstract get(key: string): string|number|boolean;
|
||||||
const obj = { id: this.id };
|
public abstract set(key: string, value: string|number|boolean);
|
||||||
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 read(): Promise<void>;
|
||||||
public abstract write(): Promise<void>;
|
public abstract write(): Promise<void>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user