-
Notifications
You must be signed in to change notification settings - Fork 0
/
mvc.ts
39 lines (33 loc) · 1004 Bytes
/
mvc.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { randomUUID } from 'crypto';
import { DB } from './db';
namespace MVC {
export class Model {
id: string;
dbName: string;
constructor() {
this.id = randomUUID();
this.dbName = this.constructor.name.toLowerCase();
}
getInfo() {
let info = `ClassName: ${this.constructor.name}, propNames: ${Object.getOwnPropertyNames(this)}`
return info;
}
all() {
let db = new DB(this.dbName);
return db.read();
}
create() {
let db = new DB(this.dbName);
db.append(this.toJSON());
}
// TODO decide whether to use JSON or a different way of storing.
// should this decision happen in the model or at the db level?
//
// How are we going to initialize objects using it?
toJSON() {
let json = JSON.stringify(this);
return json;
}
}
}
export { MVC }