check

protected fun <T> KQLiteColumn<T>.check(clause: Clause.(KQLiteColumn<T>) -> Unit): KQLiteColumn<T>

Adds a CHECK constraint to this column.

This constraint ensures that all values stored in this column satisfy a specific condition. The condition is defined by a boolean expression within the provided lambda. If an INSERT or UPDATE operation attempts to store a value that violates the constraint, the operation will fail.

The lambda receives the column itself as a parameter, allowing you to build the constraint expression using KQLite DSL operators (e.g., GT, LT, LIKE, IN).

Example:

object Products : KQLiteTable("products") {
val id = longColumn("id").primaryKey()

// Ensures the 'price' is always greater than zero.
val price = doubleColumn("price").notNull().check { it GT 0.0 }

// Ensures the 'product_code' follows a specific format.
val productCode = stringColumn("product_code").notNull().check { it LIKE "PROD-%" }
}

To define a CHECK constraint that involves multiple columns, use the check function within the table-level constraints block.

Return

The same KQLiteColumn instance, now with a CHECK constraint, to allow for further chaining.

Author

MOHAMMAD AZIM ANSARI

Parameters

clause

A lambda expression that defines the boolean condition for the check constraint. The expression is built within a Clause context.