本文整理汇总了Golang中github.com/jackc/pgx.ConnPool.Acquire方法的典型用法代码示例。如果您正苦于以下问题:Golang ConnPool.Acquire方法的具体用法?Golang ConnPool.Acquire怎么用?Golang ConnPool.Acquire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jackc/pgx.ConnPool
的用法示例。
在下文中一共展示了ConnPool.Acquire方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: acquireAllConnections
func acquireAllConnections(t *testing.T, pool *pgx.ConnPool, maxConnections int) []*pgx.Conn {
connections := make([]*pgx.Conn, maxConnections)
for i := 0; i < maxConnections; i++ {
var err error
if connections[i], err = pool.Acquire(); err != nil {
t.Fatalf("Unable to acquire connection: %v", err)
}
}
return connections
}
示例2: listenAndPoolUnlistens
func listenAndPoolUnlistens(pool *pgx.ConnPool, actionNum int) error {
conn, err := pool.Acquire()
if err != nil {
return err
}
defer pool.Release(conn)
err = conn.Listen("stress")
if err != nil {
return err
}
_, err = conn.WaitForNotification(100 * time.Millisecond)
if err == pgx.ErrNotificationTimeout {
return nil
}
return err
}
示例3: acquireWithTimeTaken
func acquireWithTimeTaken(pool *pgx.ConnPool) (*pgx.Conn, time.Duration, error) {
startTime := time.Now()
c, err := pool.Acquire()
return c, time.Now().Sub(startTime), err
}