Primary Key Constraint
interface PrimaryKeyConstraint
Represents a PRIMARY KEY constraint in a com.kqlite.table.KQLiteTable.
This interface provides a way to define the conflict resolution strategy for when a primary key violation occurs (e.g., trying to insert a duplicate key). A primary key cannot contain NULL values.
Example
object MyTable : KQLiteTable("my_table") {
val id = longColumn("id")
val email = textColumn("email").notNull()
override val constraints: (ConstraintBuilder.() -> Unit)? = {
// Define a single-column primary key
primaryKey(id).onConflict(Action.REPLACE)
// Define a composite primary key
primaryKey(id, email)
// Define primary key by name
constraint("primary_key_name").primaryKey(id)
}
}Content copied to clipboard
Author
MOHAMMAD AZIM ANSARI
See also
Functions
Link copied to clipboard
Specifies ON CONFLICT resolution algorithm to be used when a PrimaryKeyConstraint violation occurs.