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';
|
part of '../query_builder.dart';
|
||||||
|
|
||||||
/// Represents an insert statements
|
/// Represents an insert statement
|
||||||
class InsertStatement<T extends Table, D extends DataClass> {
|
class InsertStatement<T extends Table, D extends DataClass> {
|
||||||
/// The database to use then executing this statement
|
/// The database to use then executing this statement
|
||||||
@protected
|
@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
|
/// 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
|
/// return value, but the future will complete with an error if the insert
|
||||||
/// fails.
|
/// fails.
|
||||||
|
|
||||||
Future<int> insert(
|
Future<int> insert(
|
||||||
Insertable<D> entity, {
|
Insertable<D> entity, {
|
||||||
InsertMode mode,
|
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
|
/// Be aware that [insertOnConflictUpdate] uses an upsert clause, which is not
|
||||||
/// available on older sqlite implementations.
|
/// available on older sqlite implementations.
|
||||||
Future<void> insertOnConflictUpdate(Insertable<D> entity) {
|
Future<int> insertOnConflictUpdate(Insertable<D> entity) {
|
||||||
return insert(entity, onConflict: DoUpdate((_) => entity));
|
return insert(entity, onConflict: DoUpdate((_) => entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,9 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('insertOnConflictUpdate', () async {
|
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)));
|
TodosTableCompanion.insert(content: 'content', id: const Value(3)));
|
||||||
|
|
||||||
verify(executor.runInsert(
|
verify(executor.runInsert(
|
||||||
|
@ -214,5 +216,6 @@ void main() {
|
||||||
'ON CONFLICT(id) DO UPDATE SET id = ?, content = ?',
|
'ON CONFLICT(id) DO UPDATE SET id = ?, content = ?',
|
||||||
[3, 'content', 3, 'content'],
|
[3, 'content', 3, 'content'],
|
||||||
));
|
));
|
||||||
|
expect(id, 3);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue