constraints
Defines table-level constraints using a DSL.
This property allows you to specify constraints that apply to the table as a whole, such as composite primary keys, unique constraints across multiple columns, foreign keys, and check constraints. Multiple constraints can be created here.
Example:
object Users : KQLiteTable("users") {
val id = longColumn("id").primaryKey().autoIncrement()
val firstName = stringColumn("first_name")
val lastName = stringColumn("last_name")
// Defines a composite unique constraint on 'firstName' and 'lastName'
override val constraints: (ConstraintBuilder.() -> Unit) = {
unique(firstName, lastName)
check { LENGTH(firstName) GT 0 }
}
}Content copied to clipboard
Author
MOHAMMAD AZIM ANSARI