迁移至 Cypher Builder 3

本指南详细说明了将 Cypher® Builder 版本 2 迁移到版本 3 所需的所有更改。

如果必须支持 Neo4j 4,请继续使用 Cypher Builder 2.x,否则迁移至版本 3。

兼容性更改

最低 Node 引擎已更改为 20.0.0

Node.js 16 不再受支持。请将 Node.js 更新至 20.0.0 或更高版本。

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)
}

已删除 labelOperator

已从 .build 方法中移除选项 labelOperator。在使用多个标签时,运算符 & 现在是默认运算符。

不再受支持

const { cypher, params } = matchQuery.build({
    labelOperator: "&",
});

之前

MATCH (this1:Movie:Film)

之后

MATCH (this1:Movie&Film)

标签运算符 : 已不再受支持。

已删除 Call 中的 .importWith

请从 Call 子句中移除 .importWith,改用构造函数参数。

不再受支持

const clause = new Cypher.Call(nestedClause).importWith(movieNode, actorNode);
CALL {
    WITH var0, var1
    // Nested clause
}

之后

const clause = new Cypher.Call(nestedClause, [movieNode, actorNode]);
CALL (var0, var1){
    // Nested clause
}

已删除对 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 构造函数中的额外参数,改用 indo 方法。

例如,要创建以下 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);

其他破坏性更改

已从 concat 子句中移除 .children 方法

const query = Cypher.utils.concat(clause1, clause2);
query.children; // No longer supported

已移除类型 Operation

类型 Cypher.Operation 已不再可用,请改用 Cypher.Expr

之前

const myOperation: Cypher.Operation = Cypher.and()

之后

const myOperation: Cypher.Expr = Cypher.and()

其他更改

更改了 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 精确输出的项目。

© . This site is unofficial and not affiliated with Neo4j, Inc.