Constraint Builder
interface ConstraintBuilder
Provides a Kotlin DSL for defining table-level constraints within a KQLiteTable definition.
This interface is the receiver for the KQLiteTable.constraints lambda in a table definition, allowing you to declaratively specify constraints like PRIMARY KEY, UNIQUE, CHECK, and FOREIGN KEY.
Following constraints can be created:
Example
object MyTable : KQLiteTable("my_table") {
val id = longColumn("id")
val email = textColumn("email").notNull()
val score = integerColumn("score")
override val constraints: (ConstraintBuilder.() -> Unit)? = {
// Define a named primary key
primaryKey(id)
// Define a unique constraint without name on the email column
unique(email).onConflict(Action.REPLACE)
// Define a check constraint by name that can be deleted later
constraint("score_validation").check { score GTE 0 }
}
}Content copied to clipboard
Author
MOHAMMAD AZIM ANSARI
See also
Functions
Link copied to clipboard
Defines a CHECK constraint on the KQLiteTable column.
Link copied to clipboard
Specifies a name for the Constraint that follows. Represents CONSTRAINT <name>.
Link copied to clipboard
Defines a FOREIGN KEY ForeignKeyConstraint on one or more columns, linking them to another KQLiteTable.
Link copied to clipboard
Defines a PRIMARY KEY PrimaryKeyConstraint constraint on one or more KQLiteTable columns.
Link copied to clipboard
Defines a UNIQUE UniqueConstraint on one or more KQLiteTable columns.