check
Defines a CHECK constraint on the KQLiteTable column.
A CHECK constraint specifies a condition that each row in the table must satisfy. The condition is expressed as a boolean expression within the provided Clause.
This function is used within the KQLiteTable.constraints block definition.
Example
object Products : KQLiteTable("products") {
val productId = longColumn("ProductId").primaryKey()
val name = textColumn("Name").notNull()
val price = doubleColumn("Price").notNull()
val discount = doubleColumn("Discount").notNull().default(0.0)
override val constraints: (ConstraintBuilder.() -> Unit)? = {
// Ensure the price is always positive
check { price GT 0.0 }
// Ensure the discount is not greater than the price
constraint("chk_discount").check { discount LTE price }
}
}Content copied to clipboard
Return
A Constraint object representing the defined check constraint.
Author
MOHAMMAD AZIM ANSARI
Parameters
clause
A lambda with a Clause receiver where the check condition is defined. The expression inside this lambda will be translated into the SQL CHECK expression.