@neo4j/cypher-builder
Version:
A programmatic API for building Cypher queries for Neo4j
52 lines (51 loc) • 1.96 kB
JavaScript
;
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.WithSetRemove = void 0;
const compile_cypher_if_exists_1 = require("../../../utils/compile-cypher-if-exists");
const Remove_1 = require("../../sub-clauses/Remove");
const Set_1 = require("../../sub-clauses/Set");
const Mixin_1 = require("../Mixin");
class WithSetRemove extends Mixin_1.Mixin {
subClauses;
/** Append a `SET` clause. Allowing to assign variable properties to values.
* @see {@link https://neo4j.com/docs/cypher-manual/current/clauses/set/ | Cypher Documentation}
*/
set(...params) {
this.subClauses ??= []; // Due to mixin wonkiness, we need to lazy initialize
const lastSubClause = this.subClauses.at(-1);
if (lastSubClause instanceof Set_1.SetClause) {
lastSubClause.addParams(...params);
}
else {
this.subClauses.push(new Set_1.SetClause(this, params));
}
return this;
}
/** Append a `REMOVE` clause.
* @see {@link https://neo4j.com/docs/cypher-manual/current/clauses/remove/ | Cypher Documentation}
*/
remove(...properties) {
this.subClauses ??= []; // Due to mixin wonkiness, we need to lazy initialize
const lastSubClause = this.subClauses.at(-1);
if (lastSubClause instanceof Remove_1.RemoveClause) {
lastSubClause.addParams(...properties);
}
else {
this.subClauses.push(new Remove_1.RemoveClause(this, properties));
}
return this;
}
compileSetCypher(env) {
const subclausesCypher = (this.subClauses || [])
.map((subclause) => {
return (0, compile_cypher_if_exists_1.compileCypherIfExists)(subclause, env, { prefix: "\n" });
})
.join("");
return subclausesCypher;
}
}
exports.WithSetRemove = WithSetRemove;