Literals
Literal values can be defined with Cypher®.Literal.
Literals behave like parameters, but they will inject the value provided directly into the Cypher®, serializing it as needed.
For instance:
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"
Params
{ }
Note how the value The Matrix is not injected directly, but correctly serialized to a string in Cypher®.
The following values are supported by Literal:
-
String:
Cypher®.Literal("Hello")→"Hello" -
Number:
Cypher®.Literal(5)→5 -
Boolean:
Cypher®.Literal(true)→true -
Array:
Cypher®.Literal([5, "Hello"])→[5, "Hello"] -
Null:
Cypher®.Literal(null)→NULL
|
It is generally recommended to use |