连接子句
在大多数情况下,子句可以通过链式方法进行连接,例如
new Cypher.Match(myPattern).return(myNode);
MATCH(this0)
RETURN this0
然而,在某些情况下,必须手动连接子句。这可能是由于
-
链式方法不可用。
-
查询中子句数量动态变化。
-
已经单独生成的复合子句。
-
使用
Cypher®.Raw。
对于这些情况,请使用辅助工具 Cypher.utils.concat。此函数接受任意数量的子句,并按提供的顺序进行连接。例如,前面的示例可以写成
const matchClause = new Cypher.Match(myPattern);
const returnClause = new Cypher.Return(myNode);
const clause = Cypher.utils.concat(matchClause, returnClause);
生成的 Cypher 与第一个示例相同
MATCH(this0)
RETURN this0
Cypher.utils.concat 也可以用于动态合并多个子句
const match1 = new Cypher.Match(new Cypher.Node());
const match2 = new Cypher.Match(new Cypher.Node());
const match3 = new Cypher.Match(new Cypher.Node());
const clauses = [match1, match2, match3]
const clause = Cypher.utils.concat(...clauses);
此外,utils.concat 还能接受 undefined,在这种情况下这些值会被忽略。下面的示例产生的 Cypher 与之前相同
const clauses = [match1, match2, undefined, match3]
const clause = Cypher.utils.concat(...clauses);
请注意,Cypher.utils.concat 接受任何子句,但不保证生成的 Cypher 有效。
|
不能将同一个子句传递两次给 |