Package-level declarations

Types

Link copied to clipboard

Expression visitor interceptor for removing table aliases, used by Ktorm internally.

Link copied to clipboard

Base class of DSL builders, provide basic functions used to build assignments for insert or update DSL.

Link copied to clipboard

DSL builder for batch insert statements.

Link copied to clipboard

DSL builder for batch update statements.

Link copied to clipboard
data class CaseWhen<T : Any, R : Any>(val operand: ColumnDeclaring<T>?, val whenClauses: List<Pair<ColumnDeclaring<T>, ColumnDeclaring<R>>> = emptyList(), val elseClause: ColumnDeclaring<R>? = null)

Helper class used to build case-when SQL DSL. See CaseWhenExpression.

Link copied to clipboard
annotation class KtormDsl

Marker annotation for Ktorm DSL builder classes.

Link copied to clipboard
class Query(val database: Database, val expression: QueryExpression)

Query is an abstraction of query operations and the core class of Ktorm's query DSL.

Link copied to clipboard

Special implementation of ResultSet, used to hold the Query results for Ktorm.

Link copied to clipboard
data class QuerySource(val database: Database, val sourceTable: BaseTable<*>, val expression: QuerySourceExpression)

Represents a query source, used in the from clause of a query.

Link copied to clipboard

DSL builder for update statements.

Link copied to clipboard
data class WhenContinuation<T : Any, R : Any>(val parent: CaseWhen<T, R>, val condition: ColumnDeclaring<T>)

Return type for WHEN function, call its extension function THEN to finish a SQL when clause.

Link copied to clipboard

Utility object that creates expressions of window frame bounds.

Functions

Link copied to clipboard

And operator, translated to the and keyword in SQL.

Link copied to clipboard

Order this column or expression in ascending order.

Link copied to clipboard

Wrap this query as Iterable.

Link copied to clipboard
inline fun <K, V> Query.associate(transform: (row: QueryRowSet) -> Pair<K, V>): Map<K, V>

Return a Map containing key-value pairs provided by transform function applied to rows of the query.

Link copied to clipboard
inline fun <K, V> Query.associateBy(keySelector: (row: QueryRowSet) -> K, valueTransform: (row: QueryRowSet) -> V): Map<K, V>

Return a Map containing the values provided by valueTransform and indexed by keySelector functions applied to rows of the query.

Link copied to clipboard
inline fun <K, V, M : MutableMap<in K, in V>> Query.associateByTo(destination: M, keySelector: (row: QueryRowSet) -> K, valueTransform: (row: QueryRowSet) -> V): M

Populate and return the destination mutable map with key-value pairs, where key is provided by the keySelector function and value is provided by the valueTransform function applied to rows of the query.

Link copied to clipboard
inline fun <K, V, M : MutableMap<in K, in V>> Query.associateTo(destination: M, transform: (row: QueryRowSet) -> Pair<K, V>): M

Populate and return the destination mutable map with key-value pairs provided by transform function applied to each row of the query.

Link copied to clipboard

The avg function, translated to avg(column) in SQL.

Link copied to clipboard

The avg function with distinct, translated to avg(distinct column) in SQL.

Link copied to clipboard

Construct insert expressions in the given closure, then batch execute them and return the effected row counts for each expression.

Link copied to clipboard

Construct update expressions in the given closure, then batch execute them and return the effected row counts for each expression.

Link copied to clipboard

Between operator, translated to between .. and .. in SQL.

Link copied to clipboard

Starts a searched case-when DSL.

fun <T : Any> CASE(operand: ColumnDeclaring<T>): CaseWhen<T, Nothing>

Starts a simple case-when DSL with the given operand.

Link copied to clipboard

Cast the current column or expression to the given SqlType.

Link copied to clipboard

Combine this iterable of boolean expressions with the and operator.

Link copied to clipboard
fun count(column: ColumnDeclaring<*>? = null): AggregateExpression<Int>

The count function, translated to count(column) in SQL.

Link copied to clipboard

The count function with distinct, translated to count(distinct column) in SQL.

Link copied to clipboard

Perform a cross join and return a new QuerySource, translated to cross join in SQL.

Link copied to clipboard

The cume_dist window function, translated to cume_dist() in SQL.

Link copied to clipboard
fun <T : BaseTable<*>> Database.delete(table: T, predicate: (T) -> ColumnDeclaring<Boolean>): Int

Delete the records in the table that matches the given predicate.

Link copied to clipboard

Delete all the records in the table.

Link copied to clipboard

The dense_rank window function, translated to dense_rank() in SQL.

Link copied to clipboard

Order this column or expression in descending order, corresponding to the desc keyword in SQL.

Link copied to clipboard
infix operator fun <T : Number> T.div(expr: ColumnDeclaring<T>): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.div(value: T): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.div(expr: ColumnDeclaring<T>): BinaryExpression<T>

Divide operator, translated to / in SQL.

Link copied to clipboard
fun <T : Any, R : Any> CaseWhen<T, R>.ELSE(result: ColumnDeclaring<R>): CaseWhen<T, R>
inline fun <T : Any, R : Any> CaseWhen<T, R>.ELSE(result: R, sqlType: SqlType<R> = SqlType.of() ?: error("Cannot detect the argument's SqlType, please specify manually.")): CaseWhen<T, R>

Specifies the else clause for the case-when DSL.

Link copied to clipboard

Finishes the case-when DSL and returns a CaseWhenExpression.

Link copied to clipboard
infix fun <T : Any> T.eq(expr: ColumnDeclaring<T>): BinaryExpression<Boolean>
infix fun <T : Any> ColumnDeclaring<T>.eq(value: T): BinaryExpression<Boolean>

Equal operator, translated to = in SQL.

Link copied to clipboard

Check if the given query has at least one result, translated to the exists keyword in SQL.

Link copied to clipboard

The first_value window function, translated to first_value(expr) in SQL.

Link copied to clipboard
inline fun <R> Query.flatMap(transform: (row: QueryRowSet) -> Iterable<R>): List<R>

Return a single list of all elements yielded from results of transform function being invoked on each row of the query.

Link copied to clipboard
inline fun <R> Query.flatMapIndexed(transform: (index: Int, row: QueryRowSet) -> Iterable<R>): List<R>

Return a single list of all elements yielded from results of transform function being invoked on each row and its index in the query.

Link copied to clipboard
inline fun <R, C : MutableCollection<in R>> Query.flatMapIndexedTo(destination: C, transform: (index: Int, row: QueryRowSet) -> Iterable<R>): C

Append all elements yielded from results of transform function being invoked on each row and its index in the query, to the given destination.

Link copied to clipboard
inline fun <R, C : MutableCollection<in R>> Query.flatMapTo(destination: C, transform: (row: QueryRowSet) -> Iterable<R>): C

Append all elements yielded from results of transform function being invoked on each row of the query, to the given destination.

Link copied to clipboard
inline fun <R> Query.fold(initial: R, operation: (acc: R, row: QueryRowSet) -> R): R

Accumulate value starting with initial value and applying operation to current accumulator value and each row.

Link copied to clipboard
inline fun <R> Query.foldIndexed(initial: R, operation: (index: Int, acc: R, row: QueryRowSet) -> R): R

Accumulate value starting with initial value and applying operation to current accumulator value and each row with its index in the original query results.

Link copied to clipboard
inline fun Query.forEach(action: (row: QueryRowSet) -> Unit)

Perform the given action on each row of the query.

Link copied to clipboard
inline fun Query.forEachIndexed(action: (index: Int, row: QueryRowSet) -> Unit)

Perform the given action on each row of the query, providing sequential index with the row.

Link copied to clipboard

Wrap the specific table as a QuerySource.

Link copied to clipboard

Perform a full join and return a new QuerySource, translated to full join in SQL.

Link copied to clipboard
fun <T : Any> CachedRowSet.getGeneratedKey(primaryKey: Column<T>): T?

Get generated key from the row set.

Link copied to clipboard

Greater operator, translated to > in SQL.

Link copied to clipboard

Greater-eq operator, translated to >= in SQL.

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

