MCPcopy
hub / github.com/jackc/pgx / OpenDBFromPool

Function OpenDBFromPool

stdlib/sql.go:237–242  ·  view source on GitHub ↗

OpenDBFromPool creates a new *sql.DB from the given *pgxpool.Pool. Note that this method automatically sets the maximum number of idle connections in *sql.DB to zero, since they must be managed from the *pgxpool.Pool. This is required to avoid acquiring all the connections from the pgxpool and starv

(pool *pgxpool.Pool, opts ...OptionOpenDB)

Source from the content-addressed store, hash-verified

235// required to avoid acquiring all the connections from the pgxpool and starving any direct users of the pgxpool. Note
236// that closing the returned *sql.DB will not close the *pgxpool.Pool.
237func OpenDBFromPool(pool *pgxpool.Pool, opts ...OptionOpenDB) *sql.DB {
238 c := GetPoolConnector(pool, opts...)
239 db := sql.OpenDB(c)
240 db.SetMaxIdleConns(0)
241 return db
242}
243
244type connector struct {
245 pgx.ConnConfig

Callers 1

TestSQLOpenFromPoolFunction · 0.92

Calls 1

GetPoolConnectorFunction · 0.85

Tested by 1

TestSQLOpenFromPoolFunction · 0.74