insertOnConflictUpdate method

Future<int> insertOnConflictUpdate(
  1. Insertable<Row> entity
)

Attempts to insert entity into the database. If the insert would violate a primary key or uniqueness constraint, updates the columns that are present on entity.

Be aware that insertOnConflictUpdate uses an upsert clause, which is not available on older sqlite implementations. Note: By default, only the primary key is used for detect uniqueness violations. If you have further uniqueness constraints, please use the general insert method with a DoUpdate including those columns in its DoUpdate.target.

Like the other insert methods, this returns the rowid of the last insert. When the insert was turned into an update due to a conflicting row, this behavior is somewhat confusing because the id of an (likely unrelated) insert is returned instead. Use insertReturning with an onConflict clause of DoUpdate((_) => entity) to reliably get the written entity instead.

Implementation

Future<int> insertOnConflictUpdate(Insertable<Row> entity) {
  return insert(entity, onConflict: DoUpdate((_) => entity));
}