UNPKG

@neo4j/cypher-builder

Version:

A programmatic API for building Cypher queries for Neo4j

57 lines (56 loc) 1.8 kB
"use strict"; /* * Copyright (c) "Neo4j" * Neo4j Sweden AB [http://neo4j.com] */ 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 { _variable; propertyPath; /** * @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;