33 lines
831 B
TypeScript
33 lines
831 B
TypeScript
/*
|
|
* 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
|
|
*/
|
|
|
|
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>;
|
|
}
|