Specify the group by clause of this query using the given columns or expressions.

Link copied to clipboard

Greater operator, translated to > in SQL.

Link copied to clipboard

Greater-eq operator, translated to >= in SQL.

Link copied to clipboard
inline fun Query.having(condition: () -> ColumnDeclaring<Boolean>): Query

Specify the having clause of this query using the expression returned by the given callback function.

Specify the having clause of this query using the given condition expression.

Link copied to clipboard
fun <T : Any> ColumnDeclaring<T>.inList(vararg list: T): InListExpression

In-list operator, translated to the in keyword in SQL.

Link copied to clipboard

Perform an inner join and return a new QuerySource, translated to inner join in SQL.

Link copied to clipboard
fun <T : BaseTable<*>> Database.insert(table: T, block: AssignmentsBuilder.(T) -> Unit): Int

Construct an insert expression in the given closure, then execute it and return the effected row count.

Link copied to clipboard

Construct an insert expression in the given closure, then execute it and return the auto-generated key.

Link copied to clipboard
fun Query.insertTo(table: BaseTable<*>, vararg columns: Column<*>): Int

Insert the current Query's results into the given table, useful when transfer data from a table to another table.

Link copied to clipboard

Check if the current column or expression is not null, translated to is not null in SQL.

Link copied to clipboard

Check if the current column or expression is null, translated to is null in SQL.

Link copied to clipboard

Return a new-created Query object, left joining all the reference tables, and selecting all columns of them.

Link copied to clipboard
fun <A : Appendable> Query.joinTo(buffer: A, separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: (row: QueryRowSet) -> CharSequence): A

Append the string from all rows separated using separator and using the given prefix and postfix if supplied.

Link copied to clipboard
fun Query.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: (row: QueryRowSet) -> CharSequence): String

Create a string from all rows separated using separator and using the given prefix and postfix if supplied.

Link copied to clipboard
fun <T : Any> lag(expr: ColumnDeclaring<T>, offset: Int = 1, defVal: T? = null): WindowFunctionExpression<T>
fun <T : Any> lag(expr: ColumnDeclaring<T>, offset: Int, defVal: ColumnDeclaring<T>): WindowFunctionExpression<T>

The lag window function, translated to lag(expr, offset[, defVal]) in SQL.

Link copied to clipboard

The last_value window function, translated to last_value(expr) in SQL.

Link copied to clipboard
fun <T : Any> lead(expr: ColumnDeclaring<T>, offset: Int = 1, defVal: T? = null): WindowFunctionExpression<T>
fun <T : Any> lead(expr: ColumnDeclaring<T>, offset: Int, defVal: ColumnDeclaring<T>): WindowFunctionExpression<T>

The lead window function, translated to lead(expr, offset[, defVal]) in SQL.

Link copied to clipboard

Perform a left join and return a new QuerySource, translated to left join in SQL.

Link copied to clipboard

Less operator, translated to < in SQL.

Link copied to clipboard

Less-eq operator, translated to <= in SQL.

Link copied to clipboard

Like operator, translated to the like keyword in SQL.

Link copied to clipboard
fun Query.limit(n: Int): Query

Specify the pagination limit parameter of this query.

fun Query.limit(offset: Int?, limit: Int?): Query

Specify the pagination parameters of this query.

Link copied to clipboard

Less operator, translated to < in SQL.

Link copied to clipboard

Less-eq operator, translated to <= in SQL.

Link copied to clipboard
inline fun <R> Query.map(transform: (row: QueryRowSet) -> R): List<R>

Return a list containing the results of applying the given transform function to each row of the query.

Link copied to clipboard
inline fun <R> Query.mapIndexed(transform: (index: Int, row: QueryRowSet) -> R): List<R>

Return a list containing the results of applying the given transform function to each row and its index.

Link copied to clipboard
inline fun <R : Any> Query.mapIndexedNotNull(transform: (index: Int, row: QueryRowSet) -> R?): List<R>

Return a list containing only the non-null results of applying the given transform function to each row and its index.

