mirror of https://github.com/AMT-Cheif/drift.git
Make insertOnConflictUpdate return a Future<int>
This commit is contained in:
parent
821d1620cd
commit
721d25ff3c
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue