-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharango.js
More file actions
69 lines (61 loc) · 1.53 KB
/
arango.js
File metadata and controls
69 lines (61 loc) · 1.53 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { Database, aql } from "arangojs";
import { log, error, Verbose } from "./services.js";
import conf from "./conf.js";
const verbose = Verbose("sd:arango");
verbose("");
async function startArango() {
verbose("startArango");
try {
const dbInit = new Database(conf.arangodb.url);
await dbInit.createDatabase(conf.arangodb.database);
log("Database created:", conf.arangodb.database);
} catch (err) {
error("arango create db err:", err.message);
}
let db = null;
try {
db = new Database({
url: conf.arangodb.url,
databaseName: conf.arangodb.database,
auth: {
username: conf.arangodb.auth.username,
password: conf.arangodb.auth.password,
},
});
log("Connected to Database");
} catch (err) {
error("arango connect to db err:", err.message);
}
const Pokemons = db.collection("my-pokemons");
try {
await Pokemons.create();
log("Collection created");
} catch (err) {
error("arango create collection err:", err.message);
}
try {
const doc = {
type: "fire",
a: "foo",
b: "bar",
c: Date(),
};
const meta = await Pokemons.save(doc);
verbose("Arango document saved:", meta._rev);
const pokemons = await db.query(aql`
FOR pokemon IN ${Pokemons}
FILTER pokemon.type == "fire"
RETURN pokemon
`);
const allPokemons = await pokemons.all();
verbose("allPokemans:", allPokemons);
// for (let pokemon of allPokemons) {
// verbose('pokemon:', pokemon)
// }
} catch (err) {
error("arango main err:", err.message);
}
}
if (conf.arangodb.enable) {
startArango();
}