Package-level declarations

Properties

Link copied to clipboard

The global database instance, Ktorm uses this property to obtain a database when any SQL is executed.

Functions

Link copied to clipboard
fun <E : Entity<E>> Table<E>.addEntity(entity: E): Int

Insert the given entity into this sequence and return the affected record number.

Link copied to clipboard
inline 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.

Link copied to clipboard
fun <E : Any, T : BaseTable<E>> T.any(): Boolean

Check if there is any record in the table.

inline 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.

Link copied to clipboard
fun <E : Any, T : BaseTable<E>> T.asSequence(withReferences: Boolean = true): EntitySequence<E, T>

Create an EntitySequence from this table.

Link copied to clipboard
inline 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.

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
fun Database.Companion.connectGlobally(dataSource: DataSource, dialect: SqlDialect = detectDialectImplementation(), logger: Logger = detectLoggerImplementation(), alwaysQuoteIdentifiers: Boolean = false, generateSqlInUpperCase: Boolean? = null): Database

Connect to a database using a DataSource and save the returned database instance to Database.Companion.global.

fun Database.Companion.connectGlobally(dialect: SqlDialect = detectDialectImplementation(), logger: Logger = detectLoggerImplementation(), alwaysQuoteIdentifiers: Boolean = false, generateSqlInUpperCase: Boolean? = null, connector: () -> Connection): Database

Connect to a database by a specific connector function and save the returned database instance to Database.Companion.global.

fun Database.Companion.connectGlobally(url: String, driver: String? = null, user: String? = null, password: String? = null, dialect: SqlDialect = detectDialectImplementation(), logger: Logger = detectLoggerImplementation(), alwaysQuoteIdentifiers: Boolean = false, generateSqlInUpperCase: Boolean? = null): Database

Connect to a database using the specific connection arguments and save the returned database instance to Database.Companion.global.

Link copied to clipboard
fun Database.Companion.connectWithSpringSupportGlobally(dataSource: DataSource, dialect: SqlDialect = detectDialectImplementation(), logger: Logger = detectLoggerImplementation(), alwaysQuoteIdentifiers: Boolean = false, generateSqlInUpperCase: Boolean? = null): Database

Connect to a database using a DataSource with the Spring support enabled and save the returned database instance to Database.Companion.global.

Link copied to clipboard
fun <E : Any, T : BaseTable<E>> T.count(): Int

Return the records count in the table.

inline 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.

Link copied to clipboard

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

Link copied to clipboard
fun <T : BaseTable<*>> T.delete(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
fun <E : Any> BaseTable<E>.findAll(): List<E>

Obtain all the entity objects from this table, auto left joining all the reference tables.

Link copied to clipboard
inline fun <E : Any, T : BaseTable<E>> T.findList(predicate: (T) -> ColumnDeclaring<Boolean>): List<E>

Obtain a list of entity objects matching the given predicate, auto left joining all the reference tables.

Link copied to clipboard
inline fun <E : Any, T : BaseTable<E>> T.findOne(predicate: (T) -> ColumnDeclaring<Boolean>): E?

Obtain an entity object matching the given predicate, auto left joining all the reference tables.

Link copied to clipboard

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

Link copied to clipboard
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.

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
inline operator fun <T> Database.invoke(func: Database.() -> T): T

Execute the callback function using the current database instance.

Link copied to clipboard
fun <E : Any, T : BaseTable<E>> T.isEmpty(): Boolean

Return true if the table has no records.

Link copied to clipboard
fun <E : Any, T : BaseTable<E>> T.isNotEmpty(): Boolean

Return true if the table has at lease one record.

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

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

Link copied to clipboard
inline 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.

Link copied to clipboard
inline 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.

Link copied to clipboard
fun <E : Any, T : BaseTable<E>> T.none(): Boolean

Return true if there is no records in the table.

inline 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.

Link copied to clipboard

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

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

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

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

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

Link copied to clipboard
inline 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.

Link copied to clipboard
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.

Link copied to clipboard
fun <E : Entity<E>> Table<E>.updateEntity(entity: E): Int

Update properties of the given entity to the database and return the affected record number.

Link copied to clipboard
inline fun <T> useConnection(func: (Connection) -> T): T

Obtain a connection from Database.Companion.global and invoke the callback function with it.

Link copied to clipboard
inline fun <T> useTransaction(isolation: TransactionIsolation? = null, func: (Transaction) -> T): T

Execute the specific callback function in a transaction of Database.Companion.global and returns its result if the execution succeeds, otherwise, if the execution fails, the transaction will be rollback.