Concatenate clauses
In most cases, clauses can be concatenated by using chained methods, for example:
new Cypher.Match(myPattern).return(myNode);
MATCH(this0)
RETURN this0
However, in some cases, you must concatenate clauses manually. This may be caused by:
-
Chained methods not being available.
-
Dynamic number of clauses in a query.
-
Composite clauses that have been generated separately.
-
Using
Cypher®.Raw.
For these cases, use the helper utility Cypher®.utils.concat.
This function accepts any number of clauses and concatenates them in the provided order.
For instance, the previous example could be written as:
const matchClause = new Cypher.Match(myPattern);
const returnClause = new Cypher.Return(myNode);
const clause = Cypher.utils.concat(matchClause, returnClause);
The resulting Cypher® is identical to the first example:
MATCH(this0)
RETURN this0
Cypher®.utils.concat can also be used to merge multiple clauses dynamically:
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);
Additionally, utils.concat also accepts undefined and, in this case, those values are ignored.
The following example produces the same Cypher® as before:
const clauses = [match1, match2, undefined, match3]
const clause = Cypher.utils.concat(...clauses);
Note that Cypher®.utils.concat accepts any clause and does not ensure that the resulting Cypher is valid.
|
It is not possible to pass the same clause twice to |