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 7b51df2c_3f9e_94f1_8b5a_2751ae5d0ed2["buildSetOperationQuery()"] 3977a3fd_2f08_73b1_4df4_3d0fd1858514["PgDialect"] 7b51df2c_3f9e_94f1_8b5a_2751ae5d0ed2 -->|defined in| 3977a3fd_2f08_73b1_4df4_3d0fd1858514 b2ea6cdf_c2fc_2a55_86dc_57e47a8deb11["buildSetOperations()"] b2ea6cdf_c2fc_2a55_86dc_57e47a8deb11 -->|calls| 7b51df2c_3f9e_94f1_8b5a_2751ae5d0ed2 style 7b51df2c_3f9e_94f1_8b5a_2751ae5d0ed2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-orm/src/pg-core/dialect.ts lines 468–511
buildSetOperationQuery({
leftSelect,
setOperator: { type, isAll, rightSelect, limit, orderBy, offset },
}: { leftSelect: SQL; setOperator: PgSelectConfig['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 Sql syntax, Table from one of the SELECTs cannot be used in global ORDER clause
for (const singleOrderBy of orderBy) {
if (is(singleOrderBy, PgColumn)) {
orderByValues.push(sql.identifier(singleOrderBy.name));
} else if (is(singleOrderBy, SQL)) {
for (let i = 0; i < singleOrderBy.queryChunks.length; i++) {
const chunk = singleOrderBy.queryChunks[i];
if (is(chunk, PgColumn)) {
singleOrderBy.queryChunks[i] = sql.identifier(chunk.name);
}
}
orderByValues.push(sql`${singleOrderBy}`);
} else {
orderByValues.push(sql`${singleOrderBy}`);
}
}
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
Defined In
Called By
Source
Frequently Asked Questions
What does buildSetOperationQuery() do?
buildSetOperationQuery() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/pg-core/dialect.ts.
Where is buildSetOperationQuery() defined?
buildSetOperationQuery() is defined in drizzle-orm/src/pg-core/dialect.ts at line 468.
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