列表
可以使用 Cypher.List 并传入 Cypher 表达式数组来创建 Cypher® 列表。例如
new Cypher.Return(new Cypher.List([new Cypher.Literal(1), new Cypher.Literal(2)]));
RETURN [1, 2]
也可以在列表中包含更复杂的表达式
new Cypher.List([Cypher.labels(node)]));
RETURN [labels(node)]
|
|
列表推导式
列表推导式 可以使用 new Cypher.ListComprehension 并传入用于推导的变量来创建。你还需要一个产生原始列表的表达式,以便从中创建新列表。
const listComprehension = new Cypher.ListComprehension(variable).in(new Cypher.Literal([1,2]))
[var0 IN [1,2]]
通过使用 where 和 map 方法,你可以构建推导式的过滤和映射部分
const listComprehension = new Cypher.ListComprehension(variable)
.in(exprVariable)
.where(andExpr)
.map(Cypher.plus(variable, new Cypher.Literal(1)));
[var0 IN $param1 WHERE var0 = $param0 | (var0 + 1)]
模式推导式
const movie = new Cypher.Node();
const rel = new Cypher.Relationship();
const actor=new Cypher.Node()
const pattern = new Cypher.Pattern(movie, { labels: ["Movie"] }).related(rel, { type: "ACTED_IN" }).to(actor, { labels: ["Actor"] })
const comprehension = new Cypher.PatternComprehension(pattern, actor.property("name"));
[(this0:Movie)-[:ACTED_IN]->(this1:Actor) | this1.name]
可以使用 .where 方法添加过滤器
const movie = new Cypher.Node();
const rel = new Cypher.Relationship();
const actor = new Cypher.Node();
const pattern = new Cypher.Pattern(movie, { labels: ["Movie"] }).related(rel, { type: "ACTED_IN" }).to(actor, { labels: ["Actor"] });
const comprehension = new Cypher.PatternComprehension(pattern, actor.property("name")).where(
Cypher.contains(movie.property("title"), new Cypher.Literal("Matrix"))
);
[(this0:Movie)-[this2:ACTED_IN]->(this1:Actor) WHERE this0.title CONTAINS "Matrix" | this1.name]"