mirror of https://github.com/AMT-Cheif/drift.git
Mention that batches are using transactions more
This commit is contained in:
parent
a3b56f8c98
commit
2ef2d660fc
|
@ -194,6 +194,7 @@ otherwise.
|
||||||
|
|
||||||
Multiple insert statements can be run efficiently by using a batch. To do that, you can
|
Multiple insert statements can be run efficiently by using a batch. To do that, you can
|
||||||
use the `insertAll` method inside a `batch`:
|
use the `insertAll` method inside a `batch`:
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
Future<void> insertMultipleEntries() async{
|
Future<void> insertMultipleEntries() async{
|
||||||
await batch((batch) {
|
await batch((batch) {
|
||||||
|
@ -216,6 +217,10 @@ Future<void> insertMultipleEntries() async{
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Batches are similar to transactions in the sense that all updates are happening atomically,
|
||||||
|
but they enable further optimizations to avoid preparing the same SQL statement twice.
|
||||||
|
This makes them suitable for bulk insert or update operations.
|
||||||
|
|
||||||
### Upserts
|
### Upserts
|
||||||
|
|
||||||
Upserts are a feature from newer sqlite3 versions that allows an insert to
|
Upserts are a feature from newer sqlite3 versions that allows an insert to
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
part of 'runtime_api.dart';
|
part of 'runtime_api.dart';
|
||||||
|
|
||||||
/// Contains operations to run queries in a batched mode. This can be much more
|
/// Contains operations to run queries in a batched mode.
|
||||||
/// efficient when running a lot of similar queries at the same time, making
|
///
|
||||||
/// this api suitable for bulk updates.
|
/// Inside a batch, a set of SQL statements is collected and then run at once.
|
||||||
|
/// Conceptually, batches are similar to a transaction (and they will use
|
||||||
|
/// transactions internally).
|
||||||
|
/// Additionally, batches are very efficient when the same SQL statement is
|
||||||
|
/// executed with different parameters. Outside of a batch, a new statement
|
||||||
|
/// would be parsed and prepared for each execution. With batches, statements
|
||||||
|
/// are only prepared once and then run with the parameters needed.
|
||||||
|
///
|
||||||
|
/// This makes batches particularly suitable for bulk updates.
|
||||||
class Batch {
|
class Batch {
|
||||||
final List<String> _createdSql = [];
|
final List<String> _createdSql = [];
|
||||||
final Map<String, int> _sqlToIndex = {};
|
final Map<String, int> _sqlToIndex = {};
|
||||||
|
|
Loading…
Reference in New Issue