update method
Future<List<T> >
update(
- Session session,
- List<
T> rows, { - ColumnSelections<
Table> ? columns, - Transaction? transaction,
Updates all Ts in the list and returns the updated rows. If
columns is provided, only those columns will be updated. Defaults to
all columns.
This is an atomic operation, meaning that if one of the rows fails to
update, none of the rows will be updated.
Implementation
Future<List<T>> update(
_i1.Session session,
List<T> rows, {
_i1.ColumnSelections<_i1.Table>? columns,
_i1.Transaction? transaction,
}) async {
final tableName = _table.tableName;
final resultData = await supabase
.from(tableName)
.upsert((rows.map((e) => e.toJson()).toList()))
.select();
List<T> results = [];
for (int i = 0; i < resultData.length; i++) {
var dbRowMap = resultData[i];
var originalRowMap = rows[i].toJson();
var mergedMap = {...originalRowMap, ...dbRowMap};
results.add(
session.serverpod.serializationManager.deserialize<T>(mergedMap),
);
}
return results;
}