UNPKG

@neo4j/cypher-builder

Version:

A programmatic API for building Cypher queries for Neo4j

52 lines (51 loc) 1.51 kB
"use strict"; /* * Copyright (c) "Neo4j" * Neo4j Sweden AB [http://neo4j.com] */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Union = void 0; const pad_block_1 = require("../utils/pad-block"); const Clause_1 = require("./Clause"); /** * @see {@link https://neo4j.com/docs/cypher-manual/current/clauses/union/ | Cypher Documentation} * @group Clauses */ class Union extends Clause_1.Clause { subqueries = []; unionType; constructor(...subqueries) { super(); this.subqueries = subqueries.map((s) => s.getRoot()); this.addChildren(...subqueries); } all() { this.unionType = "ALL"; return this; } /** * Adds the clause `DISTINCT` after `UNION` * @since Neo4j.19 */ distinct() { this.unionType = "DISTINCT"; return this; } /** * If importWithCypher is provided, it will be added at the beginning of each subquery except first * @internal */ getCypher(env) { const subqueriesStr = this.subqueries.map((s) => this.getSubqueryCypher(s, env)); const unionTypeStr = this.unionType ? ` ${this.unionType}` : ""; return subqueriesStr.join(`\nUNION${unionTypeStr}\n`); } getSubqueryCypher(node, env) { const subqueryStr = node.getCypher(env); if (node instanceof Union) { return `{\n${(0, pad_block_1.padBlock)(subqueryStr)}\n}`; } return subqueryStr; } } exports.Union = Union;