-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathyildiz-sample.js
75 lines (56 loc) · 3.17 KB
/
yildiz-sample.js
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
70
71
72
73
74
75
"use strict";
const Yildiz = require("./../index.js").bigtable.Yildiz;
(async () => {
await yildiz.init({
//possible way to extend fields in the node and edge tables
properties: {
name: Yildiz.TYPES.STRING
},
attributes: {
as: Yildiz.TYPES.STRING
}
}, true);
const nodeHandler = await yildiz.getNodeHandler();
const translator = await yildiz.getTranslator();
const loveRelationValue = "love";
const hateRelationValue = "hate";
const otherRelationValue = "other";
const loveRelation = translator.strToInt(loveRelationValue);
const hateRelation = translator.strToInt(hateRelationValue);
const otherRelation = translator.strToInt(otherRelationValue);
const julietIdentifier = translator.strToInt("juliet");
const romeoIdentifier = translator.strToInt("romeo");
await translator.storeTranslation(romeoIdentifier, "romeo", {someKey: "someValue0"});
const transRes = await translator.getTranslation(romeoIdentifier);
console.log(transRes);
const romeo = await nodeHandler.createNode(romeoIdentifier, {someKey: "someValue1"}, {name: "Romeo"});
const juliet = await nodeHandler.createNode(julietIdentifier, {someKey: "someValue2"}, {name: "Juliet"});
const edge1 = await nodeHandler.createEdgeWithId(romeo.getYildizID(), juliet.getYildizID(), loveRelation, {someKey: "someValue3"}, {as: "loves"});
const edge2 = await nodeHandler.createEdgeWithId(juliet.getYildizID(), romeo.getYildizID(), hateRelation, {someKey: "someValue4"}, {as: "hates"});
const edge3 = await nodeHandler.createEdgeWithId(romeo.getYildizID(), juliet.getYildizID(), loveRelation, {someKey: "someValue5"}, {as: "loves"});
console.log(edge1, edge2, edge3);
const rromeo = await nodeHandler.getNodeByIdentifier(romeoIdentifier);
await nodeHandler.getNodeByPropertyField("name", "Romeo");
console.log(rromeo.getExtend());
const nodes = (await rromeo.getEdgedNodes()).map(node => [
node.getYildizID(), node.getIdentifier(), node.getProperties(), node.getExtend()]
);
console.log(nodes);
const nodex = await rromeo.getEdgedNodes();
console.log(nodex[0].getAttributes(), nodex[0].getEdge());
const redge1 = await nodeHandler.edgeExistsId(romeo.getYildizID(), juliet.getYildizID(), loveRelation);
const redge2 = await nodeHandler.edgeExists(julietIdentifier, romeoIdentifier, hateRelation);
console.log(redge1, redge2);
const redge3 = await nodeHandler.edgeExistsViaJoin(julietIdentifier, romeoIdentifier, hateRelation);
console.log(redge3);
const incRes = await nodeHandler.increaseEdgeDepthById(romeo.getYildizID(), juliet.getYildizID(), loveRelation);
console.log(incRes);
const decRes = await nodeHandler.decreaseEdgeDepthById(romeo.getYildizID(), juliet.getYildizID(), loveRelation);
console.log(decRes);
const updRes = await nodeHandler.updateEdgeByIds(romeo.getYildizID(), juliet.getYildizID(), loveRelation,
{}, {}, otherRelation);
console.log(updRes);
//const delRes = await nodeHandler.removeEdgeByIds(romeo.getYildizID(), juliet.getYildizID(), otherRelation);
//console.log(delRes);
yildiz.close();
})();