迁移至 Cypher Builder 3
本指南详细说明了将 Cypher® Builder 版本 2 迁移到版本 3 所需的所有更改。
|
如果必须支持 Neo4j 4,请继续使用 Cypher Builder 2.x,否则迁移至版本 3。 |
Cypher 4 不再受支持
Cypher 4 以及 Neo4j 4 数据库不再受支持。Cypher Builder 3 面向 Cypher 5 和 25。
以下功能仅适用于 Cypher 4,已从 Cypher Builder 中移除。
已删除在 Cypher 5 中被弃用的函数
以下函数在 Cypher 5 中仍受支持,但已被弃用。它们已从 Cypher Builder 中移除
-
distance已被point.distance取代 -
id已被elementId取代
已删除对 size 中模式的支持
不再受支持
Cypher.size(new Cypher.Pattern(node));
size((this0));
改用 Cypher.Count
new Cypher.Count(new Cypher.Pattern(node));
COUNT {
(this0)
}
已删除对 APOC 的支持
Cypher Builder 3 不再支持任何 APOC 函数或过程。以下内容不再可用
-
apoc.util.validate -
apoc.util.validatePredicate -
apoc.date.convertFormat -
apoc.cypher.runFirstColumnMany -
apoc.cypher.runFirstColumnSingle
要使用 APOC 方法,请创建一个 自定义函数或过程。例如
function validate(
predicate: Cypher.Predicate,
message: string,
params: Cypher.List | Cypher.Literal | Cypher.Map
): Cypher.VoidProcedure {
return new Cypher.VoidProcedure(
"apoc.util.validate",
[predicate, new Cypher.Literal(message), params]
);
}
function validatePredicate(predicate: Cypher.Predicate, message: string): Cypher.Function {
return new Cypher.Function("
apoc.util.validatePredicate",
[predicate, new Cypher.Literal(message), new Cypher.Literal([0])]
);
}
API 更改
以下更改旨在提升 Cypher Builder API 的一致性。
ListComprehension
已移除构造函数的第二个参数
已移除 ListComprehension 构造函数的第二个参数,改用 .in。
之前
new Cypher.ListComprehension(variable, new Cypher.Literal([1, 2]));
之后
new Cypher.ListComprehension(variable).in(new Cypher.Literal([1, 2]));
在这两种情况下,生成的列表推导相同
[var0 IN [1, 2]]
ListComprehension 的 .in 方法不再在调用两次时抛出异常
ListComprehension 的 .in 方法在被调用两次时不再抛出错误,而是覆盖先前的表达式。
之前,以下代码会抛出错误
new Cypher.ListComprehension(variable).in(new Cypher.Literal([1, 2])).in(new Cypher.Literal([1]))
之后,它会生成以下 Cypher
[var0 IN [1]]
请注意,如果省略第一个 .in,仍会生成相同的 Cypher
new Cypher.ListComprehension(variable).in(new Cypher.Literal([1]))
Foreach
已删除 Cypher.Foreach 构造函数中的额外参数
已移除 Cypher.Foreach 构造函数中的额外参数,改用 in 与 do 方法。
例如,要创建以下 Cypher
FOREACH (var0 IN [1, 2, 3] |
CREATE (this1:Movie)
SET
this1.id = var0
)
之前
const list = new Cypher.Literal([1, 2, 3]);
const variable = new Cypher.Variable();
const movieNode = new Cypher.Node();
const createMovie = new Cypher.Create(new Cypher.Pattern(movieNode, { labels: ["Movie"] })).set([
movieNode.property("id"),
variable,
]);
const foreachClause = new Cypher.Foreach(variable, list, createMovie);
之后
const list = new Cypher.Literal([1, 2, 3]);
const variable = new Cypher.Variable();
const movieNode = new Cypher.Node();
const createMovie = new Cypher.Create(new Cypher.Pattern(movieNode, { labels: ["Movie"] })).set([
movieNode.property("id"),
variable,
]);
const foreachClause = new Cypher.Foreach(variable).in(list).do(createMovie);
其他更改
更改了 Cypher 格式化
生成的 Cypher 已更改,以更好地遵循 Cypher 风格指南 推荐的最佳实践。
例如:
之前
CALL {
CREATE (this0:Movie)
SET
this0.id = "The Matrix"
RETURN this0
}
RETURN this0
之后
CALL {
CREATE (this0:Movie)
SET this0.id = 'The Matrix'
RETURN this0
}
RETURN this0
这不会影响行为本身,也不应导致任何破坏性更改。但它可能会影响那些检查或测试 Cypher Builder 生成的 Cypher 精确输出的项目。