Link copied to clipboard
inline fun <R : Any, C : MutableCollection<in R>> Query.mapIndexedNotNullTo(destination: C, transform: (index: Int, row: QueryRowSet) -> R?): C

Apply the given transform function to each row and its index and append only the non-null results to the given destination.

Link copied to clipboard
inline fun <R, C : MutableCollection<in R>> Query.mapIndexedTo(destination: C, transform: (index: Int, row: QueryRowSet) -> R): C

Apply the given transform function to each row and its index and append the results to the given destination.

Link copied to clipboard
inline fun <R : Any> Query.mapNotNull(transform: (row: QueryRowSet) -> R?): List<R>

Return a list containing only the non-null results of applying the given transform function to each row of the query.

Link copied to clipboard
inline fun <R : Any, C : MutableCollection<in R>> Query.mapNotNullTo(destination: C, transform: (row: QueryRowSet) -> R?): C

Apply the given transform function to each row of the query and append only the non-null results to the given destination.

Link copied to clipboard
inline fun <R, C : MutableCollection<in R>> Query.mapTo(destination: C, transform: (row: QueryRowSet) -> R): C

Apply the given transform function to each row of the query and append the results to the given destination.

Link copied to clipboard

The max function, translated to max(column) in SQL.

Link copied to clipboard

The max function with distinct, translated to max(distinct column) in SQL.

Link copied to clipboard

The min function, translated to min(column) in SQL.

Link copied to clipboard

The min function with distinct, translated to min(distinct column) in SQL.

Link copied to clipboard
infix operator fun <T : Number> T.minus(expr: ColumnDeclaring<T>): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.minus(value: T): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.minus(expr: ColumnDeclaring<T>): BinaryExpression<T>

Minus operator, translated to - in SQL.

Link copied to clipboard
infix fun <T : Any> ColumnDeclaring<T>.neq(value: T): BinaryExpression<Boolean>

Not-equal operator, translated to <> in SQL.

Link copied to clipboard

Negative operator, translated to the not keyword in SQL.

Link copied to clipboard

Not-between operator, translated to not between .. and .. in SQL.

Link copied to clipboard

Not-equal operator, translated to <> in SQL.

Link copied to clipboard

Check if the given query doesn't have any results, translated to the not exists keyword in SQL.

Link copied to clipboard

Not-in-list operator, translated to the not in keyword in SQL.

Link copied to clipboard

Not like operator, translated to the not like keyword in SQL.

Link copied to clipboard

The nth_value window function, translated to nth_value(expr, n) in SQL.

Link copied to clipboard

The ntile window function, translated to ntile(n) in SQL.

Link copied to clipboard

Specify the pagination offset parameter of this query.

Link copied to clipboard

Or operator, translated to the or keyword in SQL.

Link copied to clipboard
fun Query.orderBy(vararg orders: OrderByExpression): Query

Specify the order by clause of this query using the given order-by expressions.

Specify the order-by clause of this window using the given order-by expressions.

Link copied to clipboard

Use this aggregate function as a window function and specify its window specification.

Specify the window specification for this window function.

Link copied to clipboard

Specify the partition-by clause of this window using the given columns or expressions.

Link copied to clipboard

The percent_rank window function, translated to percent_rank() in SQL.

Link copied to clipboard
infix operator fun <T : Number> T.plus(expr: ColumnDeclaring<T>): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.plus(value: T): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.plus(expr: ColumnDeclaring<T>): BinaryExpression<T>

Plus operator, translated to + in SQL.

Link copied to clipboard

Specify the frame clause of this window using the given bound in range unit.

Link copied to clipboard

Specify the frame clause of this window using the given bounds (start & end) in rows unit.

Link copied to clipboard

The rank window function, translated to rank() in SQL.

Link copied to clipboard
infix operator fun <T : Number> T.rem(expr: ColumnDeclaring<T>): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.rem(value: T): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.rem(expr: ColumnDeclaring<T>): BinaryExpression<T>

Mod operator, translated to % in SQL.

Link copied to clipboard

Perform a right join and return a new QuerySource, translated to right join in SQL.

Link copied to clipboard

The row_number window function, translated to row_number() in SQL.

Link copied to clipboard

