Query

Class representing an SQL SELECT statement on which query clauses can be built.

Constructors

Link copied to clipboard
constructor(set: FieldSet, where: Op<Boolean>?)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Whether the SQL statement is meant to be performed as part of a batch execution.

Link copied to clipboard
var limit: Int?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override var set: FieldSet
Link copied to clipboard
open override val statement: Query
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
inline fun adjustColumnSet(body: ColumnSet.() -> ColumnSet): Query

Assigns a new column set, either a Table or a Join, by changing the source property of this query's set, while preserving its fields property.

Link copied to clipboard
Link copied to clipboard
fun adjustHaving(body: Op<Boolean>?.() -> Op<Boolean>): Query
Link copied to clipboard
inline fun adjustSelect(body: ColumnSet.(FieldSet) -> Query): Query

Assigns a new selection of columns, by changing the fields property of this query's set, while preserving its source property.

Link copied to clipboard
fun adjustWhere(body: Op<Boolean>?.() -> Op<Boolean>): Query

Changes the where field of this query.

Link copied to clipboard

Mutate Query instance and add andPart to having condition with and operator.

Link copied to clipboard

Mutate Query instance and add andPart to where condition with and operator.

Link copied to clipboard
open override fun arguments(): List<List<Pair<IColumnType<*>, Any?>>>
Link copied to clipboard
Link copied to clipboard
open override fun copy(): Query

Creates a new Query instance using all stored properties of this SELECT query.

Link copied to clipboard
open fun copyTo(other: Query)
Link copied to clipboard
open override fun count(): Long

Returns the number of results retrieved after query execution.

Link copied to clipboard
open override fun empty(): Boolean

Returns whether any results were retrieved by query execution.

Link copied to clipboard

Returns only distinct results from this query that are NOT common to the results of other.

Link copied to clipboard
open fun execute(transaction: JdbcTransaction): ResultApi?

Executes the SQL statement directly in the provided transaction and returns the generated result, or null if either no result was retrieved or if the transaction blocked statement execution.

Link copied to clipboard

Determines the exact way that an SQL statement is executed in a transaction and applies any necessary logic before returning the result generated by the executed statement.

Link copied to clipboard
fun fetchBatchedResults(batchSize: Int = 1000, sortOrder: SortOrder = SortOrder.ASC): Iterable<Iterable<ResultRow>>

Iterates over multiple executions of this SELECT query with its LIMIT clause set to batchSize until the amount of results retrieved from the database is less than batchSize.

Link copied to clipboard
Link copied to clipboard
open override fun forUpdate(option: ForUpdateOption): Query

Returns a new SizedIterable with a locking read for the elements according to the rules specified by option.

Link copied to clipboard
fun groupBy(vararg columns: Expression<*>): Query
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Returns only results from this query that are common to the results of other, WITHOUT including any duplicates.

Link copied to clipboard
Link copied to clipboard
open operator override fun iterator(): Iterator<ResultRow>
Link copied to clipboard
open override fun limit(count: Int): Query

Modifies this query to return only count results.

Link copied to clipboard
infix fun <T, R> SizedIterable<T>.mapLazy(f: (T) -> R): SizedIterable<R>

Returns a SizedIterable containing the lazily evaluated results of applying the function f to each original element.

Link copied to clipboard
open override fun notForUpdate(): Query

Returns a new SizedIterable without any locking read for the elements.

Link copied to clipboard
open override fun offset(start: Long): Query

Modifies this query to return only results starting after the specified start.

Link copied to clipboard
open override fun orderBy(vararg order: Pair<Expression<*>, SortOrder>): Query

Modifies this query to sort results according to the provided order of expressions.

fun orderBy(column: Expression<*>, order: SortOrder = SortOrder.ASC): Query

Modifies this query to sort results by the specified column, according to the provided order.

Link copied to clipboard

Mutate Query instance and add orPart to having condition with or operator.

Link copied to clipboard

Mutate Query instance and add orPart to where condition with or operator.

Link copied to clipboard

Uses a transaction connection and an sql string representation to return a precompiled SQL statement, stored as an implementation of PreparedStatementApi.

Link copied to clipboard
open fun prepareSQL(builder: QueryBuilder): String
open override fun prepareSQL(transaction: Transaction, prepared: Boolean): String
Link copied to clipboard
fun AbstractQuery<*>.union(other: Query): Union

Combines all results from this query with the results of other, WITHOUT including duplicates.

Link copied to clipboard

Combines all results from this query with the results of other, WITH duplicates included.

Link copied to clipboard
fun where(predicate: SqlExpressionBuilder.() -> Op<Boolean>): Query
fun where(predicate: Op<Boolean>): Query

Appends a WHERE clause with the specified predicate to this SELECT query.

Link copied to clipboard
open fun withDistinct(value: Boolean): Query
Link copied to clipboard
fun withDistinctOn(vararg columns: Column<*>): Query

fun withDistinctOn(vararg columns: Pair<Column<*>, SortOrder>): Query

Specifies that the SELECT query should retrieve distinct results based on the given list of columns with sort orders. This method sets a DISTINCT ON clause and may reorder the results as indicated.