Skip to content

Commit

Permalink
Merge pull request #117 from pashagolub/111-remove-pgxpooliface-begin…
Browse files Browse the repository at this point in the history
…txfunc

[*] remove `pgxIface.BeginTxFunc()` as deprecated, closes #111
  • Loading branch information
pashagolub authored Nov 15, 2022
2 parents 4ab7090 + 6cc3c22 commit 7121ecc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
7 changes: 4 additions & 3 deletions examples/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"

pgx "github.com/jackc/pgx/v5"
pgxpool "github.com/jackc/pgx/v5/pgxpool"
)

type PgxIface interface {
Begin(context.Context) (pgx.Tx, error)
Close(context.Context) error
Close()
}

func recordStats(db PgxIface, userID, productID int) (err error) {
Expand Down Expand Up @@ -37,11 +38,11 @@ func recordStats(db PgxIface, userID, productID int) (err error) {

func main() {
// @NOTE: the real connection is not required for tests
db, err := pgx.Connect(context.Background(), "postgres://rolname@hostname/dbname")
db, err := pgxpool.New(context.Background(), "postgres://rolname@hostname/dbname")
if err != nil {
panic(err)
}
defer db.Close(context.Background())
defer db.Close()

if err = recordStats(db, 1 /*some user id*/, 5 /*some product id*/); err != nil {
panic(err)
Expand Down
9 changes: 4 additions & 5 deletions examples/basic/basic_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"context"
"fmt"
"testing"

Expand All @@ -10,11 +9,11 @@ import (

// a successful case
func TestShouldUpdateStats(t *testing.T) {
mock, err := pgxmock.NewConn()
mock, err := pgxmock.NewPool()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer mock.Close(context.Background())
defer mock.Close()

mock.ExpectBegin()
mock.ExpectExec("UPDATE products").WillReturnResult(pgxmock.NewResult("UPDATE", 1))
Expand All @@ -34,11 +33,11 @@ func TestShouldUpdateStats(t *testing.T) {

// a failing test case
func TestShouldRollbackStatUpdatesOnFailure(t *testing.T) {
mock, err := pgxmock.NewConn()
mock, err := pgxmock.NewPool()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer mock.Close(context.Background())
defer mock.Close()

mock.ExpectBegin()
mock.ExpectExec("UPDATE products").WillReturnResult(pgxmock.NewResult("UPDATE", 1))
Expand Down
1 change: 0 additions & 1 deletion pgxmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ type pgxMockIface interface {
type pgxIface interface {
pgxMockIface
Begin(context.Context) (pgx.Tx, error)
BeginTxFunc(ctx context.Context, txOptions pgx.TxOptions, f func(pgx.Tx) error) (err error)
BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
Expand Down

0 comments on commit 7121ecc

Please sign in to comment.