Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crdb/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
// Tx abstracts the operations needed by ExecuteInTx so that different
// frameworks (e.g. go's sql package, pgx, gorm) can be used with ExecuteInTx.
type Tx interface {
Exec(context.Context, string, ...interface{}) error
Exec(context.Context, string, ...any) error
Commit(context.Context) error
Rollback(context.Context) error
}
Expand Down
2 changes: 1 addition & 1 deletion crdb/crdbgorm/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type gormTxAdapter struct {
var _ crdb.Tx = gormTxAdapter{}

// Exec is part of the crdb.Tx interface.
func (tx gormTxAdapter) Exec(_ context.Context, q string, args ...interface{}) error {
func (tx gormTxAdapter) Exec(_ context.Context, q string, args ...any) error {
return tx.db.Exec(q, args...).Error
}

Expand Down
6 changes: 3 additions & 3 deletions crdb/crdbgorm/gorm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ func (t gormWriteSkewTest) Init(context.Context) error {
}

// ExecuteTx is part of the crdb.WriteSkewTest interface.
func (t gormWriteSkewTest) ExecuteTx(ctx context.Context, fn func(tx interface{}) error) error {
func (t gormWriteSkewTest) ExecuteTx(ctx context.Context, fn func(tx any) error) error {
return ExecuteTx(ctx, t.db, nil /* opts */, func(tx *gorm.DB) error {
return fn(tx)
})
}

// GetBalances is part of the crdb.WriteSkewTest interface.
func (t gormWriteSkewTest) GetBalances(_ context.Context, txi interface{}) (int, int, error) {
func (t gormWriteSkewTest) GetBalances(_ context.Context, txi any) (int, int, error) {
tx := txi.(*gorm.DB)

var accounts []Account
Expand All @@ -118,7 +118,7 @@ func (t gormWriteSkewTest) GetBalances(_ context.Context, txi interface{}) (int,

// UpdateBalance is part of the crdb.WriteSkewInterface.
func (t gormWriteSkewTest) UpdateBalance(
_ context.Context, txi interface{}, accountID, delta int,
_ context.Context, txi any, accountID, delta int,
) error {
tx := txi.(*gorm.DB)
var acc Account
Expand Down
2 changes: 1 addition & 1 deletion crdb/crdbpgx/pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (tx pgxTxAdapter) Rollback(ctx context.Context) error {
}

// Exec is part of the crdb.Tx interface.
func (tx pgxTxAdapter) Exec(ctx context.Context, q string, args ...interface{}) error {
func (tx pgxTxAdapter) Exec(ctx context.Context, q string, args ...any) error {
_, err := tx.tx.Exec(ctx, q, args...)
return err
}
6 changes: 3 additions & 3 deletions crdb/crdbpgx/pgx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ INSERT INTO d.t (acct, balance) VALUES (1, 100), (2, 100);
var _ crdb.WriteSkewTest = pgxWriteSkewTest{}

// ExecuteTx is part of the crdb.WriteSkewTest interface.
func (t pgxWriteSkewTest) ExecuteTx(ctx context.Context, fn func(tx interface{}) error) error {
func (t pgxWriteSkewTest) ExecuteTx(ctx context.Context, fn func(tx any) error) error {
return ExecuteTx(ctx, t.pool, pgx.TxOptions{}, func(tx pgx.Tx) error {
return fn(tx)
})
}

// GetBalances is part of the crdb.WriteSkewTest interface.
func (t pgxWriteSkewTest) GetBalances(ctx context.Context, txi interface{}) (int, int, error) {
func (t pgxWriteSkewTest) GetBalances(ctx context.Context, txi any) (int, int, error) {
tx := txi.(pgx.Tx)
var rows pgx.Rows
rows, err := tx.Query(ctx, `SELECT balance FROM d.t WHERE acct IN (1, 2);`)
Expand All @@ -92,7 +92,7 @@ func (t pgxWriteSkewTest) GetBalances(ctx context.Context, txi interface{}) (int

// UpdateBalance is part of the crdb.WriteSkewInterface.
func (t pgxWriteSkewTest) UpdateBalance(
ctx context.Context, txi interface{}, acct, delta int,
ctx context.Context, txi any, acct, delta int,
) error {
tx := txi.(pgx.Tx)
_, err := tx.Exec(ctx, `UPDATE d.t SET balance=balance+$1 WHERE acct=$2;`, delta, acct)
Expand Down
2 changes: 1 addition & 1 deletion crdb/crdbpgxv5/pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (tx pgxTxAdapter) Rollback(ctx context.Context) error {
}

// Exec is part of the crdb.Tx interface.
func (tx pgxTxAdapter) Exec(ctx context.Context, q string, args ...interface{}) error {
func (tx pgxTxAdapter) Exec(ctx context.Context, q string, args ...any) error {
_, err := tx.tx.Exec(ctx, q, args...)
return err
}
6 changes: 3 additions & 3 deletions crdb/crdbpgxv5/pgx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ INSERT INTO d.t (acct, balance) VALUES (1, 100), (2, 100);
var _ crdb.WriteSkewTest = pgxWriteSkewTest{}

// ExecuteTx is part of the crdb.WriteSkewTest interface.
func (t pgxWriteSkewTest) ExecuteTx(ctx context.Context, fn func(tx interface{}) error) error {
func (t pgxWriteSkewTest) ExecuteTx(ctx context.Context, fn func(tx any) error) error {
return ExecuteTx(ctx, t.pool, pgx.TxOptions{}, func(tx pgx.Tx) error {
return fn(tx)
})
}

// GetBalances is part of the crdb.WriteSkewTest interface.
func (t pgxWriteSkewTest) GetBalances(ctx context.Context, txi interface{}) (int, int, error) {
func (t pgxWriteSkewTest) GetBalances(ctx context.Context, txi any) (int, int, error) {
tx := txi.(pgx.Tx)
var rows pgx.Rows
rows, err := tx.Query(ctx, `SELECT balance FROM d.t WHERE acct IN (1, 2);`)
Expand All @@ -92,7 +92,7 @@ func (t pgxWriteSkewTest) GetBalances(ctx context.Context, txi interface{}) (int

// UpdateBalance is part of the crdb.WriteSkewInterface.
func (t pgxWriteSkewTest) UpdateBalance(
ctx context.Context, txi interface{}, acct, delta int,
ctx context.Context, txi any, acct, delta int,
) error {
tx := txi.(pgx.Tx)
_, err := tx.Exec(ctx, `UPDATE d.t SET balance=balance+$1 WHERE acct=$2;`, delta, acct)
Expand Down
2 changes: 1 addition & 1 deletion crdb/crdbsqlx/sqlx.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type sqlxTxAdapter struct {

var _ crdb.Tx = sqlxTxAdapter{}

func (s sqlxTxAdapter) Exec(ctx context.Context, query string, args ...interface{}) error {
func (s sqlxTxAdapter) Exec(ctx context.Context, query string, args ...any) error {
_, err := s.Tx.ExecContext(ctx, query, args...)
return err
}
Expand Down
6 changes: 3 additions & 3 deletions crdb/crdbsqlx/sqlx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ INSERT INTO d.t (acct, balance) VALUES (1, 100), (2, 100);
var _ crdb.WriteSkewTest = sqlxConnSkewTest{}

// ExecuteTx is part of the crdb.WriteSkewTest interface.
func (t sqlxConnSkewTest) ExecuteTx(ctx context.Context, fn func(tx interface{}) error) error {
func (t sqlxConnSkewTest) ExecuteTx(ctx context.Context, fn func(tx any) error) error {
return ExecuteTx(ctx, t.db, nil /* txOptions */, func(tx *sqlx.Tx) error {
return fn(tx)
})
}

// GetBalances is part of the crdb.WriteSkewTest interface.
func (t sqlxConnSkewTest) GetBalances(ctx context.Context, txi interface{}) (int, int, error) {
func (t sqlxConnSkewTest) GetBalances(ctx context.Context, txi any) (int, int, error) {
tx := txi.(*sqlx.Tx)
rows, err := tx.QueryContext(ctx, `SELECT balance FROM d.t WHERE acct IN (1, 2);`)
if err != nil {
Expand All @@ -94,7 +94,7 @@ func (t sqlxConnSkewTest) GetBalances(ctx context.Context, txi interface{}) (int

// UpdateBalance is part of the crdb.WriteSkewInterface.
func (t sqlxConnSkewTest) UpdateBalance(
ctx context.Context, txi interface{}, acct, delta int,
ctx context.Context, txi any, acct, delta int,
) error {
tx := txi.(*sqlx.Tx)
_, err := tx.ExecContext(ctx, `UPDATE d.t SET balance=balance+$1 WHERE acct=$2;`, delta, acct)
Expand Down
10 changes: 5 additions & 5 deletions crdb/testing_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
// to be written once and run for any framework supported by this library.
type WriteSkewTest interface {
Init(context.Context) error
ExecuteTx(ctx context.Context, fn func(tx interface{}) error) error
GetBalances(ctx context.Context, tx interface{}) (bal1, bal2 int, err error)
UpdateBalance(ctx context.Context, tx interface{}, acct, delta int) error
ExecuteTx(ctx context.Context, fn func(tx any) error) error
GetBalances(ctx context.Context, tx any) (bal1, bal2 int, err error)
UpdateBalance(ctx context.Context, tx any, acct, delta int) error
}

// ExecuteTxGenericTest represents the structure of a test for the ExecuteTx
Expand All @@ -47,7 +47,7 @@ func ExecuteTxGenericTest(ctx context.Context, framework WriteSkewTest) error {
errCh := make(chan error, 1)
go func() {
*iter = 0
errCh <- framework.ExecuteTx(ctx, func(tx interface{}) (retErr error) {
errCh <- framework.ExecuteTx(ctx, func(tx any) (retErr error) {
defer func() {
if retErr == nil {
return
Expand Down Expand Up @@ -103,7 +103,7 @@ func ExecuteTxGenericTest(ctx context.Context, framework WriteSkewTest) error {
}

var bal1, bal2 int
err := framework.ExecuteTx(ctx, func(txi interface{}) error {
err := framework.ExecuteTx(ctx, func(txi any) error {
var err error
bal1, bal2, err = framework.GetBalances(ctx, txi)
return err
Expand Down
8 changes: 4 additions & 4 deletions crdb/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func Execute(fn func() error) (err error) {
// ExecuteCtxFunc represents a function that takes a context and variadic
// arguments and returns an error. It's used with ExecuteCtx to enable retryable
// operations with configurable parameters.
type ExecuteCtxFunc func(context.Context, ...interface{}) error
type ExecuteCtxFunc func(context.Context, ...any) error

// ExecuteCtx runs fn and retries it as needed, respecting a retry policy
// obtained from the context. It is used to add configurable retry handling to
Expand Down Expand Up @@ -134,7 +134,7 @@ type ExecuteCtxFunc func(context.Context, ...interface{}) error
// `Cause() error` (github.com/pkg/errors) or `Unwrap() error` (Go 1.13+).
// For example:
//
// crdb.ExecuteCtx(ctx, func(ctx context.Context, args ...interface{}) error {
// crdb.ExecuteCtx(ctx, func(ctx context.Context, args ...any) error {
// id := args[0].(int)
// rows, err := db.QueryContext(ctx, "SELECT * FROM users WHERE id = $1", id)
// if err != nil {
Expand All @@ -144,7 +144,7 @@ type ExecuteCtxFunc func(context.Context, ...interface{}) error
// // ...
// return nil
// }, userID)
func ExecuteCtx(ctx context.Context, fn ExecuteCtxFunc, args ...interface{}) (err error) {
func ExecuteCtx(ctx context.Context, fn ExecuteCtxFunc, args ...any) (err error) {
// establish the retry policy
retryPolicy := getRetryPolicy(ctx)
// set up the retry policy state
Expand Down Expand Up @@ -312,7 +312,7 @@ type stdlibTxnAdapter struct {
var _ Tx = stdlibTxnAdapter{}

// Exec is part of the tx interface.
func (tx stdlibTxnAdapter) Exec(ctx context.Context, q string, args ...interface{}) error {
func (tx stdlibTxnAdapter) Exec(ctx context.Context, q string, args ...any) error {
_, err := tx.tx.ExecContext(ctx, q, args...)
return err
}
Expand Down
8 changes: 4 additions & 4 deletions crdb/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestExecuteCtx(t *testing.T) {
{"no args", 1, 3, false, nil},
}

fn := func(ctx context.Context, args ...interface{}) error {
fn := func(ctx context.Context, args ...any) error {
if len(args) == 0 {
_, err := db.ExecContext(ctx, `INSERT INTO test_retry VALUES (3)`)
return err
Expand Down Expand Up @@ -179,13 +179,13 @@ INSERT INTO d.t (acct, balance) VALUES (1, 100), (2, 100);
return err
}

func (t stdlibWriteSkewTest) ExecuteTx(ctx context.Context, fn func(tx interface{}) error) error {
func (t stdlibWriteSkewTest) ExecuteTx(ctx context.Context, fn func(tx any) error) error {
return ExecuteTx(ctx, t.db, nil /* opts */, func(tx *sql.Tx) error {
return fn(tx)
})
}

func (t stdlibWriteSkewTest) GetBalances(ctx context.Context, txi interface{}) (int, int, error) {
func (t stdlibWriteSkewTest) GetBalances(ctx context.Context, txi any) (int, int, error) {
tx := txi.(*sql.Tx)
var rows *sql.Rows
rows, err := tx.QueryContext(ctx, `SELECT balance FROM d.t WHERE acct IN (1, 2);`)
Expand All @@ -208,7 +208,7 @@ func (t stdlibWriteSkewTest) GetBalances(ctx context.Context, txi interface{}) (
}

func (t stdlibWriteSkewTest) UpdateBalance(
ctx context.Context, txi interface{}, acct, delta int,
ctx context.Context, txi any, acct, delta int,
) error {
tx := txi.(*sql.Tx)
_, err := tx.ExecContext(ctx, `UPDATE d.t SET balance=balance+$1 WHERE acct=$2;`, delta, acct)
Expand Down