UNPKG

@neo4j/cypher-builder

Version:

A programmatic API for building Cypher queries for Neo4j

79 lines (78 loc) 3.79 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. */ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var Unwind_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.Unwind = void 0; const __1 = __importDefault(require("..")); const compile_cypher_if_exists_1 = require("../utils/compile-cypher-if-exists"); const Clause_1 = require("./Clause"); const WithCreate_1 = require("./mixins/clauses/WithCreate"); const WithMatch_1 = require("./mixins/clauses/WithMatch"); const WithMerge_1 = require("./mixins/clauses/WithMerge"); const WithReturn_1 = require("./mixins/clauses/WithReturn"); const WithWith_1 = require("./mixins/clauses/WithWith"); const WithDelete_1 = require("./mixins/sub-clauses/WithDelete"); const WithOrder_1 = require("./mixins/sub-clauses/WithOrder"); const WithSetRemove_1 = require("./mixins/sub-clauses/WithSetRemove"); const Projection_1 = require("./sub-clauses/Projection"); const mixin_1 = require("./utils/mixin"); /** * @see {@link https://neo4j.com/docs/cypher-manual/current/clauses/unwind/ | Cypher Documentation} * @group Clauses */ let Unwind = Unwind_1 = class Unwind extends Clause_1.Clause { constructor(projection) { super(); this.projection = new Projection_1.Projection([projection]); } unwind(clauseOrColumn) { if (clauseOrColumn instanceof Unwind_1) { this.addNextClause(clauseOrColumn); return clauseOrColumn; } else { const newUnwind = new __1.default.Unwind(clauseOrColumn); this.addNextClause(newUnwind); return newUnwind; } } /** @internal */ getCypher(env) { const projectionStr = this.projection.getCypher(env); const deleteCypher = (0, compile_cypher_if_exists_1.compileCypherIfExists)(this.deleteClause, env, { prefix: "\n" }); const setCypher = this.compileSetCypher(env); const orderCypher = (0, compile_cypher_if_exists_1.compileCypherIfExists)(this.orderByStatement, env, { prefix: "\n" }); const nextClause = this.compileNextClause(env); return `UNWIND ${projectionStr}${setCypher}${deleteCypher}${orderCypher}${nextClause}`; } }; exports.Unwind = Unwind; exports.Unwind = Unwind = Unwind_1 = __decorate([ (0, mixin_1.mixin)(WithWith_1.WithWith, WithDelete_1.WithDelete, WithMatch_1.WithMatch, WithReturn_1.WithReturn, WithSetRemove_1.WithSetRemove, WithCreate_1.WithCreate, WithMerge_1.WithMerge, WithOrder_1.WithOrder) ], Unwind);