UNPKG

@neo4j/cypher-builder

Version:

A programmatic API for building Cypher queries for Neo4j

69 lines (68 loc) 2.35 kB
"use strict"; /* * 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.PropertyRef = void 0; const ListIndex_1 = require("../expressions/list/ListIndex"); const ListRange_1 = require("../expressions/list/ListRange"); const escape_1 = require("../utils/escape"); /** Reference to a variable property * @group Variables * @example `new Node({labels: ["Movie"]}).property("title")` */ class PropertyRef { /** * @internal */ constructor(variable, ...properties) { this._variable = variable; this.propertyPath = properties; } get variable() { return this._variable; } /** Access individual property via the PropertyRef class, using dot notation or square brackets notation if an expression is provided */ property(prop) { return new PropertyRef(this._variable, ...this.propertyPath, prop); } /** Access individual elements in the list */ index(index) { return (0, ListIndex_1.listIndex)(this, index); } /** Adds a list range operator (`[ .. ]`) */ range(from, to) { return (0, ListRange_1.listRange)(this, from, to); } /** @internal */ getCypher(env) { const variableStr = this.variable.getCypher(env); const propStr = this.propertyPath.map((prop) => this.getPropertyCypher(prop, env)).join(""); return `${variableStr}${propStr}`; } getPropertyCypher(prop, env) { if (typeof prop === "string") { return `.${(0, escape_1.escapeProperty)(prop)}`; } else { const exprStr = prop.getCypher(env); return `[${exprStr}]`; } } } exports.PropertyRef = PropertyRef;