update method
Updates matching rows in the table
with the given data
.
The where
clause is used to filter which rows are updated.
All keys in where
are prefixed with w_
to avoid naming collisions.
Returns the updated row(s).
Implementation
@override
Future<DbResult> update(
String table,
Map<String, dynamic> data, {
required Map<String, dynamic> where,
}) async {
final sets = data.keys.map((k) => '$k = @$k').join(', ');
final conditions = where.keys.map((k) => '$k = @w_$k').join(' AND ');
final values = {
...data,
...{for (var k in where.keys) 'w_$k': where[k]},
};
final query = 'UPDATE $table SET $sets WHERE $conditions RETURNING *;';
return rawQuery(query, values: values);
}