exposed-jdbc/src/main/kotlin/org/jetbrains/exposed/v1/jdbc/Query.kt [29:130]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - get() = TransactionManager.current() /** Creates a new [Query] instance using all stored properties of this `SELECT` query. */ override fun copy(): Query = Query(set, where).also { copy -> copyTo(copy) } override fun forUpdate(option: ForUpdateOption): Query { @OptIn(InternalApi::class) this.forUpdate = if (option is ForUpdateOption.NoForUpdateOption || transaction.db.supportsSelectForUpdate) { option } else { null } return this } override fun notForUpdate(): Query { @OptIn(InternalApi::class) forUpdate = ForUpdateOption.NoForUpdateOption return this } /** Modifies this query to return only [count] results. **/ override fun limit(count: Int): Query = apply { limit = count } /** Modifies this query to return only results starting after the specified [start]. **/ override fun offset(start: Long): Query = apply { offset = start } /** Modifies this query to sort results by the specified [column], according to the provided [order]. **/ fun orderBy(column: Expression<*>, order: SortOrder = SortOrder.ASC): Query = orderBy(column to order) /** Modifies this query to sort results according to the provided [order] of expressions. **/ override fun orderBy(vararg order: Pair, SortOrder>): Query = apply { (orderByExpressions as MutableList).addAll(order) } /** * 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. * * This method can be used to set a `DISTINCT ON` clause for the query, which is supported by some SQL dialects * (e.g., PostgreSQL, H2), along with an `ORDER BY` clause for the specified columns. * * @param columns The columns and their sort orders to apply the `DISTINCT ON` clause. * @return The current `Query` instance with the `DISTINCT ON` clause and reordering applied. */ fun withDistinctOn(vararg columns: Pair, SortOrder>): Query = apply { if (columns.isEmpty()) return@apply require(!distinct) { "DISTINCT ON cannot be used with the DISTINCT modifier. Only one of them should be applied." } withDistinctOn(columns = columns.map { it.first }.toTypedArray()) return orderBy(order = columns) } /** * Assigns a new selection of columns, by changing the `fields` property of this query's [set], * while preserving its `source` property. * * @param body Builder for the new column set defined using `select()`, with the current [set]'s `source` * property used as the receiver and the current [set] as an argument. * @sample org.jetbrains.exposed.v1.tests.shared.dml.AdjustQueryTests.testAdjustQuerySlice */ inline fun adjustSelect(body: ColumnSet.(FieldSet) -> Query): Query = apply { set = set.source.body(set).set } /** * 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. * * @param body Builder for the new column set, with the previous column set value as the receiver. * @sample org.jetbrains.exposed.v1.tests.shared.dml.AdjustQueryTests.testAdjustQueryColumnSet */ inline fun adjustColumnSet(body: ColumnSet.() -> ColumnSet): Query { return adjustSelect { oldSlice -> body().select(oldSlice.fields) } } /** * Changes the [where] field of this query. * * @param body Builder for the new `WHERE` condition, with the previous value used as the receiver. * @sample org.jetbrains.exposed.v1.tests.shared.dml.AdjustQueryTests.testAdjustQueryWhere */ fun adjustWhere(body: Op?.() -> Op): Query = apply { where = where.body() } /** * Appends a `WHERE` clause with the specified [predicate] to this `SELECT` query. * * @sample org.jetbrains.exposed.v1.tests.shared.dml.SelectTests.testSelect */ fun where(predicate: () -> Op): Query = where(predicate()) /** * Appends a `WHERE` clause with the specified [predicate] to this `SELECT` query. * * @sample org.jetbrains.exposed.v1.tests.shared.dml.ExistsTests.testExists01 */ fun where(predicate: Op): Query { where?.let { error("WHERE clause is specified twice. Old value = '$it', new value = '$predicate'") } where = predicate return this - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - exposed-r2dbc/src/main/kotlin/org/jetbrains/exposed/v1/r2dbc/Query.kt [34:135]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - get() = TransactionManager.current() /** Creates a new [Query] instance using all stored properties of this `SELECT` query. */ override fun copy(): Query = Query(set, where).also { copy -> copyTo(copy) } override fun forUpdate(option: ForUpdateOption): Query { @OptIn(InternalApi::class) this.forUpdate = if (option is ForUpdateOption.NoForUpdateOption || transaction.db.supportsSelectForUpdate) { option } else { null } return this } override fun notForUpdate(): Query { @OptIn(InternalApi::class) forUpdate = ForUpdateOption.NoForUpdateOption return this } /** Modifies this query to return only [count] results. **/ override fun limit(count: Int): Query = apply { limit = count } /** Modifies this query to return only results starting after the specified [start]. **/ override fun offset(start: Long): Query = apply { offset = start } /** Modifies this query to sort results by the specified [column], according to the provided [order]. **/ fun orderBy(column: Expression<*>, order: SortOrder = SortOrder.ASC): Query = orderBy(column to order) /** Modifies this query to sort results according to the provided [order] of expressions. **/ override fun orderBy(vararg order: Pair, SortOrder>): Query = apply { (orderByExpressions as MutableList).addAll(order) } /** * 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. * * This method can be used to set a `DISTINCT ON` clause for the query, which is supported by some SQL dialects * (e.g., PostgreSQL, H2), along with an `ORDER BY` clause for the specified columns. * * @param columns The columns and their sort orders to apply the `DISTINCT ON` clause. * @return The current `Query` instance with the `DISTINCT ON` clause and reordering applied. */ fun withDistinctOn(vararg columns: Pair, SortOrder>): Query = apply { if (columns.isEmpty()) return@apply require(!distinct) { "DISTINCT ON cannot be used with the DISTINCT modifier. Only one of them should be applied." } withDistinctOn(columns = columns.map { it.first }.toTypedArray()) return orderBy(order = columns) } /** * Assigns a new selection of columns, by changing the `fields` property of this query's [set], * while preserving its `source` property. * * @param body Builder for the new column set defined using `select()`, with the current [set]'s `source` * property used as the receiver and the current [set] as an argument. * @sample org.jetbrains.exposed.v1.r2dbc.sql.tests.shared.dml.AdjustQueryTests.testAdjustQuerySlice */ inline fun adjustSelect(body: ColumnSet.(FieldSet) -> Query): Query = apply { set = set.source.body(set).set } /** * 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. * * @param body Builder for the new column set, with the previous column set value as the receiver. * @sample org.jetbrains.exposed.v1.r2dbc.sql.tests.shared.dml.AdjustQueryTests.testAdjustQueryColumnSet */ inline fun adjustColumnSet(body: ColumnSet.() -> ColumnSet): Query { return adjustSelect { oldSlice -> body().select(oldSlice.fields) } } /** * Changes the [where] field of this query. * * @param body Builder for the new `WHERE` condition, with the previous value used as the receiver. * @sample org.jetbrains.exposed.v1.r2dbc.sql.tests.shared.dml.AdjustQueryTests.testAdjustQueryWhere */ fun adjustWhere(body: Op?.() -> Op): Query = apply { where = where.body() } /** * Appends a `WHERE` clause with the specified [predicate] to this `SELECT` query. * * @sample org.jetbrains.exposed.v1.r2dbc.sql.tests.shared.dml.SelectTests.testSelect */ fun where(predicate: () -> Op): Query = where(predicate()) /** * Appends a `WHERE` clause with the specified [predicate] to this `SELECT` query. * * @sample org.jetbrains.exposed.v1.r2dbc.sql.tests.shared.dml.ExistsTests.testExists01 */ fun where(predicate: Op): Query { where?.let { error("WHERE clause is specified twice. Old value = '$it', new value = '$predicate'") } where = predicate return this - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -