on Conflict
Specifies the ON CONFLICT resolution algorithm for a UNIQUE, PRIMARY KEY, or NOT NULL constraint.
This function defines how SQLite should handle a constraint violation when it occurs. For example, if a UNIQUE constraint is violated during an INSERT or UPDATE, the ON CONFLICT clause determines the action to be taken, such as rolling back the transaction, ignoring the new row, or replacing the existing row.
This applies to UNIQUE, PRIMARY KEY, and NOT NULL constraints defined on this single column. For table-level constraints, the ON CONFLICT clause is specified within the constraints block.
Example:
object Users : KQLiteTable("users") {
val id = longColumn("id").primaryKey()
// If an attempt is made to insert a user with an existing username,
// the new record will replace the old one.
val username = stringColumn("username")
.unique()
.onConflict(Action.REPLACE)
// If a null value is inserted into 'email', the operation will be aborted.
val email = stringColumn("email")
.notNull()
.onConflict(Action.ABORT)
}Return
The same KQLiteColumn instance, now with a conflict resolution clause, to allow for further chaining.
Author
MOHAMMAD AZIM ANSARI
Parameters
The conflict resolution strategy to apply (e.g., ROLLBACK, ABORT, FAIL, IGNORE, REPLACE).