executeBatch method

Future<void> executeBatch(
  1. String sql,
  2. List<List<Object?>> paramSets
)

Executes one SQL statement across many parameter sets in a single transaction.

await db.executeBatch(
  'INSERT INTO users(name) VALUES (?)',
  [['Ada'], ['Grace'], ['Sonja']],
);

The statement is prepared once and reused across all paramSets, wrapped in a single BEGIN/COMMIT transaction. This is significantly faster than calling execute in a loop.

All-or-nothing: if any row fails, the entire batch rolls back.

Streams watching the affected table fire once on commit, not per row.

Throws a ResqliteQueryException if any statement fails.

Implementation

Future<void> executeBatch(String sql, List<List<Object?>> paramSets) async {
  final transaction = Transaction.current;
  if (transaction != null) {
    return transaction.executeBatch(sql, paramSets);
  }

  _ensureOpen();

  final writer = await _writer;
  final reponse =
      await writer.locked(() => writer.executeBatch(sql, paramSets));

  if (reponse?.dirtyTables case List<String> dirtyTables) {
    _streamEngine.handleDirtyTables(dirtyTables);
  }
}