Skip to content

Add transaction support via sessions - #5

Merged
DavidBadura merged 1 commit into
1.1.xfrom
add-transaction-support
Aug 31, 2026
Merged

Add transaction support via sessions#5
DavidBadura merged 1 commit into
1.1.xfrom
add-transaction-support

Conversation

@DavidBadura

Copy link
Copy Markdown
Member

Adds opt-in transaction support on top of the existing single-connection model.

Client::startSession() returns a Session that manages BEGIN, COMMIT, and ROLLBACK on the client's PDO connection. Its API mirrors mongodb/mongodb with startTransaction, commitTransaction, abortTransaction, and withTransaction, allowing existing MongoDB-oriented code to keep working with minimal changes.

withTransaction handles commit and rollback automatically and retries transient failures such as serialization errors and deadlocks a limited number of times. MongoDB's readConcern is mapped to the corresponding PostgreSQL isolation level.

Because all operations already use the single PDO connection owned by the client, an active transaction automatically covers subsequent operations, regardless of whether the session option is explicitly passed. Sessions from a different client are not validated yet; this is documented as a current limitation.

Two related changes are included:

  • bulkWrite now joins an existing transaction instead of attempting to open a nested one, which PDO does not support.
  • QueryException now exposes the SQLSTATE so the transaction retry logic can identify transient database errors.

Nested transactions are rejected, matching MongoDB's behavior.

@DavidBadura DavidBadura added this to the 1.1.0 milestone Aug 29, 2026
@DavidBadura DavidBadura added the enhancement New feature or request label Aug 29, 2026
@DavidBadura
DavidBadura force-pushed the add-transaction-support branch from bd6cf09 to 97cdac0 Compare August 29, 2026 09:13
@DavidBadura
DavidBadura force-pushed the add-transaction-support branch from 97cdac0 to e59abdd Compare August 29, 2026 09:17
Comment thread .github/workflows/integration.yml
@DavidBadura
DavidBadura merged commit dbdcf80 into 1.1.x Aug 31, 2026
12 checks passed
@DavidBadura
DavidBadura deleted the add-transaction-support branch August 31, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants