English | 简体中文

api-docs / me.liuwj.ktorm.dsl

Package me.liuwj.ktorm.dsl

Constructs strong-typed SQL DSL.

Types

NameSummary

AssignmentsBuilder

open class AssignmentsBuilder

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

BatchInsertStatementBuilder

class BatchInsertStatementBuilder<T : BaseTable<>>

DSL builder for batch insert statements.

BatchUpdateStatementBuilder

class BatchUpdateStatementBuilder<T : BaseTable<>>

DSL builder for batch update statements.

Query

data class Query : Iterable<QueryRowSet>

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

QueryRowSet

class QueryRowSet : ResultSet

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

UpdateStatementBuilder

class UpdateStatementBuilder : AssignmentsBuilder

DSL builder for update statements.

Annotations

NameSummary

KtormDsl

annotation class KtormDsl

Marker annotation for Ktorm DSL builder classes.

Extensions for External Classes

NameSummary

kotlin.Boolean

kotlin.collections.Iterable

Functions

NameSummary

all

fun <E : Any, T : BaseTable<E>> T.all(
    predicate: (T) -> ColumnDeclaring<Boolean>
): Boolean

Check if all the records in the table matches the given predicate.

and


infix fun ColumnDeclaring<Boolean>.and(
    argument: Boolean
): BinaryExpression<Boolean>

And operator, translated to the and keyword in SQL.

any

fun <E : Any, T : BaseTable<E>> T.any(): Boolean

Check if there is any record in the table.

fun <E : Any, T : BaseTable<E>> T.any(
    predicate: (T) -> ColumnDeclaring<Boolean>
): Boolean

Check if there is any record in the table matches the given predicate.

asc

Order this column or expression in ascending order.

averageBy

fun <E : Any, T : BaseTable<E>> T.averageBy(
    selector: (T) -> ColumnDeclaring<out Number>
): Double?

Return the average value of the given column or expression of all the records, null if there are no records.

avg

fun <C : Number> avg(
    column: ColumnDeclaring<C>
): AggregateExpression<Double>

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

avgDistinct

fun <C : Number> avgDistinct(
    column: ColumnDeclaring<C>
): AggregateExpression<Double>

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

batchInsert

fun <T : BaseTable<>> T.batchInsert(
    block: BatchInsertStatementBuilder<T>.() -> Unit
): IntArray

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

batchUpdate

fun <T : BaseTable<>> T.batchUpdate(
    block: BatchUpdateStatementBuilder<T>.() -> Unit
): IntArray

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

between

infix fun <T : Comparable<T>> ColumnDeclaring<T>.between(
    range: ClosedRange<T>
): BetweenExpression<T>

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

cast

fun <T : Any> ColumnDeclaring<>.cast(
    sqlType: SqlType<T>
): CastingExpression<T>

Cast the current column or expression to the given SqlType.

count

fun count(
    column: ColumnDeclaring<>? = null
): AggregateExpression<Int>

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

fun <E : Any, T : BaseTable<E>> T.count(): Int

Return the records count in the table.

fun <E : Any, T : BaseTable<E>> T.count(
    predicate: (T) -> ColumnDeclaring<Boolean>
): Int

Return the records count in the table that matches the given predicate.

countDistinct

fun countDistinct(
    column: ColumnDeclaring<>? = null
): AggregateExpression<Int>

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

crossJoin

