Neo4j-Cypher查询语言-参数

Cypher支持带参数的查询,它允许开发者不需要do string building to create a query,同时它能使执行计划的缓存更容易。
 
参数可以用在WHERE子句的literals和expressions、可以用在START子句或索引查询的索引键值上、节点/关系的ID上。但是参数不能用在属性名上,因为属性是查询结构的一部分,是要编译成执行计划的。
 
参数名称只能是字母和数字的组合
 
如下是在JAVA中使用参数的几个例子:
节点ID参数
1
2
3
Map<String, Object> params = new HashMap<String, Object>();
params.put( "id", 0 );
ExecutionResult result = 
engine.execute("start n=node({id}) return n.name", params );
 
节点对象参数
1
2
3
Map<String, Object> params = new HashMap<String, Object>();
params.put( "node", andreasNode );
ExecutionResult result = 
engine.execute("start n=node({node}) return n.name", params );
 
多节点ID参数
1
2
3
Map<String, Object> params = new HashMap<String, Object>();
params.put( "id", Arrays.asList( 0, 1, 2 ) );
ExecutionResult result = 
engine.execute("start n=node({id}) return n.name", params );
字符串参数
1
2
3
4
Map<String, Object> params = new HashMap<String, Object>();
params.put( "name", "Johan" );
ExecutionResult result =
engine.execute("start n=node(0,1,2) where n.name = {name} return n", params );
索引键值参数
1
2
3
4
5
Map<String, Object> params = new HashMap<String, Object>();
params.put( "key""name" );
params.put( "value""Michaela" );
ExecutionResult result =
 engine.execute("start n=node:people({key} = {value}) return n", params );
 
索引查询参数
1
2
3
Map<String, Object> params = new HashMap<String, Object>();
params.put( "query""name:Andreas" );
ExecutionResult result = 
engine.execute("start n=node:people({query}) return n", params );
 
SKIP和LIMIT的数字参数
1
2
3
4
5
Map<String, Object> params = new HashMap<String, Object>();
params.put( "s", 1 );
params.put( "l", 1 );
ExecutionResult result =
 engine.execute("start n=node(0,1,2) return n.name skip {s} limit {l}", params );
 
正则表达式参数
1
2
3
4
Map<String, Object> params = new HashMap<String, Object>();
params.put( "regex", ".*h.*" );
ExecutionResult result =
engine.execute("start n=node(0,1,2) where n.name =~ {regex} return n.name"
  , params);

你可能感兴趣的:(参数,neo4j,cypher,图数据库)