From de5c397ed385e509650de3d423844a5b7761428e Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Sat, 2 May 2020 20:00:41 +0200 Subject: [PATCH] better structure --- lib/DatabaseModel.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/DatabaseModel.ts b/lib/DatabaseModel.ts index 06ba7ab..344fb9b 100644 --- a/lib/DatabaseModel.ts +++ b/lib/DatabaseModel.ts @@ -6,7 +6,15 @@ */ export abstract class DatabaseModel { - protected id?: number; + protected data: Record = {}; + + public get id (): number { + return this.data.id; + } + + public set id (val: number) { + this.data.id = val; + } public static async get ( id: number, @@ -18,14 +26,8 @@ export abstract class DatabaseModel { return dbm; } - public get object (): Record { - const obj = { id: this.id }; - return obj; - } - - public set object (obj: Record) { - 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; public abstract write(): Promise;