From 721d25ff3c57b9fa91f10f855c887dec710ca327 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 24 Apr 2020 22:34:09 +0200 Subject: [PATCH] Make insertOnConflictUpdate return a Future --- moor/lib/src/runtime/query_builder/statements/insert.dart | 5 ++--- moor/test/insert_test.dart | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/moor/lib/src/runtime/query_builder/statements/insert.dart b/moor/lib/src/runtime/query_builder/statements/insert.dart index 0cb6e87c..275c4c79 100644 --- a/moor/lib/src/runtime/query_builder/statements/insert.dart +++ b/moor/lib/src/runtime/query_builder/statements/insert.dart @@ -1,6 +1,6 @@ part of '../query_builder.dart'; -/// Represents an insert statements +/// Represents an insert statement class InsertStatement { /// The database to use then executing this statement @protected @@ -55,7 +55,6 @@ class InsertStatement { /// 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 insert( Insertable entity, { InsertMode mode, @@ -83,7 +82,7 @@ class InsertStatement { /// /// Be aware that [insertOnConflictUpdate] uses an upsert clause, which is not /// available on older sqlite implementations. - Future insertOnConflictUpdate(Insertable entity) { + Future insertOnConflictUpdate(Insertable entity) { return insert(entity, onConflict: DoUpdate((_) => entity)); } diff --git a/moor/test/insert_test.dart b/moor/test/insert_test.dart index 74c51880..cdcbece0 100644 --- a/moor/test/insert_test.dart +++ b/moor/test/insert_test.dart @@ -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); }); }