UniqueConstraint

Represents a UNIQUE constraint in a com.kqlite.table.KQLiteTable.

A UNIQUE constraint ensures that all values in a column or a set of columns are different from one another. This constraint can be applied to one or more columns in a table.

Example

object Employees : KQLiteTable("employees") {
val employeeId = longColumn("EmployeeId")
val lastName = stringColumn("LastName").notNull()
val firstName = stringColumn("FirstName").notNull()
val email = stringColumn("Email")

override val constraints: (ConstraintBuilder.() -> Unit)? = {
// Define a single-column unique key
unique(employeeId).onConflict(Action.REPLACE)

// Define a multi-column unique key
unique(firstName, lastName)

// Define unique key by name
constraint("unique_key_name").unique(email)
}
}

See also

Functions

Link copied to clipboard
abstract fun onConflict(action: Action): Constraint

Specifies ON CONFLICT resolution algorithm to be used when a UniqueConstraint violation occurs.