1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 var srv
= new Neo4jServer
22 var andres
= new NeoNode
23 andres
.labels
.add_all
(["PERSON", "MALE"])
24 andres
["name"] = "Andres"
26 andres
["status"] = true
27 andres
["groups"] = new JsonArray.from
([1, 2, 3])
30 var kate
= new NeoNode
31 kate
.labels
.add_all
(["PERSON", "FEMALE"])
34 kate
["status"] = false
36 var loves
= new NeoEdge(andres
, "LOVES", kate
)
39 var client
= new Neo4jClient("http://localhost:7474")
42 print
"# Save batch\n"
44 var batch
= new NeoBatch(client
)
45 batch
.save_node
(andres
)
47 batch
.save_edge
(loves
)
48 var errors
= batch
.execute
50 assert errors
.is_empty
51 assert andres
.is_linked
53 assert loves
.is_linked
55 var andres_url
= andres
.url
.to_s
56 var kate_url
= kate
.url
.to_s
57 var loves_url
= loves
.url
.to_s
59 client
= new Neo4jClient("http://localhost:7474")
63 var res4
= client
.load_node
(andres_url
)
65 print res4
["name"].to_s
66 print res4
["age"].to_s
67 print res4
["status"].to_s
68 print res4
["groups"].to_s
69 print res4
.labels
.join
(" ")
70 assert res4
.in_edges
.is_empty
71 assert not res4
.out_edges
.is_empty
74 var res5
= client
.load_node
(kate_url
)
76 print res5
["name"].to_s
77 print res5
["age"].to_s
78 print res5
["status"].to_s
79 print res5
.labels
.join
(" ")
80 assert not res5
.in_edges
.is_empty
81 assert res5
.out_edges
.is_empty
84 var res6
= client
.load_edge
(loves_url
)
86 print res6
.rel_type
.to_s
87 print res6
["since"].to_s
88 print
"{res4["name"].to_s} LOVES {res4.out_nodes("LOVES").first["name"].to_s}"
89 print
"{res5["name"].to_s} IS LOVED BY {res5.in_nodes("LOVES").first["name"].to_s}"
92 var query
= (new CypherQuery).
93 nmatch
("(n: MALE)-[r: LOVES]->(m)").
94 nwhere
("n.name = 'Andres'").
95 nand
("n.key = {key}").
97 var res7
= client
.cypher
(query
)
98 assert res7
.as(JsonObject)["data"].as(JsonArray).length
== 1