quickInsert

fun <T : KQLiteTable> T.quickInsert(onConflict: Action? = null, connection: SQLiteConnection? = null, binding: Bind.(T) -> Unit)

Executes SQL INSERT and inserts a single row into the table.

This is a convenience function for a simple insert operation. It creates, binds, executes, and closes an InsertStatement in a single call.

Conflict resolution algorithm can also be specified using onConflict action.

All columns in the table that do not have a default value must be bound in the binding lambda.

Example:

// Assume artistId is a primary key
Artists.quickInsert {
it.artistId.bind(1)
it.artistName.bind("SuperCoolMan")
}

// INSERT OR REPLACE ...
Artists.quickInsert(onConflict = Action.REPLACE) {
it.artistId.bind(1)
it.artistName.bind("SuperAwesomeMan")
}

Author

MOHAMMAD AZIM ANSARI

Parameters

onConflict

Optional conflict resolution strategy (e.g., Action.IGNORE, Action.REPLACE). If null, the default database conflict behavior is used.

connection

An optional SQLiteConnection to use for this specific operation. If null, a default connection is used.

binding

A lambda function with a Bind receiver to specify column-to-value mappings for the new row. The lambda also receives the table instance T as a parameter.

Type Parameters

T

The type of the KQLiteTable.

See also

Throws

if the binding is empty, a required column is not bound, or a database error occurs.