Specify the frame clause of this window using the given bound in rows unit.

Link copied to clipboard

Specify the frame clause of this window using the given bounds (start & end) in rows unit.

Link copied to clipboard
fun QuerySource.select(vararg columns: ColumnDeclaring<*>): Query

Create a query object, selecting the specific columns or expressions from this QuerySource.

Link copied to clipboard

Create a query object, selecting the specific columns or expressions from this QuerySource distinctly.

Link copied to clipboard

The sum function, translated to sum(column) in SQL.

Link copied to clipboard

The sum function with distinct, translated to sum(distinct column) in SQL.

Link copied to clipboard
fun <T : Any, R : Any> WhenContinuation<T, R>.THEN(result: ColumnDeclaring<R>): CaseWhen<T, R>
@JvmName(name = "firstTHEN")
fun <T : Any, R : Any> WhenContinuation<T, Nothing>.THEN(result: ColumnDeclaring<R>): CaseWhen<T, R>
inline fun <T : Any, R : Any> WhenContinuation<T, R>.THEN(result: R, sqlType: SqlType<R> = SqlType.of() ?: error("Cannot detect the argument's SqlType, please specify manually.")): CaseWhen<T, R>
@JvmName(name = "firstTHEN")
inline fun <T : Any, R : Any> WhenContinuation<T, Nothing>.THEN(result: R, sqlType: SqlType<R> = SqlType.of() ?: error("Cannot detect the argument's SqlType, please specify manually.")): CaseWhen<T, R>

Finishes the current when clause with the given result.

Link copied to clipboard
infix operator fun <T : Number> T.times(expr: ColumnDeclaring<T>): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.times(value: T): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.times(expr: ColumnDeclaring<T>): BinaryExpression<T>

Multiply operator, translated to * in SQL.

Link copied to clipboard

Cast the current column or expression's type to Double.

Link copied to clipboard

Cast the current column or expression's type to Float.

Link copied to clipboard
@JvmName(name = "booleanToInt")
fun ColumnDeclaring<Boolean>.toInt(): CastingExpression<Int>

Cast the current column or expression's type to Int.

Link copied to clipboard

Cast the current column or expression's type to Long.

Link copied to clipboard

Cast the current column or expression's type to Short.

Link copied to clipboard

Unary minus operator, translated to - in SQL.

Link copied to clipboard

Unary plus operator, translated to + in SQL.

Link copied to clipboard
fun Query.union(right: Query): Query

Union this query with the given one, corresponding to the union keyword in SQL.

Link copied to clipboard
fun Query.unionAll(right: Query): Query

Union this query with the given one, corresponding to the union all keyword in SQL.

Link copied to clipboard
fun <T : BaseTable<*>> Database.update(table: T, block: UpdateStatementBuilder.(T) -> Unit): Int

Construct an update expression in the given closure, then execute it and return the effected row count.

Link copied to clipboard
fun <T : Any, R : Any> CaseWhen<T, R>.WHEN(condition: ColumnDeclaring<T>): WhenContinuation<T, R>
inline fun <T : Any, R : Any> CaseWhen<T, R>.WHEN(condition: T, sqlType: SqlType<T> = SqlType.of() ?: error("Cannot detect the argument's SqlType, please specify manually.")): WhenContinuation<T, R>

Starts a when clause with the given condition.

Link copied to clipboard
inline fun Query.where(condition: () -> ColumnDeclaring<Boolean>): Query

Specify the where clause of this query using the expression returned by the given callback function.

Specify the where clause of this query using the given condition expression.

Link copied to clipboard

Create a mutable list, then add filter conditions to the list in the given callback function, finally combine them with the and operator and set the combined condition as the where clause of this query.

Link copied to clipboard

Create a mutable list, then add filter conditions to the list in the given callback function, finally combine them with the or operator and set the combined condition as the where clause of this query.

Link copied to clipboard

Create a default window specification.

Link copied to clipboard

Return a lazy Iterable that wraps each row of the query into an IndexedValue containing the index of that row and the row itself.

Link copied to clipboard

Xor operator, translated to the xor keyword in SQL.