Skip to content

Allow setting default connection transaction behavior#1532

Merged
gwenn merged 3 commits intorusqlite:masterfrom
seddonm1:feat/set-transaction-behavior
Jul 19, 2024
Merged

Allow setting default connection transaction behavior#1532
gwenn merged 3 commits intorusqlite:masterfrom
seddonm1:feat/set-transaction-behavior

Conversation

@seddonm1
Copy link
Contributor

Hi,
It would be nice if a per connection default transaction_behavior could be set instead of having to use transaction_with_behavior everywhere.

Then, for example:

  • a connection of writing could be set conn.set_transaction_behavior(TransactionBehavior::Immediate)
  • read-connections would be conn.set_transaction_behavior(TransactionBehavior::Deferred)

This PR adds this behavior with the default value remaining unchanged as TransactionBehavior::Deferred.

@gwenn
Copy link
Collaborator

gwenn commented Jul 17, 2024

At least, we should document that this flag / field is ignored by manual / direct transactions:

let mut conn = Connection::open_in_memory()?;
conn.set_transaction_behavior(TransactionBehavior::Immediate);
conn.execute_batch("BEGIN")?; // deferred
...

@seddonm1
Copy link
Contributor Author

Thanks for the very quick review @gwenn and thanks for being open to this new feature.

I have refactored the code based on your comments and add an example so it is consistent with the rest of the code.

@codecov
Copy link

codecov bot commented Jul 18, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.

Project coverage is 85.20%. Comparing base (eebbbb0) to head (484e01b).
Report is 2 commits behind head on master.

Files Patch % Lines
src/transaction.rs 40.00% 3 Missing ⚠️
src/lib.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1532      +/-   ##
==========================================
- Coverage   85.23%   85.20%   -0.03%     
==========================================
  Files          54       54              
  Lines       10469    10476       +7     
==========================================
+ Hits         8923     8926       +3     
- Misses       1546     1550       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gwenn gwenn merged commit ba019d7 into rusqlite:master Jul 19, 2024
@gwenn
Copy link
Collaborator

gwenn commented Jul 19, 2024

Thanks.

cljoly added a commit to cljoly/rusqlite_migration that referenced this pull request Jul 22, 2024
Changelog at https://github.com/rusqlite/rusqlite/releases/tag/v0.32.0

Potential concern:
* rusqlite/rusqlite#1532: does this mean that
  default transaction behavior can interfer with the migrations?
cljoly added a commit to cljoly/rusqlite_migration that referenced this pull request Aug 20, 2024
Changelog at https://github.com/rusqlite/rusqlite/releases/tag/v0.32.0

Concerns:
* rusqlite/rusqlite#1532: does this mean that
  default transaction behavior can interfer with the migrations?
cljoly added a commit to cljoly/rusqlite_migration that referenced this pull request Sep 23, 2024
Changelog at https://github.com/rusqlite/rusqlite/releases/tag/v0.32.0

Concerns:
* rusqlite/rusqlite#1532: does this mean that
  default transaction behavior can interfer with the migrations?
cljoly added a commit to cljoly/rusqlite_migration that referenced this pull request Sep 23, 2024
Changelog at https://github.com/rusqlite/rusqlite/releases/tag/v0.32.0

Concerns:
* rusqlite/rusqlite#1532: does this mean that
  default transaction behavior can interfer with the migrations?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants