Skip to content

Commit

Permalink
Only apply defer_foreign_keys on SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Dec 28, 2024
1 parent e7c49e5 commit 2e40917
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions drift/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.23.1-dev

- Fix `TableStatements.insertAll` to only apply a database-specific pragma for
SQLite databases.

## 2.23.0

- Allow building compound select statements in Dart.
Expand Down
9 changes: 8 additions & 1 deletion drift/lib/src/runtime/query_builder/on_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ extension TableStatements<Tbl extends Table, Row> on TableInfo<Tbl, Row> {
Future<void> insertAll(Iterable<Insertable<Row>> rows,
{InsertMode? mode, UpsertClause<Tbl, Row>? onConflict}) {
return attachedDatabase.batch((b) {
b.customStatement('pragma defer_foreign_keys = on;');
// TODO: Remove this pragma, it should be an explicit opt-in.
// https://github.com/simolus3/drift/issues/3393
if (attachedDatabase.executor.dialect == SqlDialect.sqlite) {
// Note that this batch runs in a transaction, the pragma will be reset
// when the transaction completes.
b.customStatement('pragma defer_foreign_keys = on;');
}

b.insertAll(this, rows, mode: mode, onConflict: onConflict);
});
}
Expand Down
2 changes: 1 addition & 1 deletion drift/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: drift
description: Drift is a reactive library to store relational data in Dart and Flutter applications.
version: 2.23.0
version: 2.23.1-dev
repository: https://github.com/simolus3/drift
homepage: https://drift.simonbinder.eu/
issue_tracker: https://github.com/simolus3/drift/issues
Expand Down

0 comments on commit 2e40917

Please sign in to comment.