47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
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
|
|
*/
|
|
|
|
import { Assignable } from './interfaces/Assignable';
|
|
|
|
export abstract class DatabaseModel extends Assignable {
|
|
public get id (): number {
|
|
return this.data.id as number;
|
|
}
|
|
|
|
public apply_object (obj: Record<string, unknown>): void {
|
|
for (const key of Object.keys (obj)) {
|
|
if ([
|
|
'string',
|
|
'number',
|
|
'boolean'
|
|
].indexOf (typeof obj[key]) > -1)
|
|
this.data[key] = obj[key];
|
|
}
|
|
}
|
|
|
|
public constructor (id: number) {
|
|
super ();
|
|
this.data.id = id;
|
|
}
|
|
|
|
public get (key: string): string|number|boolean {
|
|
return this.data[key] as string|number|boolean;
|
|
}
|
|
|
|
public set (key: string, value: string|number|boolean): void {
|
|
this.data[key] = value;
|
|
}
|
|
|
|
public get_data (): Record<string, string|number|boolean> {
|
|
return super.get_data () as Record<string, string|number|boolean>;
|
|
}
|
|
|
|
public abstract async read(): Promise<boolean>;
|
|
public abstract async write(): Promise<boolean>;
|
|
public abstract async delete(): Promise<boolean>;
|
|
}
|