@neo4j/cypher-builder
Version:
A programmatic API for building Cypher queries for Neo4j
55 lines (54 loc) • 1.82 kB
JavaScript
;
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuantifiedPath = void 0;
const pad_block_1 = require("../../utils/pad-block");
const PathAssign_1 = require("../PathAssign");
/**
* @group Patterns
*/
class QuantifiedPath {
constructor(...patterns) {
this.patterns = [];
this.patterns = patterns;
}
assignTo(variable) {
return new PathAssign_1.PathAssign(this, variable);
}
/**
* @internal
*/
getCypher(env) {
const patternsStrings = this.patterns.map((pattern) => {
return pattern.getCypher(env);
});
const firstPattern = patternsStrings.shift() ?? "";
if (patternsStrings.length > 0) {
const remainingPatternsString = this.getRemainingPatternsString(patternsStrings);
return `${firstPattern}\n${remainingPatternsString}`;
}
return firstPattern;
}
getRemainingPatternsString(patternStrings) {
const remainingPatternsStr = patternStrings.join("\n");
return (0, pad_block_1.padBlock)(remainingPatternsStr, 6);
}
}
exports.QuantifiedPath = QuantifiedPath;