MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / buildUnionQuery

Method buildUnionQuery

packages/sql/src/query/QueryBuilder.ts:2771–2788  ·  view source on GitHub ↗
(
    separator: 'union' | 'union all',
    others: (QueryBuilder<any> | NativeQueryBuilder)[],
  )

Source from the content-addressed store, hash-verified

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.

Callers 2

unionAllMethod · 0.95
unionMethod · 0.95

Calls 5

cloneMethod · 0.95
toQueryMethod · 0.80
pushMethod · 0.80
joinMethod · 0.65
compileMethod · 0.45

Tested by

no test coverage detected