fun QuerySourceExpression.crossJoin(
    right: QuerySourceExpression,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

fun QuerySourceExpression.crossJoin(
    right: BaseTable<>,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

fun BaseTable<>.crossJoin(
    right: QuerySourceExpression,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

fun BaseTable<>.crossJoin(
    right: BaseTable<>,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

Join the right table and return a JoinExpression, translated to cross join in SQL.

delete

fun <T : BaseTable<>> T.delete(
    predicate: (T) -> ColumnDeclaring<Boolean>
): Int

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

deleteAll

fun BaseTable<>.deleteAll(): Int

Delete all the records in the table.

desc

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

div

infix operator fun <T : Number> ColumnDeclaring<T>.div(
    expr: ColumnDeclaring<T>
): BinaryExpression<T>

infix operator fun <T : Number> ColumnDeclaring<T>.div(
    argument: T
): BinaryExpression<T>

infix operator fun <T : Number> T.div(
    expr: ColumnDeclaring<T>
): BinaryExpression<T>

Divide operator, translated to / in SQL.

eq

infix fun <T : Any> ColumnDeclaring<T>.eq(
    expr: ColumnDeclaring<T>
): BinaryExpression<Boolean>

infix fun <T : Any> ColumnDeclaring<T>.eq(
    argument: T
): BinaryExpression<Boolean>

Equal operator, translated to = in SQL.

exists

fun exists(query: Query): ExistsExpression

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

greater

infix fun <T : Comparable<T>> ColumnDeclaring<T>.greater(
    expr: ColumnDeclaring<T>
): BinaryExpression<Boolean>

infix fun <T : Comparable<T>> ColumnDeclaring<T>.greater(
    argument: T
): BinaryExpression<Boolean>

infix fun <T : Comparable<T>> T.greater(
    expr: ColumnDeclaring<T>
): BinaryExpression<Boolean>

Greater operator, translated to > in SQL.

greaterEq

infix fun <T : Comparable<T>> ColumnDeclaring<T>.greaterEq(
    expr: ColumnDeclaring<T>
): BinaryExpression<Boolean>

infix fun <T : Comparable<T>> ColumnDeclaring<T>.greaterEq(
    argument: T
): BinaryExpression<Boolean>

infix fun <T : Comparable<T>> T.greaterEq(
    expr: ColumnDeclaring<T>
): BinaryExpression<Boolean>

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

groupBy

fun Query.groupBy(vararg columns: ColumnDeclaring<>): Query

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

having

fun Query.having(
    block: () -> ColumnDeclaring<Boolean>
): Query

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

inList

infix fun <T : Any> ColumnDeclaring<T>.inList(
    collection: Collection<T>
): InListExpression<T>

infix fun <T : Any> ColumnDeclaring<T>.inList(
    query: Query
): InListExpression<T>

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

innerJoin

fun QuerySourceExpression.innerJoin(
    right: QuerySourceExpression,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

fun QuerySourceExpression.innerJoin(
    right: BaseTable<>,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

fun BaseTable<>.innerJoin(
    right: QuerySourceExpression,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

fun BaseTable<>.innerJoin(
    right: BaseTable<>,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

Join the right table and return a JoinExpression, translated to inner join in SQL.

insert

fun <T : BaseTable<>> T.insert(
    block: AssignmentsBuilder.(T) -> Unit
): Int

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

insertAndGenerateKey

fun <T : BaseTable<>> T.insertAndGenerateKey(
    block: AssignmentsBuilder.(T) -> Unit
): Any

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

insertTo

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.

isNotNull

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

isNull

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

iterable

fun <T : ResultSet> T.iterable(): Iterable<T>

Wrap this ResultSet as Iterable.

iterator

operator fun <T : ResultSet> T.iterator(): Iterator<T>

Return an iterator over the rows of this ResultSet.

leftJoin

fun QuerySourceExpression.leftJoin(
    right: QuerySourceExpression,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

fun QuerySourceExpression.leftJoin(
    right: BaseTable<>,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

fun BaseTable<>.leftJoin(
    right: QuerySourceExpression,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

fun BaseTable<>.leftJoin(
    right: BaseTable<>,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

Join the right table and return a JoinExpression, translated to left join in SQL.

less

infix fun <T : Comparable<T>> ColumnDeclaring<T>.less(
    expr: ColumnDeclaring<T>
): BinaryExpression<Boolean>

infix fun <T : Comparable<T>> ColumnDeclaring<T>.less(
    argument: T
): BinaryExpression<Boolean>

infix fun <T : Comparable<T>> T.less(
    expr: ColumnDeclaring<T>
): BinaryExpression<Boolean>

Less operator, translated to < in SQL.

lessEq

infix fun <T : Comparable<T>> ColumnDeclaring<T>.lessEq(
    expr: ColumnDeclaring<T>
): BinaryExpression<Boolean>

infix fun <T : Comparable<T>> ColumnDeclaring<T>.lessEq(
    argument: T
): BinaryExpression<Boolean>

infix fun <T : Comparable<T>> T.lessEq(
    expr: ColumnDeclaring<T>
): BinaryExpression<Boolean>

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

like

infix fun ColumnDeclaring<>.like(
    expr: ColumnDeclaring<String>
): BinaryExpression<Boolean>

infix fun ColumnDeclaring<>.like(
    argument: String
): BinaryExpression<Boolean>

Like operator, translated to the like keyword in SQL.

limit

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

Specify the pagination parameters of this query.

max

fun <C : Comparable<C>> max(
    column: ColumnDeclaring<C>
): AggregateExpression<C>

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

maxBy

fun <E : Any, T : BaseTable<E>, C : Comparable<C>> T.maxBy(
    selector: (T) -> ColumnDeclaring<C>
): C?

Return the max value of the given column or expression of all the records, null if there are no records in the table.

maxDistinct

fun <C : Comparable<C>> maxDistinct(
    column: ColumnDeclaring<C>
): AggregateExpression<C>

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

min

fun <C : Comparable<C>> min(
    column: ColumnDeclaring<C>
): AggregateExpression<C>

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

minBy

fun <E : Any, T : BaseTable<E>, C : Comparable<C>> T.minBy(
    selector: (T) -> ColumnDeclaring<C>
): C?

Return the min value of the given column or expression of all the records, null if there are no records in the table.

minDistinct

fun <C : Comparable<C>> minDistinct(
    column: ColumnDeclaring<C>
): AggregateExpression<C>

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

minus

infix operator fun <T : Number> ColumnDeclaring<T>.minus(
    expr: ColumnDeclaring<T>
): BinaryExpression<T>

infix operator fun <T : Number> ColumnDeclaring<T>.minus(
    argument: T
): BinaryExpression<T>

infix operator fun <T : Number> T.minus(
    expr: ColumnDeclaring<T>
): BinaryExpression<T>

Minus operator, translated to - in SQL.

none

fun <E : Any, T : BaseTable<E>> T.none(): Boolean

Return true if there is no records in the table.

fun <E : Any, T : BaseTable<E>> T.none(
    predicate: (T) -> ColumnDeclaring<Boolean>
): Boolean

Return true if there is no records in the table that matches the given predicate.

not

Negative operator, translated to the not keyword in SQL.

notBetween

infix fun <T : Comparable<T>> ColumnDeclaring<T>.notBetween(
    range: ClosedRange<T>
): BetweenExpression<T>

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

notEq

infix fun <T : Any> ColumnDeclaring<T>.notEq(
    expr: ColumnDeclaring<T>
): BinaryExpression<Boolean>

infix fun <T : Any> ColumnDeclaring<T>.notEq(
    argument: T
): BinaryExpression<Boolean>

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

notExists

fun notExists(query: Query): ExistsExpression

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

notInList

infix fun <T : Any> ColumnDeclaring<T>.notInList(
    collection: Collection<T>
): InListExpression<T>

infix fun <T : Any> ColumnDeclaring<T>.notInList(
    query: Query
): InListExpression<T>

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

notLike

infix fun ColumnDeclaring<>.notLike(
    expr: ColumnDeclaring<String>
): BinaryExpression<Boolean>

infix fun ColumnDeclaring<>.notLike(
    argument: String
): BinaryExpression<Boolean>

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

or


infix fun ColumnDeclaring<Boolean>.or(
    argument: Boolean
): BinaryExpression<Boolean>

Or operator, translated to the or keyword in SQL.

orderBy

fun Query.orderBy(vararg orders: OrderByExpression): Query

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

plus

infix operator fun <T : Number> ColumnDeclaring<T>.plus(
    expr: ColumnDeclaring<T>
): BinaryExpression<T>

infix operator fun <T : Number> ColumnDeclaring<T>.plus(
    argument: T
): BinaryExpression<T>

infix operator fun <T : Number> T.plus(
    expr: ColumnDeclaring<T>
): BinaryExpression<T>

Plus operator, translated to + in SQL.

rem

infix operator fun <T : Number> ColumnDeclaring<T>.rem(
    expr: ColumnDeclaring<T>
): BinaryExpression<T>

infix operator fun <T : Number> ColumnDeclaring<T>.rem(
    argument: T
): BinaryExpression<T>

infix operator fun <T : Number> T.rem(
    expr: ColumnDeclaring<T>
): BinaryExpression<T>

Mod operator, translated to % in SQL.

rightJoin

fun QuerySourceExpression.rightJoin(
    right: QuerySourceExpression,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

fun QuerySourceExpression.rightJoin(
    right: BaseTable<>,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

fun BaseTable<>.rightJoin(
    right: QuerySourceExpression,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

fun BaseTable<>.rightJoin(
    right: BaseTable<>,
    on: ColumnDeclaring<Boolean>? = null
): JoinExpression

Join the right table and return a JoinExpression, translated to right join in SQL.

select

fun QuerySourceExpression.select(
    columns: Collection<ColumnDeclaring<>>
): Query

fun QuerySourceExpression.select(
    vararg columns: ColumnDeclaring<>
): Query

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

fun BaseTable<>.select(
    columns: Collection<ColumnDeclaring<>>
): Query

fun BaseTable<>.select(
    vararg columns: ColumnDeclaring<>
): Query

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

selectDistinct

fun QuerySourceExpression.selectDistinct(
    columns: Collection<ColumnDeclaring<>>
): Query

fun QuerySourceExpression.selectDistinct(
    vararg columns: ColumnDeclaring<>
): Query

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

fun BaseTable<>.selectDistinct(
    columns: Collection<ColumnDeclaring<>>
): Query

fun BaseTable<>.selectDistinct(
    vararg columns: ColumnDeclaring<>
): Query

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

sum

fun <C : Number> sum(
    column: ColumnDeclaring<C>
): AggregateExpression<C>

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

sumBy

fun <E : Any, T : BaseTable<E>, C : Number> T.sumBy(
    selector: (T) -> ColumnDeclaring<C>
): C?

Return the sum of the given column or expression of all the records, null if there are no records in the table.

sumDistinct

fun <C : Number> sumDistinct(
    column: ColumnDeclaring<C>
): AggregateExpression<C>

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

times

infix operator fun <T : Number> ColumnDeclaring<T>.times(
    expr: ColumnDeclaring<T>
): BinaryExpression<T>

infix operator fun <T : Number> ColumnDeclaring<T>.times(
    argument: T
): BinaryExpression<T>

infix operator fun <T : Number> T.times(
    expr: ColumnDeclaring<T>
): BinaryExpression<T>

Multiply operator, translated to in SQL.

toDouble

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

toFloat

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

toInt

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

toLong

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

unaryMinus

operator fun <T : Number> ColumnDeclaring<T>.unaryMinus(): UnaryExpression<T>

Unary minus operator, translated to - in SQL.

unaryPlus

operator fun <T : Number> ColumnDeclaring<T>.unaryPlus(): UnaryExpression<T>

Unary plus operator, translated to + in SQL.

union

fun Query.union(right: Query): Query

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

unionAll

fun Query.unionAll(right: Query): Query

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

update

fun <T : BaseTable<>> T.update(
    block: UpdateStatementBuilder.(T) -> Unit
): Int

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

where

fun Query.where(block: () -> ColumnDeclaring<Boolean>): Query

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

whereWithConditions

fun Query.whereWithConditions(
    block: (MutableList<ColumnDeclaring<Boolean>>) -> Unit
): Query

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.

whereWithOrConditions

fun Query.whereWithOrConditions(
    block: (MutableList<ColumnDeclaring<Boolean>>) -> Unit
): Query

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.

xor


infix fun ColumnDeclaring<Boolean>.xor(
    argument: Boolean
): BinaryExpression<Boolean>

Xor operator, translated to the xor keyword in SQL.