-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.ts
55 lines (52 loc) · 1.67 KB
/
db.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import rockset from "@rockset/client";
import {
AddDocumentsResponse,
DeleteDocumentsResponse,
PatchDocumentsResponse,
QueryRequestSql,
QueryResponse,
} from "@rockset/client/dist/codegen/api";
import { QueryCallback } from "./types";
const client = rockset(require("./config.json").rocksetApiKey);
export function isPatchSuccess(r: PatchDocumentsResponse) {
return r.data != undefined && !r.data[0].error;
}
export function isQuerySuccess(r: QueryResponse) {
return !!r.results;
}
export const addDocs = (
collection: "slots" | "students" | "teachers",
documents: any[]
) => {
return new Promise<AddDocumentsResponse>((resolve, reject) => {
client.documents
.addDocuments("office-hours", collection, { data: documents })
.then(resolve)
.catch(console.log);
});
};
export const rmDocs = (
collection: "slots" | "students" | "teachers",
documents: any[]
) => {
return new Promise<DeleteDocumentsResponse>((resolve, reject) => {
client.documents
.deleteDocuments("office-hours", collection, { data: documents })
.then(resolve)
.catch(console.log);
});
};
export const editDocs = (
collection: "slots" | "students" | "teachers",
documents: any[]
) => {
return new Promise<PatchDocumentsResponse>((resolve, reject) => {
client.documents
.patchDocuments("office-hours", collection, { data: documents })
.then(resolve)
.catch(console.log);
});
};
export const query = (queryBody: QueryRequestSql, callback: QueryCallback) => {
client.queries.query({ sql: queryBody }).then(callback).catch(console.log);
};