Skip to content
# Class: BinarySelectQuery

Defined in: packages/core/src/models/BinarySelectQuery.ts:25

Represents a binary SELECT expression (UNION/INTERSECT/EXCEPT) composed from two SelectQuery values.

Example

typescript
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

SelectQuery

operator

string

SelectQuery

Returns

BinarySelectQuery

Overrides

SqlComponent.constructor

Properties

kind

static kind: symbol

Defined in: packages/core/src/models/BinarySelectQuery.ts:26

Overrides

SqlComponent.kind


__selectQueryType

readonly __selectQueryType: "SelectQuery" = 'SelectQuery'

Defined in: packages/core/src/models/BinarySelectQuery.ts:27

Implementation of

SelectQuery.__selectQueryType


headerComments

headerComments: null | string[] = null

Defined in: packages/core/src/models/BinarySelectQuery.ts:28

Implementation of

SelectQuery.headerComments


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

SelectQuery.comments

Inherited from

SqlComponent.comments


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

SelectQuery

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

SelectQuery

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

SelectQuery

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

SelectQuery

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

SelectQuery

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

SelectQuery

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

SelectQuery

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

SqlParameterValue

Value to set

Returns

this

Implementation of

SelectQuery.setParameter


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

SimpleSelectQuery

A SimpleSelectQuery representation of this binary query

Implementation of

SelectQuery.toSimpleQuery


getKind()

getKind(): symbol

Defined in: packages/core/src/models/SqlComponent.ts:13

Returns

symbol

Implementation of

SelectQuery.getKind

Inherited from

SqlComponent.getKind


accept()

accept<T&gt;(visitor): T

Defined in: packages/core/src/models/SqlComponent.ts:17

Type Parameters

T

T

Parameters

visitor

SqlComponentVisitor<T&gt;

Returns

T

Implementation of

SelectQuery.accept

Inherited from

SqlComponent.accept


toSqlString()

toSqlString(formatter): string

Defined in: packages/core/src/models/SqlComponent.ts:21

Parameters

formatter

SqlComponentVisitor<string&gt;

Returns

string

Implementation of

SelectQuery.toSqlString

Inherited from

SqlComponent.toSqlString


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

Inherited from

SqlComponent.getAllPositionedComments

Released under the MIT License.