Defined in: packages/core/src/models/BinarySelectQuery.ts:34
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:42
Parameters ​
left ​
operator ​
string
right ​
Returns ​
BinarySelectQuery
Overrides ​
Properties ​
kind ​
statickind:symbol
Defined in: packages/core/src/models/BinarySelectQuery.ts:35
Overrides ​
__selectQueryType ​
readonly__selectQueryType:"SelectQuery"='SelectQuery'
Defined in: packages/core/src/models/BinarySelectQuery.ts:36
Implementation of ​
headerComments ​
headerComments:
string[] |null=null
Defined in: packages/core/src/models/BinarySelectQuery.ts:37
Implementation of ​
left ​
left:
SelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:38
operator ​
operator:
RawString
Defined in: packages/core/src/models/BinarySelectQuery.ts:39
right ​
right:
SelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:40
comments ​
comments:
string[] |null=null
Defined in: packages/core/src/models/SqlComponent.ts:29
Implementation of ​
Inherited from ​
positionedComments ​
positionedComments:
PositionedComment[] |null=null
Defined in: packages/core/src/models/SqlComponent.ts:32
Implementation of ​
SelectQuery.positionedComments
Inherited from ​
SqlComponent.positionedComments
Methods ​
union() ​
union(
query):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:57
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:69
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:81
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:93
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:105
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:117
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:130
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:146
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:150
Parameters ​
sql ​
string
Returns ​
BinarySelectQuery
intersectRaw() ​
intersectRaw(
sql):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:154
Parameters ​
sql ​
string
Returns ​
BinarySelectQuery
intersectAllRaw() ​
intersectAllRaw(
sql):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:158
Parameters ​
sql ​
string
Returns ​
BinarySelectQuery
exceptRaw() ​
exceptRaw(
sql):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:162
Parameters ​
sql ​
string
Returns ​
BinarySelectQuery
exceptAllRaw() ​
exceptAllRaw(
sql):BinarySelectQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:166
Parameters ​
sql ​
string
Returns ​
BinarySelectQuery
toInsertQuery() ​
toInsertQuery(
options):InsertQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:175
Converts this query into an INSERT statement definition.
Parameters ​
options ​
Returns ​
Remarks ​
The underlying simple query may be reordered so that column order matches the requested insert columns.
Implementation of ​
toUpdateQuery() ​
toUpdateQuery(
options):UpdateQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:183
Converts this query into an UPDATE statement definition.
Parameters ​
options ​
Returns ​
Remarks ​
The conversion can reorder the SELECT list produced by toSimpleQuery.
Implementation of ​
toDeleteQuery() ​
toDeleteQuery(
options):DeleteQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:191
Converts this query into a DELETE statement definition.
Parameters ​
options ​
Returns ​
Remarks ​
The conversion can reorder the SELECT list produced by toSimpleQuery.
Implementation of ​
toMergeQuery() ​
toMergeQuery(
options):MergeQuery
Defined in: packages/core/src/models/BinarySelectQuery.ts:199
Converts this query into a MERGE statement definition.
Parameters ​
options ​
Returns ​
Remarks ​
The conversion can reorder the SELECT list produced by toSimpleQuery.
Implementation of ​
toSource() ​
toSource(
alias):SourceExpression
Defined in: packages/core/src/models/BinarySelectQuery.ts:205
Parameters ​
alias ​
string = "subq"
Returns ​
setParameter() ​
setParameter(
name,value):this
Defined in: packages/core/src/models/BinarySelectQuery.ts:217
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:227
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:15
Returns ​
symbol
Implementation of ​
Inherited from ​
accept() ​
accept<
T>(visitor):T
Defined in: packages/core/src/models/SqlComponent.ts:19
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:23
Parameters ​
formatter ​
SqlComponentVisitor<string>
Returns ​
string
Implementation of ​
Inherited from ​
addPositionedComments() ​
addPositionedComments(
position,comments):void
Defined in: packages/core/src/models/SqlComponent.ts:37
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:56
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:66
Get all positioned comments as a flat array in order (before, after)
Returns ​
string[]
Implementation of ​
SelectQuery.getAllPositionedComments