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

Method Connect

stdlib/sql.go:255–305  ·  view source on GitHub ↗

Connect implement driver.Connector interface

(ctx context.Context)

Source from the content-addressed store, hash-verified

253
254// Connect implement driver.Connector interface
255func (c connector) Connect(ctx context.Context) (driver.Conn, error) {
256 var (
257 connConfig pgx.ConnConfig
258 conn *pgx.Conn
259 close func(context.Context) error
260 err error
261 )
262
263 if c.pool == nil {
264 // Create a shallow copy of the config, so that BeforeConnect can safely modify it
265 connConfig = c.ConnConfig
266
267 if err = c.BeforeConnect(ctx, &connConfig); err != nil {
268 return nil, err
269 }
270
271 if conn, err = pgx.ConnectConfig(ctx, &connConfig); err != nil {
272 return nil, err
273 }
274
275 if err = c.AfterConnect(ctx, conn); err != nil {
276 return nil, err
277 }
278
279 close = conn.Close
280 } else {
281 var pconn *pgxpool.Conn
282
283 pconn, err = c.pool.Acquire(ctx)
284 if err != nil {
285 return nil, err
286 }
287
288 conn = pconn.Conn()
289
290 close = func(_ context.Context) error {
291 pconn.Release()
292 return nil
293 }
294 }
295
296 return &Conn{
297 conn: conn,
298 close: close,
299 driver: c.driver,
300 connConfig: connConfig,
301 resetSessionFunc: c.ResetSession,
302 shouldPing: c.ShouldPing,
303 psRefCounts: make(map[*pgconn.StatementDescription]int),
304 }, nil
305}
306
307// Driver implement driver.Connector interface
308func (c connector) Driver() driver.Driver {

Callers 15

TestCrateDBConnectFunction · 0.45
ExampleConn_SendBatchFunction · 0.45
ExampleForEachRowFunction · 0.45
ExampleCollectRowsFunction · 0.45
ExampleRowToFunction · 0.45
ExampleRowToAddrOfFunction · 0.45
ExampleRowToStructByPosFunction · 0.45
ExampleRowToStructByNameFunction · 0.45
TestLargeObjectsFunction · 0.45
BenchmarkConnectCloseFunction · 0.45

Calls 3

ConnMethod · 0.95
ReleaseMethod · 0.95
AcquireMethod · 0.80

Tested by 15

TestCrateDBConnectFunction · 0.36
ExampleConn_SendBatchFunction · 0.36
ExampleForEachRowFunction · 0.36
ExampleCollectRowsFunction · 0.36
ExampleRowToFunction · 0.36
ExampleRowToAddrOfFunction · 0.36
ExampleRowToStructByPosFunction · 0.36
ExampleRowToStructByNameFunction · 0.36
TestLargeObjectsFunction · 0.36
BenchmarkConnectCloseFunction · 0.36