Make insertOnConflictUpdate return a Future<int>

This commit is contained in:
Simon Binder 2020-04-24 22:34:09 +02:00
parent 821d1620cd
commit 721d25ff3c
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 6 additions and 4 deletions

View File

@ -1,6 +1,6 @@
part of '../query_builder.dart';
/// Represents an insert statements
/// Represents an insert statement
class InsertStatement<T extends Table, D extends DataClass> {
/// The database to use then executing this statement
@protected
@ -55,7 +55,6 @@ class InsertStatement<T extends Table, D extends DataClass> {
/// be returned. If there is no auto-increment column, you can't rely on the
/// return value, but the future will complete with an error if the insert
/// fails.
Future<int> insert(
Insertable<D> entity, {
InsertMode mode,
@ -83,7 +82,7 @@ class InsertStatement<T extends Table, D extends DataClass> {
///
/// Be aware that [insertOnConflictUpdate] uses an upsert clause, which is not
/// available on older sqlite implementations.
Future<void> insertOnConflictUpdate(Insertable<D> entity) {
Future<int> insertOnConflictUpdate(Insertable<D> entity) {
return insert(entity, onConflict: DoUpdate((_) => entity));
}

View File

@ -206,7 +206,9 @@ void main() {
});
test('insertOnConflictUpdate', () async {
await db.into(db.todosTable).insertOnConflictUpdate(
when(executor.runInsert(any, any)).thenAnswer((_) => Future.value(3));
final id = await db.into(db.todosTable).insertOnConflictUpdate(
TodosTableCompanion.insert(content: 'content', id: const Value(3)));
verify(executor.runInsert(
@ -214,5 +216,6 @@ void main() {
'ON CONFLICT(id) DO UPDATE SET id = ?, content = ?',
[3, 'content', 3, 'content'],
));
expect(id, 3);
});
}