Back to Exposed

Query

docs/api/exposed-r2dbc/org.jetbrains.exposed.v1.r2dbc/-query/index.html

1.2.023.6 KB
Original Source

Query

open class Query(var set: FieldSet, where: Op<Boolean>?) : AbstractQuery<Query> , SuspendExecutable<ResultApi, Query> , SizedIterable<ResultRow>

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

MembersMembers & Extensions

Constructors

Query

Link copied to clipboard

constructor(set: FieldSet, where: Op<Boolean>?)

Types

Companion

Link copied to clipboard

object Companion

Properties

comments

Link copied to clipboard

var comments: Map<AbstractQuery.CommentPosition, String>

distinct

Link copied to clipboard

var distinct: Boolean

distinctOn

Link copied to clipboard

var distinctOn: List<Column<*>>?

fetchSize

Link copied to clipboard

var fetchSize: Int?

groupedByColumns

Link copied to clipboard

var groupedByColumns: List<Expression<*>>

having

Link copied to clipboard

var having: Op<Boolean>?

isAlwaysBatch

Link copied to clipboard

open val isAlwaysBatch: Boolean

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

limit

Link copied to clipboard

var limit: Int?

offset

Link copied to clipboard

var offset: Long

orderByExpressions

Link copied to clipboard

var orderByExpressions: List<Pair<Expression<*>, SortOrder>>

set

Link copied to clipboard

open override var set: FieldSet

statement

Link copied to clipboard

open override val statement: Query

The actual Exposed Statement on which the specific execution logic should be used.

targets

Link copied to clipboard

val targets: List<Table>

type

Link copied to clipboard

val type: StatementType

where

Link copied to clipboard

var where: Op<Boolean>?

Functions

adjustColumnSet

Link copied to clipboard

inline fun adjustColumnSet(body: ColumnSet.() -> ColumnSet): Query

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

adjustComments

Link copied to clipboard

fun adjustComments(position: AbstractQuery.CommentPosition, content: String?): Query

adjustHaving

Link copied to clipboard

fun adjustHaving(body: Op<Boolean>?.() -> Op<Boolean>): Query

adjustSelect

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.

adjustWhere

Link copied to clipboard

fun adjustWhere(body: Op<Boolean>?.() -> Op<Boolean>): Query

Changes the where field of this query.

andHaving

Link copied to clipboard

fun Query.andHaving(andPart: () -> Op<Boolean>): Query

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

andWhere

Link copied to clipboard

fun Query.andWhere(andPart: () -> Op<Boolean>): Query

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

arguments

Link copied to clipboard

open override fun arguments(): List<List<Pair<IColumnType<*>, Any?>>>

collect

Link copied to clipboard

open suspend override fun collect(collector: FlowCollector<ResultRow>)

comment

Link copied to clipboard

fun comment(content: String, position: AbstractQuery.CommentPosition): Query

copy

Link copied to clipboard

open override fun copy(): Query

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

copyTo

Link copied to clipboard

open fun copyTo(other: Query)

count

Link copied to clipboard

open suspend override fun count(): Long

Returns the number of results retrieved after query execution.

empty

Link copied to clipboard

open suspend override fun empty(): Boolean

Returns whether any results were retrieved by query execution.

except

Link copied to clipboard

fun AbstractQuery<*>.except(other: Query): Except

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

execute

Link copied to clipboard

open suspend fun execute(transaction: R2dbcTransaction): 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.

executeInternal

Link copied to clipboard

open suspend override fun R2dbcPreparedStatementApi.executeInternal(transaction: R2dbcTransaction): R2dbcResult?

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.

fetchBatchedResults

Link copied to clipboard

fun fetchBatchedResults(batchSize: Int = 1000, sortOrder: SortOrder = SortOrder.ASC): Flow<Flow<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.

fetchSize

Link copied to clipboard

fun fetchSize(n: Int): Query

forUpdate

Link copied to clipboard

open override fun forUpdate(option: ForUpdateOption = ForUpdateOption.ForUpdate): Query

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

groupBy

Link copied to clipboard

fun groupBy(vararg columns: Expression<*>): Query

hasCustomForUpdateState

Link copied to clipboard

fun hasCustomForUpdateState(): Boolean

having

Link copied to clipboard

fun having(op: () -> Op<Boolean>): Query

intersect

Link copied to clipboard

fun AbstractQuery<*>.intersect(other: Query): Intersect

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

isForUpdate

Link copied to clipboard

fun isForUpdate(): Boolean

limit

Link copied to clipboard

open override fun limit(count: Int): Query

Modifies this query to return only count results.

mapLazy

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.

notForUpdate

Link copied to clipboard

open override fun notForUpdate(): Query

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

offset

Link copied to clipboard

open override fun offset(start: Long): Query

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

orderBy

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.

orHaving

Link copied to clipboard

fun Query.orHaving(orPart: () -> Op<Boolean>): Query

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

orWhere

Link copied to clipboard

fun Query.orWhere(orPart: () -> Op<Boolean>): Query

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

prepared

Link copied to clipboard

open suspend fun prepared(transaction: R2dbcTransaction, sql: String): R2dbcPreparedStatementApi

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

prepareSQL

Link copied to clipboard

open fun prepareSQL(builder: QueryBuilder): String

open override fun prepareSQL(transaction: Transaction, prepared: Boolean): String

union

Link copied to clipboard

fun AbstractQuery<*>.union(other: Query): Union

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

unionAll

Link copied to clipboard

fun AbstractQuery<*>.unionAll(other: Query): UnionAll

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

where

Link copied to clipboard

fun where(predicate: () -> Op<Boolean>): Query

fun where(predicate: Op<Boolean>): Query

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

withDistinct

Link copied to clipboard

open fun withDistinct(value: Boolean): Query

withDistinctOn

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.

Generated by Dokka © 2026 Copyright