mirror of https://github.com/AMT-Cheif/drift.git
website: Update documentation on batches (#318)
This commit is contained in:
parent
49d251f819
commit
681ed5fbd1
|
@ -144,5 +144,24 @@ If a column is nullable or has a default value (this includes auto-increments),
|
||||||
can be omitted. All other fields must be set and non-null. The `insert` method will throw
|
can be omitted. All other fields must be set and non-null. The `insert` method will throw
|
||||||
otherwise.
|
otherwise.
|
||||||
|
|
||||||
Multiple inserts can be batched by using `insertAll` - it takes a list of companions instead
|
Multiple insert statements can be run efficiently by using a batch. To do that, you can
|
||||||
of a single companion.
|
use the `insertAll` method inside a `batch`:
|
||||||
|
```dart
|
||||||
|
Future<void> insertMultipleEntries() async{
|
||||||
|
await batch((batch) {
|
||||||
|
// functions in a batch don't have to be awaited - just
|
||||||
|
// await the whole batch afterwards.
|
||||||
|
batch.insertAll([
|
||||||
|
TodosCompanion.insert(
|
||||||
|
title: 'First entry',
|
||||||
|
content: 'My content',
|
||||||
|
),
|
||||||
|
TodosCompanion.insert(
|
||||||
|
title: 'Another entry',
|
||||||
|
content: 'More content',
|
||||||
|
),
|
||||||
|
// ...
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
Loading…
Reference in New Issue