-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
55 lines (46 loc) · 1.63 KB
/
index.tsx
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
48
49
50
51
52
53
54
55
import { NDBConfig } from "./src/config";
import { NDBRecord } from "./src/record";
import { createFile, modifyFile, getFile, deleteFile } from "./src/githubFileIO";
export { NDBRecord, NDBConfig };
export { NDBRecordKeyType } from './src/record';
/**
* JS Wrapper for NoDB
*/
export default class NoDB {
private static config: NDBConfig;
/**
* Sets the settings used for NoDB
* @param config settings to use for NoDB
*/
public static Init(config: NDBConfig) {
NoDB.config = config;
}
/**
* Stores a new record in the database
* @param record new record to store in the database.
*/
public static Create<RecordType extends NDBRecord>(record: RecordType): void {
createFile(NoDB.config, record);
}
/**
* Overwrites a record with the same key in the database
* @param record new record to store in the database
*/
public static Modify<RecordType extends NDBRecord>(record: RecordType): void {
modifyFile(NoDB.config, record);
}
/**
* Returns the JSON object of the record being returned
* @param record type and key of record to get from the database
*/
public static async Get<RecordType extends NDBRecord>(record: RecordType): Promise<RecordType> {
return JSON.parse(await getFile(NoDB.config, record)) as RecordType;
}
/**
* Deletes a record from the database
* @param record type and key of the record to delete from the database
*/
public static Delete(record: NDBRecord): void {
deleteFile(NoDB.config, record)
}
}