end
# Retrieve all nodes with specified `lbl`
+ #
+ # var client = new Neo4jClient("http://localhost:7474")
+ # #
+ # var andres = new NeoNode
+ # andres.labels.add_all(["Human", "Male"])
+ # client.save_node(andres)
+ # var kate = new NeoNode
+ # kate.labels.add_all(["Human", "Female"])
+ # client.save_node(kate)
+ # #
+ # var nodes = client.nodes_with_label("Human")
+ # assert nodes.has(andres)
+ # assert nodes.has(kate)
fun nodes_with_label(lbl: String): Array[NeoNode] do
var res = get("{base_url}/db/data/label/{lbl}/nodes")
var nodes = new Array[NeoNode]
return nodes
end
+ # Retrieve nodes belonging to all the specified `labels`.
+ #
+ # var client = new Neo4jClient("http://localhost:7474")
+ # #
+ # var andres = new NeoNode
+ # andres.labels.add_all(["Human", "Male"])
+ # client.save_node(andres)
+ # var kate = new NeoNode
+ # kate.labels.add_all(["Human", "Female"])
+ # client.save_node(kate)
+ # #
+ # var nodes = client.nodes_with_labels(["Human", "Male"])
+ # assert nodes.has(andres)
+ # assert not nodes.has(kate)
+ fun nodes_with_labels(labels: Array[String]): Array[NeoNode] do
+ assert not labels.is_empty
+ var res = cypher(new CypherQuery.from_string("MATCH (n:{labels.join(":")}) RETURN n"))
+ var nodes = new Array[NeoNode]
+ for json in res.as(JsonObject)["data"].as(JsonArray) do
+ var obj = json.as(JsonArray).first.as(JsonObject)
+ var node = load_node(obj["self"].to_s)
+ node.internal_properties = obj["data"].as(JsonObject)
+ nodes.add node
+ end
+ return nodes
+ end
+
# Perform a `CypherQuery`
# see: CypherQuery
fun cypher(query: CypherQuery): Jsonable do
# For more details, see: http://docs.neo4j.org/chunked/milestone/rest-api-cypher.html
class CypherQuery
# Query string to perform
- private var query: String
+ private var query: String = ""
# `params` to embed in the query like in prepared statements
var params = new JsonObject
- init do
- self.query = ""
- end
+ init do end
# init the query from a query string
init from_string(query: String) do
# assert node["name"] == "Andres" # loaded lazily from base
abstract class NeoEntity
# Neo4j client connector
- private var neo: Neo4jClient
+ private var neo: Neo4jClient is noinit
# Entity unique URL in Neo4j REST API
- var url: nullable String
+ var url: nullable String = null
# Temp id used in batch mode to update the entity
private var batch_id: nullable Int = null
end
end
+ # Create a `NeoNode` or a `NeoEdge` in batch mode.
+ fun save_entity(nentity: NeoEntity) do
+ if nentity isa NeoNode then
+ save_node(nentity)
+ else if nentity isa NeoEdge then
+ save_edge(nentity)
+ else abort
+ end
+
# Create a node in batch mode also create labels and edges
fun save_node(node: NeoNode) do
if node.id != null or node.batch_id != null then return