website: Update documentation on batches (#318)

This commit is contained in:
Simon Binder 2020-01-04 20:48:55 +01:00
parent a7300ee9a8
commit 0cdfc9a4ab
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 21 additions and 2 deletions

View File

@ -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
otherwise.
Multiple inserts can be batched by using `insertAll` - it takes a list of companions instead
of a single companion.
Multiple insert statements can be run efficiently by using a batch. To do that, you can
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',
),
// ...
]);
});
}
```