Skip to content

Add begin_with methods to support database-specific transaction options#3614

Closed
bonsairobo wants to merge 12 commits into
transact-rs:mainfrom
fslabs:duncan/begin-with
Closed

Add begin_with methods to support database-specific transaction options#3614
bonsairobo wants to merge 12 commits into
transact-rs:mainfrom
fslabs:duncan/begin-with

Conversation

@bonsairobo
Copy link
Copy Markdown

Fixes #481

@bonsairobo bonsairobo force-pushed the duncan/begin-with branch 2 times, most recently from 2041cdf to 7ab05a6 Compare November 28, 2024 03:23
@bonsairobo

This comment was marked as outdated.

Comment thread sqlx-core/src/connection.rs
Comment thread sqlx-core/src/connection.rs Outdated
Comment thread sqlx-sqlite/src/connection/mod.rs Outdated
Comment thread sqlx-mysql/src/transaction.rs Outdated
Comment thread tests/sqlite/sqlite.rs Outdated
@bonsairobo bonsairobo requested a review from abonander December 3, 2024 03:18
@bonsairobo

This comment was marked as outdated.

@bonsairobo
Copy link
Copy Markdown
Author

I'm having trouble running the MySQL tests locally. I keep ending up with this error:

error communicating with database: expected to read 4 bytes, got 0 bytes at EOF

Even after I remove the mysql container.

@bonsairobo
Copy link
Copy Markdown
Author

@abonander All review comments have been addressed. Mind taking another look?

@abonander
Copy link
Copy Markdown
Collaborator

@bonsairobo can you rebase and fix conflicts?

Duncan Fairbanks added 10 commits January 26, 2025 00:36
This patch completes the plumbing of an optional statement from these methods to
`TransactionManager::begin` without any validation of the provided statement.

There is a new `Error::InvalidSavePoint` which is triggered by any attempt to
call `Connection::begin_with` when we are already inside of a transaction.
This makes the new method a non-breaking change.
@bonsairobo bonsairobo force-pushed the duncan/begin-with branch 2 times, most recently from e58d85a to f565ea1 Compare January 26, 2025 08:47
Duncan Fairbanks added 2 commits January 26, 2025 00:48
abonander added a commit that referenced this pull request Mar 10, 2025
* feat: Implement `get_transaction_depth` for drivers

* test: Verify `get_transaction_depth()` on postgres

* Refactor: `TransactionManager` delegation without BC

SQLite implementation is currently WIP

* Fix: Avoid breaking changes on `AnyConnectionBackend`

* Refactor: Remove verbose `SqliteConnection` typing

* Feat: Implementation for SQLite

I have included `AtomicUsize` in `WorkerSharedState`. Ideally, it is not desirable to execute `load` and `fetch_add` in two separate steps, but we decided to allow it here since there is only one thread writing. To prevent writing from other threads, the field itself was made private, and a getter method was provided with `pub(crate)`.

* Refactor: Same approach for `cached_statements_size`

ref: a66787d

* Fix: Add missing `is_in_transaction` for backend

* Doc: Remove verbose "synchronously" word

* Fix: Remove useless `mut` qualifier

* feat: add Connection::begin_with

This patch completes the plumbing of an optional statement from these methods to
`TransactionManager::begin` without any validation of the provided statement.

There is a new `Error::InvalidSavePoint` which is triggered by any attempt to
call `Connection::begin_with` when we are already inside of a transaction.

* feat: add Pool::begin_with and Pool::try_begin_with

* feat: add Error::BeginFailed and validate that custom "begin" statements are successful

* chore: add tests of Error::BeginFailed

* chore: add tests of Error::InvalidSavePointStatement

* chore: test begin_with works for all SQLite "BEGIN" statements

* chore: improve comment on Connection::begin_with

* feat: add default impl of `Connection::begin_with`

This makes the new method a non-breaking change.

* refactor: combine if statement + unwrap_or_else into one match

* feat: use in-memory SQLite DB to avoid conflicts across tests run in parallel

* feedback: remove public wrapper for sqlite3_txn_state

Move the wrapper directly into the test that uses it instead.

* fix: cache Status on MySqlConnection

* fix: compilation errors

* fix: format

* fix: postgres test

* refactor: delete `Connection::get_transaction_depth`

* fix: tests

---------

Co-authored-by: mpyw <ryosuke_i_628@yahoo.co.jp>
Co-authored-by: Duncan Fairbanks <duncanfairbanks6@gmail.com>
@abonander
Copy link
Copy Markdown
Collaborator

Merged in #3765

@abonander abonander closed this Mar 10, 2025
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.

Isolation level support

2 participants