Add bussql transaction utilities and context propagation#13
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a shared bussql package for transaction management and context-based executor propagation, and refactors the bus and PostgreSQL dialect to use it. It also wires in SQLite for transaction tests and slightly tightens the repo’s ignore patterns.
Changes:
- Add
bussqlpackage withExecutor,FromContext/NewContext, andTransaction/savepoint logic plus comprehensive unit tests (using SQLite). - Replace the
BeginTx-style transaction handling inbus.BusImpl.Publishandpgbus.Dialect(Upsert,delete,drain) with a newExecTxmethod that leveragesbussql. - Update module dependencies and
.gitignoreto support the new tests and ignore test binaries.
Reviewed changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
.gitignore |
Adds patterns to ignore __debug* and *.test binaries, keeping the repo clean from local build artifacts. |
go.mod |
Adds a dependency on github.com/mattn/go-sqlite3 for running the new database-backed tests. |
go.sum |
Records checksums for the added SQLite dependency to keep module verification consistent. |
bus.go |
Refactors BusImpl.Publish to run job enqueuing inside Dialect.ExecTx, enabling reuse of ambient transactions via bussql and simplifying local transaction management. |
dialect.go (root) |
Updates the Dialect interface to expose ExecTx (and removes BeginTx), codifying transaction orchestration at the dialect level. |
pgbus/dialect.go |
Implements ExecTx using bussql.Transaction + FromContext/NewContext, and refactors Upsert, delete, and drain to use this shared transaction wrapper. |
bussql/context.go |
Introduces the Executor abstraction plus FromContext/NewContext helpers to propagate DB/Tx instances via context.Context. |
bussql/context_test.go |
Verifies FromContext/NewContext behavior, including overriding executors, nil handling, and fallback semantics. |
bussql/tx.go |
Provides generic Transaction and nested-savepoint logic with robust rollback/commit behavior and context-cancellation handling. |
bussql/tx_test.go |
Adds extensive tests (backed by in-memory SQLite) covering basic, rollback, nested, savepoint, and context-cancellation scenarios for Transaction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.