-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmod.ts
38 lines (29 loc) · 1.06 KB
/
mod.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
import get from "https://deno.land/x/[email protected]/get.js";
import set from "https://deno.land/x/[email protected]/set.js";
import { Connector, ConnectOptions } from "./connector.ts";
import { createNewOperator } from "./operator/utils.ts";
class CasualDB<Schema> {
private _connector: Connector<Schema>;
constructor() {
this._connector = new Connector();
}
connect(fsPath: string, options?: ConnectOptions): Promise<unknown> {
return this._connector.connect(fsPath, options);
}
async get<T>(path: string) {
const data = await this._connector.read();
const value: T = get(data, path, null);
return createNewOperator<T>(value);
}
seed(data: Schema): Promise<unknown> {
return this._connector.write(data);
}
async write<T>(path: string, value: T) {
const data = await this._connector.read();
const updatedData = set(data, path, value);
return this._connector.write(updatedData as Schema);
}
}
export default CasualDB;
export { CasualDB };
export { PrimitiveOperator, CollectionOperator } from "./operator/operators.ts";