neo4j :: CypherQuery
The Neo4j REST API allows querying with Cypher. The results are returned as a list of string headers (columns), and a data part, consisting of a list of all rows, every row consisting of a list of REST representations of the field value - Node, Relationship, Path or any simple value like String.
Example:
var client = new Neo4jClient("http://neo4j:7474")
var query = new CypherQuery
query.nmatch("(n)-[r:LOVES]->(m)")
query.nwhere("n.name=\"Andres\"")
query.nreturn("m.name")
var res = client.cypher(query).as(JsonObject)
assert res["data"].as(JsonArray).first.as(JsonArray).first == "Kate"
For more details, see: http://docs.neo4j.org/chunked/milestone/rest-api-cypher.html
neo4j :: CypherQuery :: []=
Pass the argumentvalue
as the parameter key
.
neo4j :: CypherQuery :: defaultinit
neo4j :: CypherQuery :: from_string
init the query from a query stringneo4j :: CypherQuery :: ncreate
Add aCREATE
statement to the query
neo4j :: CypherQuery :: nmatch
Add aMATCH
statement to the query
neo4j :: CypherQuery :: nreturn
Add aRETURN
statement to the query
neo4j :: CypherQuery :: nstart
Add aSTART
statement to the query
neo4j :: CypherQuery :: nwhere
Add aWHERE
statement to the query
neo4j :: CypherQuery :: params
params
to embed in the query like in prepared statements
neo4j :: CypherQuery :: params=
params
to embed in the query like in prepared statements
neo4j :: CypherQuery :: set
Pass the argumentvalue
as the parameter key
.
neo4j :: CypherQuery :: to_rest
Translate the query to the body of a corresponding Neo4j REST request.neo4j :: CypherQuery :: with_params
init the query with parametersneo4j $ CypherQuery :: SELF
Type of this instance, automatically specialized in every classneo4j :: CypherQuery :: []=
Pass the argumentvalue
as the parameter key
.
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Object :: defaultinit
neo4j :: CypherQuery :: defaultinit
neo4j :: CypherQuery :: from_string
init the query from a query stringcore :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
neo4j :: CypherQuery :: ncreate
Add aCREATE
statement to the query
neo4j :: CypherQuery :: nmatch
Add aMATCH
statement to the query
neo4j :: CypherQuery :: nreturn
Add aRETURN
statement to the query
neo4j :: CypherQuery :: nstart
Add aSTART
statement to the query
neo4j :: CypherQuery :: nwhere
Add aWHERE
statement to the query
core :: Object :: output_class_name
Display class name on stdout (debug only).neo4j :: CypherQuery :: params
params
to embed in the query like in prepared statements
neo4j :: CypherQuery :: params=
params
to embed in the query like in prepared statements
neo4j :: CypherQuery :: set
Pass the argumentvalue
as the parameter key
.
neo4j :: CypherQuery :: to_rest
Translate the query to the body of a corresponding Neo4j REST request.neo4j :: CypherQuery :: with_params
init the query with parameters
# A Cypher query for Neo4j REST API
#
# The Neo4j REST API allows querying with Cypher.
# The results are returned as a list of string headers (columns), and a data part,
# consisting of a list of all rows, every row consisting of a list of REST representations
# of the field value - Node, Relationship, Path or any simple value like String.
#
# Example:
#
# var client = new Neo4jClient("http://neo4j:7474")
# var query = new CypherQuery
# query.nmatch("(n)-[r:LOVES]->(m)")
# query.nwhere("n.name=\"Andres\"")
# query.nreturn("m.name")
# var res = client.cypher(query).as(JsonObject)
# assert res["data"].as(JsonArray).first.as(JsonArray).first == "Kate"
#
# For more details, see: http://docs.neo4j.org/chunked/milestone/rest-api-cypher.html
class CypherQuery
# Query string to perform
private var query: String = ""
# `params` to embed in the query like in prepared statements
var params = new JsonObject
# init the query from a query string
init from_string(query: String) do
self.query = query
end
# init the query with parameters
init with_params(params: JsonObject) do
self.params = params
end
# Pass the argument `value` as the parameter `key`.
#
# SEE: `set`
fun []=(key: String, value: nullable Serializable) do
params[key] = value
end
# Add a `CREATE` statement to the query
fun ncreate(query: String): CypherQuery do
self.query = "{self.query}CREATE {query} "
return self
end
# Add a `START` statement to the query
fun nstart(query: String): CypherQuery do
self.query = "{self.query}START {query} "
return self
end
# Add a `MATCH` statement to the query
fun nmatch(query: String): CypherQuery do
self.query = "{self.query}MATCH {query} "
return self
end
# Add a `WHERE` statement to the query
fun nwhere(query: String): CypherQuery do
self.query = "{self.query}WHERE {query} "
return self
end
# Add a `AND` statement to the query
fun nand(query: String): CypherQuery do
self.query = "{self.query}AND {query} "
return self
end
# Add a `RETURN` statement to the query
fun nreturn(query: String): CypherQuery do
self.query = "{self.query}RETURN {query} "
return self
end
# Pass the argument `value` as the parameter `key`.
#
# Return `self`.
#
# ```
# var query = (new CypherQuery).
# nmatch("(n)").
# nwhere("n.key = \{key\}").
# set("key", "foo")
#
# assert query.params["key"] == "foo"
# ```
#
# SEE: `[]=`
fun set(key: String, value: nullable Serializable): SELF do
self[key] = value
return self
end
# Translate the query to the body of a corresponding Neo4j REST request.
fun to_rest: JsonObject do
var obj = new JsonObject
obj["query"] = query
if not params.is_empty then
obj["params"] = params
end
return obj
end
redef fun to_s do return to_rest.to_s
end
lib/neo4j/neo4j.nit:345,1--453,3