mirror of https://github.com/AMT-Cheif/drift.git
Fix type argument in `Batch.insert` (#1781)
This commit is contained in:
parent
8e3259c971
commit
221ca2382f
|
@ -48,7 +48,7 @@ class Batch {
|
|||
{InsertMode? mode, UpsertClause<T, D>? onConflict}) {
|
||||
_addUpdate(table, UpdateKind.insert);
|
||||
final actualMode = mode ?? InsertMode.insert;
|
||||
final context = InsertStatement<Table, D>(_user, table)
|
||||
final context = InsertStatement<T, D>(_user, table)
|
||||
.createContext(row, actualMode, onConflict: onConflict);
|
||||
_addContext(context);
|
||||
}
|
||||
|
|
|
@ -121,6 +121,41 @@ void main() {
|
|||
)));
|
||||
});
|
||||
|
||||
test('insert with where clause and excluded table', () async {
|
||||
// https://github.com/simolus3/drift/issues/1781
|
||||
final entries = [
|
||||
CategoriesCompanion.insert(description: 'first'),
|
||||
CategoriesCompanion.insert(description: 'second'),
|
||||
];
|
||||
|
||||
await db.batch((batch) {
|
||||
batch.insertAll<Categories, Category>(
|
||||
db.categories,
|
||||
entries,
|
||||
onConflict: DoUpdate.withExcluded(
|
||||
(old, excluded) => CategoriesCompanion.custom(
|
||||
description: old.description.dartCast(),
|
||||
priority: excluded.priority.dartCast(),
|
||||
),
|
||||
where: (old, excluded) =>
|
||||
old.id.dartCast<int>().isBiggerOrEqual(excluded.id.dartCast()),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
verify(executor.transactions.runBatched(BatchedStatements(
|
||||
[
|
||||
('INSERT INTO categories ("desc") VALUES (?) ON CONFLICT(id) '
|
||||
'DO UPDATE SET "desc" = categories."desc", '
|
||||
'priority = excluded.priority WHERE categories.id >= excluded.id')
|
||||
],
|
||||
[
|
||||
ArgumentsForBatchedStatement(0, ['first']),
|
||||
ArgumentsForBatchedStatement(0, ['second']),
|
||||
],
|
||||
)));
|
||||
});
|
||||
|
||||
test('can re-use an outer transaction', () async {
|
||||
await db.transaction(() async {
|
||||
await db.batch((b) {});
|
||||
|
|
Loading…
Reference in New Issue