insertAll method

Future<void> insertAll(
  1. Iterable<Insertable<Row>> rows, {
  2. UpsertClause<Row, RS>? onConflict,
})

Atomically inserts all rows into the table.

Unlike calling Batch.insertAll in a Batch directly, foreign keys are checked only after all inserts ran. In other words, the order in which the rows are in doesn't matter if there are foreign keys between them.

Implementation

Future<void> insertAll(
  Iterable<Insertable<Row>> rows, {
  UpsertClause<Row, RS>? onConflict,
}) {
  return database.transaction(
    options: const TransactionOptions(deferForeignKeys: true),
    () async {
      await database.batch((b) {
        b.insertAll(resultSet, rows, onConflict: onConflict);
      });
    },
  );
}