字面量
可以使用 Cypher®.Literal 定义字面量值。字面量的行为类似参数,但它们会将提供的值直接注入到 Cypher 中,并在需要时进行序列化。例如
const movie = new Cypher.Node();
const titleProp = movie.property(movie);
const titleLiteral = new Cypher.Literal("The Matrix")
const query = new Cypher.Match(new Cypher.Pattern(movie, { labels: ["Movie"] })).where(Cypher.eq(titleProp, titleLiteral)).return(titleLiteral);
const {cypher, params} = query.build();
Cypher
MATCH (this0:Movie)
WHERE this0[this0] = "The Matrix"
RETURN this0, "The Matrix"
参数
{ }
请注意,值 The Matrix 并未直接注入,而是被正确序列化为 Cypher 中的字符串。
以下值由 Literal 支持
-
字符串:
Cypher.Literal("Hello")→"Hello" -
数字:
Cypher.Literal(5)→5 -
布尔值:
Cypher.Literal(true)→true -
数组:
Cypher.Literal([5, "Hello"])→[5, "Hello"] -
空值:
Cypher.Literal(null)→NULL
|
通常建议对用户输入使用 |