| 2769 | } |
| 2770 | |
| 2771 | private buildUnionQuery( |
| 2772 | separator: 'union' | 'union all', |
| 2773 | others: (QueryBuilder<any> | NativeQueryBuilder)[], |
| 2774 | ): QueryBuilder<Entity> { |
| 2775 | const all = [this as unknown as QueryBuilder<any>, ...others]; |
| 2776 | const parts: string[] = []; |
| 2777 | const params: unknown[] = []; |
| 2778 | |
| 2779 | for (const qb of all) { |
| 2780 | const compiled = qb instanceof QueryBuilder ? qb.toQuery() : qb.compile(); |
| 2781 | parts.push(`(${compiled.sql})`); |
| 2782 | params.push(...compiled.params); |
| 2783 | } |
| 2784 | |
| 2785 | const result = this.clone(true) as unknown as QueryBuilder<Entity>; |
| 2786 | result.#state.unionQuery = { sql: parts.join(` ${separator} `), params }; |
| 2787 | return result; |
| 2788 | } |
| 2789 | |
| 2790 | /** |
| 2791 | * Adds a Common Table Expression (CTE) to the query. |