mirror of https://github.com/jackc/pgx.git
remove before/after acquire hooks
parent
639691c0ab
commit
18856482c4
|
@ -152,20 +152,6 @@ func OptionAfterConnect(ac func(context.Context, *pgx.Conn) error) OptionOpenDB
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OptionBeforeConnect provides a callback for before acquire. Used only if db is opened with *pgxpool.Pool.
|
|
||||||
func OptionBeforeAcquire(ba func(context.Context, *pgxpool.Pool) error) OptionOpenDB {
|
|
||||||
return func(c *connector) {
|
|
||||||
c.BeforeAcquire = ba
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// OptionAfterAcquire provides a callback for after acquire. Used only if db is opened with *pgxpool.Pool.
|
|
||||||
func OptionAfterAcquire(aa func(context.Context, *pgxpool.Conn) error) OptionOpenDB {
|
|
||||||
return func(c *connector) {
|
|
||||||
c.AfterAcquire = aa
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// OptionResetSession provides a callback that can be used to add custom logic prior to executing a query on the
|
// OptionResetSession provides a callback that can be used to add custom logic prior to executing a query on the
|
||||||
// connection if the connection has been used before.
|
// connection if the connection has been used before.
|
||||||
// If ResetSessionFunc returns ErrBadConn error the connection will be discarded.
|
// If ResetSessionFunc returns ErrBadConn error the connection will be discarded.
|
||||||
|
@ -220,11 +206,9 @@ func GetConnector(config pgx.ConnConfig, opts ...OptionOpenDB) driver.Connector
|
||||||
|
|
||||||
func GetPoolConnector(pool *pgxpool.Pool, opts ...OptionOpenDB) driver.Connector {
|
func GetPoolConnector(pool *pgxpool.Pool, opts ...OptionOpenDB) driver.Connector {
|
||||||
c := connector{
|
c := connector{
|
||||||
pool: pool,
|
pool: pool,
|
||||||
BeforeAcquire: func(context.Context, *pgxpool.Pool) error { return nil }, // noop before acquire by default
|
ResetSession: func(context.Context, *pgx.Conn) error { return nil }, // noop reset session by default
|
||||||
AfterAcquire: func(context.Context, *pgxpool.Conn) error { return nil }, // noop after acquire by default
|
driver: pgxDriver,
|
||||||
ResetSession: func(context.Context, *pgx.Conn) error { return nil }, // noop reset session by default
|
|
||||||
driver: pgxDriver,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
|
@ -251,8 +235,6 @@ type connector struct {
|
||||||
pool *pgxpool.Pool
|
pool *pgxpool.Pool
|
||||||
BeforeConnect func(context.Context, *pgx.ConnConfig) error // function to call before creation of every new connection
|
BeforeConnect func(context.Context, *pgx.ConnConfig) error // function to call before creation of every new connection
|
||||||
AfterConnect func(context.Context, *pgx.Conn) error // function to call after creation of every new connection
|
AfterConnect func(context.Context, *pgx.Conn) error // function to call after creation of every new connection
|
||||||
BeforeAcquire func(context.Context, *pgxpool.Pool) error // function to call before acquiring of every new connection
|
|
||||||
AfterAcquire func(context.Context, *pgxpool.Conn) error // function to call after acquiring of every new connection
|
|
||||||
ResetSession func(context.Context, *pgx.Conn) error // function is called before a connection is reused
|
ResetSession func(context.Context, *pgx.Conn) error // function is called before a connection is reused
|
||||||
driver *Driver
|
driver *Driver
|
||||||
}
|
}
|
||||||
|
@ -286,19 +268,11 @@ func (c connector) Connect(ctx context.Context) (driver.Conn, error) {
|
||||||
} else {
|
} else {
|
||||||
var pconn *pgxpool.Conn
|
var pconn *pgxpool.Conn
|
||||||
|
|
||||||
if err = c.BeforeAcquire(ctx, c.pool); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
pconn, err = c.pool.Acquire(ctx)
|
pconn, err = c.pool.Acquire(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = c.AfterAcquire(ctx, pconn); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
conn = pconn.Conn()
|
conn = pconn.Conn()
|
||||||
|
|
||||||
close = func(_ context.Context) error {
|
close = func(_ context.Context) error {
|
||||||
|
|
Loading…
Reference in New Issue