UNPKG

sedk-neo4j

Version:

Cypher builder and validator for Neo4j

40 lines 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Step = void 0; const Variable_1 = require("./Variable"); class Step { constructor() { this.matchParts = []; this.returnParts = []; } match(...varLabels) { if (varLabels.length === 0) { throw new Error('No variable or labels provided'); } this.matchParts.push(...varLabels); return this; } return(...variables) { if (variables.length === 0) { throw new Error('At least one variable must be provided'); } this.returnParts.push(...variables); return this; } getCypher() { const first = this.matchParts[0]; if (first === undefined) { throw new Error('No variable or labels provided'); } const matchArray = (first instanceof Variable_1.Variable) ? [first.name, ...this.matchParts.slice(1).map(label => `${label === null || label === void 0 ? void 0 : label.name}`)] : ['', ...this.matchParts.map(label => `${label === null || label === void 0 ? void 0 : label.name}`)]; return `MATCH (${matchArray.join(':')}) RETURN ${this.returnParts.map(it => it.name).join(', ')}`; } cleanUp() { this.matchParts.length = 0; this.returnParts.length = 0; } } exports.Step = Step; //# sourceMappingURL=Step.js.map