writeReturning method

Future<List<D>> writeReturning(
  1. Insertable<D> entity
)

Applies the updates from entity to all rows matching the applied where clause and returns affected rows after the update.

For more details on writing entries, see write. Note that this requires sqlite 3.35 or later.

Implementation

Future<List<D>> writeReturning(Insertable<D> entity) async {
  writeReturningClause = true;
  await write(entity, dontExecute: true);

  final ctx = constructQuery();
  final rows = await database.withCurrentExecutor((e) {
    return e.runSelect(ctx.sql, ctx.boundVariables);
  });

  if (rows.isNotEmpty) {
    database.notifyUpdates(
        {TableUpdate.onTable(_sourceTable, kind: UpdateKind.update)});
  }

  return rows.mapAsyncAndAwait(table.map);
}