replace method
Replaces the old version of entity that is stored in the database with
the fields of the entity provided here. This implicitly applies a
where clause to rows with the same primary key as entity, so that only
the row representing outdated data will be replaced.
If entity has absent values (set to null on the DataClass or
explicitly to absent on the UpdateCompanion), and a default value for
the field exists, that default value will be used. Otherwise, the field
will be reset to null. This behavior is different to write, which simply
ignores such fields without changing them in the database.
When dontExecute is true (defaults to false), the query will NOT be
run, but all the validations are still in place. This is mainly used
internally by drift.
Returns true if a row was affected by this operation.
See also:
- write, which doesn't apply a
wherestatement itself and ignores null values in the entity. InsertStatement.insertwith theorReplaceparameter, which behaves similar to this method but creates a new row if none exists.
Implementation
Future<bool> replace(Insertable<Row> entity) async {
prepareReplace(entity);
final result = await _run();
return result.affectedRows! != 0;
}