aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-09-08 18:26:05 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-09-08 18:26:06 +0200
commit9686269498477d0b56caf06166a975a25248b1c1 (patch)
tree7f8cc0aebd3f8fbac6e1a26c4f8e46caada87ea9
parenta6eb1abe75f1abc807d98c48dd1edc86c54cefb9 (diff)
downloadgo-gg-9686269498477d0b56caf06166a975a25248b1c1.tar.gz
gsql: change WithinTransaction methods to take sql.TxOptions
This makes them usable as replacements for BeginTx + Commit/Rollback.
-rw-r--r--CHANGELOG.md5
-rw-r--r--gsql/std.go14
2 files changed, 11 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4150b9e..1468577 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,10 +3,13 @@ SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
SPDX-License-Identifier: Apache-2.0
-->
-# v1.14.1 (TBD)
+# v1.15.0 (TBD)
Changes:
+- gsql: Add an additional `*sql.TxOptions` argument to `WithinTransaction` methods.
+ This constitutes a breaking change, which I find acceptable because there are no known users of this function yet.
+ The alternative would have been to pollute the namespace with additional methods (like for `Begin` vs `BeginTx`).
- Improve presentation of string literals in `assert.ErrEqual()` output (same as for `assert.Equal()` in v1.11.0).
# v1.14.0 (2026-08-18)
diff --git a/gsql/std.go b/gsql/std.go
index 1896725..bf4c718 100644
--- a/gsql/std.go
+++ b/gsql/std.go
@@ -58,8 +58,8 @@ func (db *DB) Conn(ctx context.Context) (*Conn, error) {
//
// This is equivalent to the GSQLTransact() method of the DB's [ConnectionHandle] implementation,
// but the callback receives the concrete type [*Tx] instead of a generic [Handle].
-func (db *DB) WithinTransaction(ctx context.Context, action func(*Tx) error) error {
- return withinTransaction(ctx, db.DB, action)
+func (db *DB) WithinTransaction(ctx context.Context, opts *sql.TxOptions, action func(*Tx) error) error {
+ return withinTransaction(ctx, db.DB, opts, action)
}
// Conn wraps [*sql.Conn] into a [Handle].
@@ -87,8 +87,8 @@ func (conn *Conn) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
//
// This is equivalent to the GSQLTransact() method of conn's [ConnectionHandle] implementation,
// but the callback receives the concrete type [*Tx] instead of a generic [Handle].
-func (conn *Conn) WithinTransaction(ctx context.Context, action func(*Tx) error) error {
- return withinTransaction(ctx, conn.Conn, action)
+func (conn *Conn) WithinTransaction(ctx context.Context, opts *sql.TxOptions, action func(*Tx) error) error {
+ return withinTransaction(ctx, conn.Conn, opts, action)
}
// Tx wraps [*sql.Tx] into a [Handle].
@@ -209,14 +209,14 @@ func (h sqlConnectionHandle[T]) GSQLClose(ctx context.Context) error {
// GSQLTransact implements the [ConnectionHandle] interface.
func (h sqlConnectionHandle[T]) GSQLTransact(ctx context.Context, action func(tx Handle) error) error {
- return withinTransaction(ctx, h.Base, func(tx *Tx) error {
+ return withinTransaction(ctx, h.Base, nil, func(tx *Tx) error {
return action(tx)
})
}
// withinTransaction implements the method of that name that exists on all types based on [sqlConnectionHandle].
-func withinTransaction(ctx context.Context, conn sqlConnection, action func(*Tx) error) error {
- tx, err := conn.BeginTx(ctx, nil)
+func withinTransaction(ctx context.Context, conn sqlConnection, opts *sql.TxOptions, action func(*Tx) error) error {
+ tx, err := conn.BeginTx(ctx, opts)
if err != nil {
return err
}