Home / Function/ buildSetOperationQuery() — drizzle-orm Function Reference

buildSetOperationQuery() — drizzle-orm Function Reference

Architecture documentation for the buildSetOperationQuery() function in dialect.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  31499e13_5192_4f89_5474_18778c62f63d["buildSetOperationQuery()"]
  1da3f399_3da2_55ff_342e_fb92de5e010c["SingleStoreDialect"]
  31499e13_5192_4f89_5474_18778c62f63d -->|defined in| 1da3f399_3da2_55ff_342e_fb92de5e010c
  c34ad8eb_a54d_5af8_42dd_3a7fda682b78["buildSetOperations()"]
  c34ad8eb_a54d_5af8_42dd_3a7fda682b78 -->|calls| 31499e13_5192_4f89_5474_18778c62f63d
  3501009a_4117_447e_6d96_3952e8aaae6e["getSQL()"]
  31499e13_5192_4f89_5474_18778c62f63d -->|calls| 3501009a_4117_447e_6d96_3952e8aaae6e
  style 31499e13_5192_4f89_5474_18778c62f63d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-orm/src/singlestore-core/dialect.ts lines 421–464

	buildSetOperationQuery({
		leftSelect,
		setOperator: { type, isAll, rightSelect, limit, orderBy, offset },
	}: { leftSelect: SQL; setOperator: SingleStoreSelectConfig['setOperators'][number] }): SQL {
		const leftChunk = sql`(${leftSelect.getSQL()}) `;
		const rightChunk = sql`(${rightSelect.getSQL()})`;

		let orderBySql;
		if (orderBy && orderBy.length > 0) {
			const orderByValues: (SQL<unknown> | Name)[] = [];

			// The next bit is necessary because the sql operator replaces ${table.column} with `table`.`column`
			// which is invalid SingleStore syntax, Table from one of the SELECTs cannot be used in global ORDER clause
			for (const orderByUnit of orderBy) {
				if (is(orderByUnit, SingleStoreColumn)) {
					orderByValues.push(sql.identifier(this.casing.getColumnCasing(orderByUnit)));
				} else if (is(orderByUnit, SQL)) {
					for (let i = 0; i < orderByUnit.queryChunks.length; i++) {
						const chunk = orderByUnit.queryChunks[i];

						if (is(chunk, SingleStoreColumn)) {
							orderByUnit.queryChunks[i] = sql.identifier(this.casing.getColumnCasing(chunk));
						}
					}

					orderByValues.push(sql`${orderByUnit}`);
				} else {
					orderByValues.push(sql`${orderByUnit}`);
				}
			}

			orderBySql = sql` order by ${sql.join(orderByValues, sql`, `)} `;
		}

		const limitSql = typeof limit === 'object' || (typeof limit === 'number' && limit >= 0)
			? sql` limit ${limit}`
			: undefined;

		const operatorChunk = sql.raw(`${type} ${isAll ? 'all ' : ''}`);

		const offsetSql = offset ? sql` offset ${offset}` : undefined;

		return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
	}

Domain

Subdomains

Calls

Frequently Asked Questions

What does buildSetOperationQuery() do?
buildSetOperationQuery() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/singlestore-core/dialect.ts.
Where is buildSetOperationQuery() defined?
buildSetOperationQuery() is defined in drizzle-orm/src/singlestore-core/dialect.ts at line 421.
What does buildSetOperationQuery() call?
buildSetOperationQuery() calls 1 function(s): getSQL.
What calls buildSetOperationQuery()?
buildSetOperationQuery() is called by 1 function(s): buildSetOperations.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free