batchUpdate

abstract suspend fun batchUpdate(context: QueryExecutor, entities: Iterable<T>): DbResult<Long>(source)

Updates multiple entities in the data source using the specified driver context.

All the entities are written with a single UPDATE statement, each row matched by the entity's id (and version, for a versioned entity). The updated rows are not read back. The operation fails with SQLError.Code.RowMismatch (or SQLError.Code.OptimisticLockFailed for a versioned entity) when the number of affected rows differs from the number of entities. The rows that did match are already updated at that point: run it inside a transaction and roll back on failure for all-or-nothing semantics.

Return

A DbResult containing the number of updated rows (equal to the number of entities), or an error if the operation fails.

Parameters

context

The database driver context used to execute the batch update operation.

entities

The collection of entities of type T to be updated in the data source.