insertReturning method
Future<D>
insertReturning(
- Insertable<
D> entity, { - InsertMode? mode,
- UpsertClause<
T, D> ? onConflict,
Inserts a row into the table and returns it.
Depending on the InsertMode or the DoUpdate onConflict
clause, the
insert statement may not actually insert a row into the database. Since
this function was declared to return a non-nullable row, it throws an
exception in that case. Use insertReturningOrNull when performing an
insert with an insert mode like InsertMode.insertOrIgnore or when using
a DoUpdate with a where
clause clause.
Implementation
Future<D> insertReturning(Insertable<D> entity,
{InsertMode? mode, UpsertClause<T, D>? onConflict}) async {
final row =
await insertReturningOrNull(entity, mode: mode, onConflict: onConflict);
if (row == null) {
throw StateError('The insert statement did not insert any rows that '
'could be returned. Please use insertReturningOrNull() when using a '
'`DoUpdate` clause with `where`.');
}
return row;
}