enhanced transaction APIs - #11
Merged
Merged
Conversation
…ted documentation, and enhanced transaction APIs.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The transaction implementation currently introduces redundant rollback calls, and commit-error test expectations don’t match the cleanup behavior, which will likely break sqlmock-based tests.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR modernizes the project’s CI/tooling setup (GitHub Actions + golangci-lint + make targets) and refreshes documentation/examples around dbx’s context-aware APIs and transaction reuse semantics, alongside a functional update to transaction error handling.
Changes:
- Refactors
transactionWithInternalto reuse transactions viaFromContext, improves rollback error reporting (joining op + rollback failures), and updates examples to context-aware calls. - Overhauls CI by consolidating jobs (test/quality/race/vuln scan), pinning tool versions, and migrating linting/format checks to
golangci-lint+make fmt-check. - Updates docs and comments across the library to clarify
DatabasevsDatabaseWithContext, transaction reuse vs “independent” transactions, and context helper semantics; adds/refreshes tests and helpers.
File summaries
| File | Description |
|---|---|
| transaction.go | Updates transaction core logic (reuse detection + rollback error joining) and examples. |
| transaction_test.go | Reworks transaction tests for new semantics and adds new cases (panic, rollback join, reuse). |
| test_helpers_test.go | Adds shared sqlmock helper + test-only Beginner implementation. |
| README.md | Major doc refresh: context-aware API usage, transaction semantics, and examples. |
| options.go | Clarifies that isolation/read-only options apply only when dbx creates a new transaction. |
| options_test.go | Updates option tests and transaction-with-result tests to use shared helpers and new expectations. |
| Makefile | Switches lint to golangci-lint and adds fmt-check + test-race targets. |
| lib.go | Updates package/docs examples to use context-aware query/exec methods and clarifies transaction reuse phrasing. |
| go.mod | Removes toolchain pin and drops unused indirect deps. |
| go.sum | Tidies module checksums consistent with go.mod changes. |
| database.go | Improves docs and adds //nolint:noctx annotations for legacy database/sql-style methods. |
| database_test.go | Updates tests to reuse shared column-name constants and checks Rows.Err()/Row.Err(). |
| context.go | Updates examples to use context-aware exec; adds/extends context creation helpers. |
| context_test.go | Refactors tests to use shared sqlmock helper; adds coverage for NewContextFrom. |
| .golangci.yml | Migrates to a v2-style golangci-lint config, enabling formatters and reorganizing settings/exclusions. |
| .github/workflows/static-analysis.yml | Removes standalone static-analysis workflow (consolidated into CI). |
| .github/workflows/ci.yml | Rebuilds CI into separate jobs (test/quality/race/vuln), pins tool versions, and runs fmt-check/lint/tidy-diff. |
Review details
- Files reviewed: 16/17 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
… panics by introducing `operationReturned` flag.
… variables, and enhance error handling with reused transactions and panics.
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.
This pull request refactors and modernizes the CI pipeline, improves documentation, and updates code quality tooling for the project. The most important changes include a major overhaul of the GitHub Actions workflows, significant improvements and clarifications to the documentation (
README.md), and a migration togolangci-lintfor linting. The configuration for static analysis and formatting tools is also updated for better maintainability and clarity.CI/CD and Tooling Modernization:
.github/workflows/ci.ymlworkflow is completely restructured: it now uses versioned actions, adds environment variables for tool versions, splits jobs into test, quality (lint/format), race detection, and vulnerability scanning, and pins tool versions for reproducibility. The Go versions matrix is updated for clarity and future-proofing..github/workflows/static-analysis.ymlworkflow is removed, consolidating all static analysis into the main CI workflow.Makefileis updated to usegolangci-lintfor linting, adds afmt-checktarget for CI formatting checks, and introduces atest-racetarget for race condition testing.Documentation and API Clarification:
README.mdis extensively revised to clarify the API, usage patterns, and transaction management semantics. It updates code examples to use context-aware methods, explains the difference betweenDatabaseandDatabaseWithContext, and provides more accurate helper function descriptions and transaction behavior explanations. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]Static Analysis and Formatting Configuration:
.golangci.ymlconfiguration is rewritten for the latestgolangci-lintversion, enabling only the necessary linters, and moving linter settings under asettingsblock. It also adds exclusions and path settings for generated code and third-party directories, and configures formatters forgofmtandgoimports. [1] [2]Code Example Updates:
These changes collectively improve the project's maintainability, developer experience, and documentation accuracy.