Defined in: packages/core/src/models/BinarySelectQuery.ts:25
Represents a binary SELECT expression (UNION/INTERSECT/EXCEPT) composed from two SelectQuery values.
Example
const parts = [
SelectQueryParser.parse('SELECT id, name FROM users').toSimpleQuery(),
SelectQueryParser.parse('SELECT id, name FROM archived_users').toSimpleQuery()
];
const unionQuery = QueryBuilder.buildBinaryQuery(parts, 'union');
Related tests: packages/core/tests/models/SelectQueryUnion.test.ts
Extends
Implements
Constructors
Constructor
new BinarySelectQuery(
left
,operator
,right
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:33
Parameters
left
operator
string
right
Returns
BinarySelectQuery
Overrides
Properties
kind
static
kind:symbol
Defined in: packages/core/src/models/BinarySelectQuery.ts:26
Overrides
__selectQueryType
readonly
__selectQueryType:"SelectQuery"
='SelectQuery'
Defined in: packages/core/src/models/BinarySelectQuery.ts:27
Implementation of
headerComments
headerComments:
null
|string
[] =null
Defined in: packages/core/src/models/BinarySelectQuery.ts:28
Implementation of
left
left:
SelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:29
operator
operator:
RawString
Defined in: packages/core/src/models/BinarySelectQuery.ts:30
right
right:
SelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:31
comments
comments:
null
|string
[] =null
Defined in: packages/core/src/models/SqlComponent.ts:27
Implementation of
Inherited from
positionedComments
positionedComments:
null
|PositionedComment
[] =null
Defined in: packages/core/src/models/SqlComponent.ts:30
Implementation of
SelectQuery
.positionedComments
Inherited from
SqlComponent
.positionedComments
Methods
union()
union(
query
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:48
Appends another query to this binary query using UNION as the operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.
Parameters
query
The query to append with UNION
Returns
BinarySelectQuery
A new BinarySelectQuery representing "(this) UNION query"
unionAll()
unionAll(
query
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:60
Appends another query to this binary query using UNION ALL as the operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.
Parameters
query
The query to append with UNION ALL
Returns
BinarySelectQuery
A new BinarySelectQuery representing "(this) UNION ALL query"
intersect()
intersect(
query
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:72
Appends another query to this binary query using INTERSECT as the operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.
Parameters
query
The query to append with INTERSECT
Returns
BinarySelectQuery
A new BinarySelectQuery representing "(this) INTERSECT query"
intersectAll()
intersectAll(
query
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:84
Appends another query to this binary query using INTERSECT ALL as the operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.
Parameters
query
The query to append with INTERSECT ALL
Returns
BinarySelectQuery
A new BinarySelectQuery representing "(this) INTERSECT ALL query"
except()
except(
query
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:96
Appends another query to this binary query using EXCEPT as the operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.
Parameters
query
The query to append with EXCEPT
Returns
BinarySelectQuery
A new BinarySelectQuery representing "(this) EXCEPT query"
exceptAll()
exceptAll(
query
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:108
Appends another query to this binary query using EXCEPT ALL as the operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.
Parameters
query
The query to append with EXCEPT ALL
Returns
BinarySelectQuery
A new BinarySelectQuery representing "(this) EXCEPT ALL query"
appendSelectQuery()
appendSelectQuery(
operator
,query
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:121
Appends another query to this binary query using the specified operator. This creates a new BinarySelectQuery where the left side is this binary query and the right side is the provided query.
Parameters
operator
string
SQL operator to use (e.g. 'union', 'union all', 'intersect', 'except')
query
The query to append with the specified operator
Returns
BinarySelectQuery
A new BinarySelectQuery representing "(this) [operator] query"
unionRaw()
unionRaw(
sql
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:137
Appends another query to this binary query using UNION as the operator, accepting a raw SQL string. This method parses the SQL string and appends the resulting query using UNION.
Parameters
sql
string
The SQL string to parse and union
Returns
BinarySelectQuery
A new BinarySelectQuery representing "(this) UNION (parsed query)"
unionAllRaw()
unionAllRaw(
sql
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:141
Parameters
sql
string
Returns
BinarySelectQuery
intersectRaw()
intersectRaw(
sql
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:145
Parameters
sql
string
Returns
BinarySelectQuery
intersectAllRaw()
intersectAllRaw(
sql
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:149
Parameters
sql
string
Returns
BinarySelectQuery
exceptRaw()
exceptRaw(
sql
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:153
Parameters
sql
string
Returns
BinarySelectQuery
exceptAllRaw()
exceptAllRaw(
sql
):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:157
Parameters
sql
string
Returns
BinarySelectQuery
toSource()
toSource(
alias
):SourceExpression
Defined in: packages/core/src/models/BinarySelectQuery.ts:164
Parameters
alias
string
= "subq"
Returns
SourceExpression
setParameter()
setParameter(
name
,value
):this
Defined in: packages/core/src/models/BinarySelectQuery.ts:176
Sets the value of a parameter by name in this query.
Parameters
name
string
Parameter name
value
Value to set
Returns
this
Implementation of
toSimpleQuery()
toSimpleQuery():
SimpleSelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:186
Converts this BinarySelectQuery to a SimpleSelectQuery using QueryBuilder. This enables CTE management on binary queries by wrapping them as subqueries.
Returns
A SimpleSelectQuery representation of this binary query
Implementation of
getKind()
getKind():
symbol
Defined in: packages/core/src/models/SqlComponent.ts:13
Returns
symbol
Implementation of
Inherited from
accept()
accept<
T
>(visitor
):T
Defined in: packages/core/src/models/SqlComponent.ts:17
Type Parameters
T
T
Parameters
visitor
SqlComponentVisitor
<T
>
Returns
T
Implementation of
Inherited from
toSqlString()
toSqlString(
formatter
):string
Defined in: packages/core/src/models/SqlComponent.ts:21
Parameters
formatter
SqlComponentVisitor
<string
>
Returns
string
Implementation of
Inherited from
addPositionedComments()
addPositionedComments(
position
,comments
):void
Defined in: packages/core/src/models/SqlComponent.ts:35
Add comments at a specific position
Parameters
position
"before"
| "after"
comments
string
[]
Returns
void
Implementation of
SelectQuery
.addPositionedComments
Inherited from
SqlComponent
.addPositionedComments
getPositionedComments()
getPositionedComments(
position
):string
[]
Defined in: packages/core/src/models/SqlComponent.ts:54
Get comments for a specific position
Parameters
position
"before"
| "after"
Returns
string
[]
Implementation of
SelectQuery
.getPositionedComments
Inherited from
SqlComponent
.getPositionedComments
getAllPositionedComments()
getAllPositionedComments():
string
[]
Defined in: packages/core/src/models/SqlComponent.ts:64
Get all positioned comments as a flat array in order (before, after)
Returns
string
[]
Implementation of
SelectQuery
.getAllPositionedComments