-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
66 lines (54 loc) · 1.38 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
import Surreal, {
RecordId,
} from "https://deno.land/x/[email protected]/mod.ts";
import flow from "npm:xml-flow";
import { createReadStream } from "node:fs";
import { sleep } from "https://deno.land/x/[email protected]/mod.ts";
const source = createReadStream("/portable/DrugBank.xml");
const opts = {
// useArrays: flow.ALWAYS
};
const rder = flow(source, opts);
let x = 0;
const db = new Surreal();
await db.connect("http://127.0.0.1:8000/rpc", {
namespace: "drugs",
database: "drugs",
});
await db.delete("drug");
rder.on(
"tag:drug",
async (
drug: { "drugbank-id": [string]; name: [string]; "cas-number": [string] },
) => {
console.log(drug);
const created = db.create("drug", drug);
x++;
if (x > 100) {
rder.pause();
}
},
);
await sleep(200000);
async function main() {
try {
// Connect to the database
// Create a new person with a random id
// // Update a person record with a specific id
const updated = await db.merge("person:jaime", {
marketing: true,
});
// // Select all people records
const people = await db.select("person");
// // Perform a custom advanced query
const groups = await db.query(
"SELECT marketing, count() FROM type::table($tb) GROUP BY marketing",
{
tb: "person",
},
);
console.log(people);
} catch (e) {
console.error("ERROR", e);
}
}