insertReturning method
Future<D>
insertReturning(
- Insertable<
D> entity, { - InsertMode? mode,
- UpsertClause<
T, D> ? onConflict,
Inserts a row into the table, and returns a generated instance.
Note: This uses the RETURNING
syntax added in sqlite3 version 3.35,
which is not available on most operating systems by default. When using
this method, make sure that you have a recent sqlite3 version available.
This is the case with sqlite3_flutter_libs
.
Implementation
Future<D> insertReturning(Insertable<D> entity,
{InsertMode? mode, UpsertClause<T, D>? onConflict}) async {
final ctx = createContext(entity, mode ?? InsertMode.insert,
onConflict: onConflict, returning: true);
return database.doWhenOpened((e) async {
final result = await e.runSelect(ctx.sql, ctx.boundVariables);
database
.notifyUpdates({TableUpdate.onTable(table, kind: UpdateKind.insert)});
return table.map(result.single);
});
}