modelling/lib/DatabaseModel.ts

33 lines
833 B
TypeScript
Raw Normal View History

2020-05-02 19:40:53 +02:00
/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Modelling which is released under MIT.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
2020-04-23 17:09:14 +02:00
export abstract class DatabaseModel {
2020-05-02 20:00:41 +02:00
protected data: Record<string, string|number|boolean> = {};
public get id (): number {
2020-05-02 20:04:14 +02:00
return this.data.id as number;
2020-05-02 20:00:41 +02:00
}
public set id (val: number) {
this.data.id = val;
}
2020-04-23 17:09:14 +02:00
2020-05-02 21:01:08 +02:00
public get data (): Record<string, string|number, boolean> {
return this.data;
}
2020-05-02 20:04:14 +02:00
public constructor (id: number) {
2020-05-02 20:03:14 +02:00
this.id = id;
2020-04-23 17:09:14 +02:00
}
2020-05-02 20:00:41 +02:00
public abstract get(key: string): string|number|boolean;
2020-05-02 20:04:14 +02:00
public abstract set(key: string, value: string|number|boolean): void;
2020-04-23 17:09:14 +02:00
2020-05-02 20:03:14 +02:00
public abstract async read(): Promise<void>;
public abstract async write(): Promise<void>;
2020-04-23 17:09:14 +02:00
}