Skip to content

Commit e6e4f9c

Browse files
authored
Merge pull request #1 from randlabs/updated_deps
Updated dependencies and added comments.
2 parents 020f38a + 0906de6 commit e6e4f9c

File tree

8 files changed

+43
-33
lines changed

8 files changed

+43
-33
lines changed

go.mod

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ module github.com/randlabs/go-postgres
22

33
go 1.19
44

5-
require (
6-
github.com/jackc/pgx/v5 v5.2.0
7-
github.com/randlabs/go-exterror v1.0.0
8-
)
5+
require github.com/jackc/pgx/v5 v5.4.2
96

107
require (
118
github.com/jackc/pgpassfile v1.0.0 // indirect
12-
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
13-
github.com/jackc/puddle/v2 v2.1.2 // indirect
14-
go.uber.org/atomic v1.10.0 // indirect
15-
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
16-
golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7 // indirect
17-
golang.org/x/text v0.3.8 // indirect
9+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
10+
github.com/jackc/puddle/v2 v2.2.0 // indirect
11+
golang.org/x/crypto v0.11.0 // indirect
12+
golang.org/x/sync v0.1.0 // indirect
13+
golang.org/x/text v0.11.0 // indirect
1814
)

go.sum

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
22
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
33
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
44
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
5-
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg=
6-
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
7-
github.com/jackc/pgx/v5 v5.2.0 h1:NdPpngX0Y6z6XDFKqmFQaE+bCtkqzvQIOt1wvBlAqs8=
8-
github.com/jackc/pgx/v5 v5.2.0/go.mod h1:Ptn7zmohNsWEsdxRawMzk3gaKma2obW+NWTnKa0S4nk=
9-
github.com/jackc/puddle/v2 v2.1.2 h1:0f7vaaXINONKTsxYDn4otOAiJanX/BMeAtY//BXqzlg=
10-
github.com/jackc/puddle/v2 v2.1.2/go.mod h1:2lpufsF5mRHO6SuZkm0fNYxM6SWHfvyFj62KwNzgels=
5+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
6+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
7+
github.com/jackc/pgx/v5 v5.4.2 h1:u1gmGDwbdRUZiwisBm/Ky2M14uQyUP65bG8+20nnyrg=
8+
github.com/jackc/pgx/v5 v5.4.2/go.mod h1:q6iHT8uDNXWiFNOlRqJzBTaSH3+2xCXkokxHZC5qWFY=
9+
github.com/jackc/puddle/v2 v2.2.0 h1:RdcDk92EJBuBS55nQMMYFXTxwstHug4jkhT5pq8VxPk=
10+
github.com/jackc/puddle/v2 v2.2.0/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
1111
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1212
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
13-
github.com/randlabs/go-exterror v1.0.0 h1:KJT5iMslnIK3acMQELSoKTmGbjgBReVryo/VCYu/qw0=
14-
github.com/randlabs/go-exterror v1.0.0/go.mod h1:4XHfj2DJ9E7JTpuS1tBrr40y2WNQEIwAb5/flSqY7Lo=
1513
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1614
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
17-
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
18-
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
19-
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
20-
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
21-
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM=
22-
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
23-
golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7 h1:ZrnxWX62AgTKOSagEqxvb3ffipvEDX2pl7E1TdqLqIc=
24-
golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
25-
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
26-
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
15+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
16+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
17+
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
18+
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
19+
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
20+
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
21+
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
22+
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
2723
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
28-
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
24+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2925
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

internal.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var errNoRows = &NoRowsError{}
1313

1414
// -----------------------------------------------------------------------------
1515

16-
// Gets a connection from the pool and initiates a transaction
16+
// Gets a connection from the pool and initiates a transaction.
1717
func (db *Database) getTx(ctx context.Context) (pgx.Tx, error) {
1818
tx, err := db.pool.BeginTx(ctx, pgx.TxOptions{
1919
IsoLevel: pgx.ReadCommitted, //pgx.Serializable,
@@ -40,12 +40,16 @@ func (db *Database) processError(err error) error {
4040
if err != nil && IsDatabaseError(err) && err != errNoRows {
4141
if db.err.last == nil {
4242
db.err.last = err
43-
db.err.handler(err)
43+
if db.err.handler != nil {
44+
db.err.handler(err)
45+
}
4446
}
4547
} else {
4648
if db.err.last != nil {
4749
db.err.last = nil
48-
db.err.handler(nil)
50+
if db.err.handler != nil {
51+
db.err.handler(nil)
52+
}
4953
}
5054
}
5155

postgres.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ import (
1313

1414
// -----------------------------------------------------------------------------
1515

16+
// WithinTxCallback defines a callback called in the context of the initiated transaction.
1617
type WithinTxCallback = func(ctx context.Context, tx Tx) error
18+
19+
// CopyCallback defines a callback that is called for each record being copied to the database
1720
type CopyCallback func(ctx context.Context, idx int) ([]interface{}, error)
1821

1922
// -----------------------------------------------------------------------------
2023

24+
// Database represents a PostgreSQL database accessor.
2125
type Database struct {
2226
pool *pgxpool.Pool
2327
err struct {
@@ -27,6 +31,7 @@ type Database struct {
2731
}
2832
}
2933

34+
// Options defines the database connection options.
3035
type Options struct {
3136
Host string `json:"host"`
3237
Port uint16 `json:"port"`
@@ -37,8 +42,10 @@ type Options struct {
3742
SSLMode SSLMode
3843
}
3944

45+
// ErrorHandler defines a custom error handler.
4046
type ErrorHandler func(err error)
4147

48+
// SSLMode states if secure communication with the server is optional or mandatory.
4249
type SSLMode int
4350

4451
const (

postgres_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ func TestPostgres(t *testing.T) {
117117
if err != nil {
118118
t.Fatalf("%v", err.Error())
119119
}
120-
// We comment the next line because we want to do a clean database pool shutdown on errors
120+
// We comment the next defer line because we want to do a clean database pool shutdown on errors and
121+
// calling fatal exits the process.
121122
// defer db.Close()
122123

123124
ctx := context.Background()

rowgetter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66

77
// -----------------------------------------------------------------------------
88

9+
// Row defines a returned record.
910
type Row interface {
11+
// Scan saves the content of the current row in the destination variables.
1012
Scan(dest ...interface{}) error
1113
}
1214

rowsgetter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import (
88

99
// -----------------------------------------------------------------------------
1010

11+
// ScanRowsCallback defines a callback that is called on each row returned by the executed query.
1112
type ScanRowsCallback = func(ctx context.Context, row Row) (bool, error)
1213

14+
// Rows defines a set of returned records.
1315
type Rows interface {
16+
// Do calls the provided callback for each row returned by the executed query.
1417
Do(callback ScanRowsCallback) error
1518
}
1619

transaction.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
// -----------------------------------------------------------------------------
1010

11+
// Tx encloses a transation object.
1112
type Tx struct {
1213
db *Database
1314
tx pgx.Tx

0 commit comments

Comments
 (0)