-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.ts
More file actions
49 lines (35 loc) · 1.07 KB
/
database.ts
File metadata and controls
49 lines (35 loc) · 1.07 KB
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
40
41
42
43
44
45
46
47
// interface Database {
// get(id: string): string
// set(id: string, value: string): void
// }
// interface Persistable {
// saveDBtoString(): string
// restoreDBfromString(storestring: string): void
// }
// class InMemoryDatabase implements Database {
// protected db: Record<string, string> = {}
// get(id: string): string {
// return this.db[id]
// }
// set(id: string, value: string): void {
// this.db[id] = value
// }
// }
// // const myDb = new InMemoryDatabase()
// class PersistableDatabase extends InMemoryDatabase implements Persistable {
// saveDBtoString(): string {
// return JSON.stringify(this.db)
// }
// restoreDBfromString(storestring: string): void {
// this.db = JSON.parse(storestring)
// }
// }
// const myDb = new PersistableDatabase()
// const myDb2 = new PersistableDatabase()
// myDb.set('id1', 'dani')
// console.log(myDb.get('id1'))
// const savedDB = myDb.saveDBtoString()
// myDb.set('id1', 'nuevo')
// console.log(myDb.get('id1'))
// myDb2.restoreDBfromString(savedDB)
// console.log(myDb2.get('id1'))