Skip to content

Add bussql transaction utilities and context propagation#13

Merged
molon merged 3 commits intomainfrom
tx-support
Jan 29, 2026
Merged

Add bussql transaction utilities and context propagation#13
molon merged 3 commits intomainfrom
tx-support

Conversation

@molon
Copy link
Copy Markdown
Contributor

@molon molon commented Jan 29, 2026

No description provided.

Copilot AI review requested due to automatic review settings January 29, 2026 11:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bussql package with Executor, FromContext/NewContext, and Transaction/savepoint logic plus comprehensive unit tests (using SQLite).
  • Replace the BeginTx-style transaction handling in bus.BusImpl.Publish and pgbus.Dialect (Upsert, delete, drain) with a new ExecTx method that leverages bussql.
  • Update module dependencies and .gitignore to 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.

Comment thread bussql/context.go Outdated
Comment thread dialect.go
Comment thread bussql/context.go
@molon molon requested a review from Copilot January 29, 2026 11:36
@molon molon merged commit d102f70 into main Jan 29, 2026
8 checks passed
@molon molon review requested due to automatic review settings March 23, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants