From aa8604b5c22989167e7158ecb1f6e7b8ddfebf04 Mon Sep 17 00:00:00 2001 From: davidsbond Date: Mon, 25 Jan 2021 17:09:07 +0000 Subject: [PATCH] Add Ping method to pgxpool.Conn Adds the Ping method to pgxpool.Conn, returning the result of calling Ping on the underlying pgx.Conn. --- pgxpool/conn.go | 4 ++++ pgxpool/pool.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/pgxpool/conn.go b/pgxpool/conn.go index afc75ced..4bd4bb9f 100644 --- a/pgxpool/conn.go +++ b/pgxpool/conn.go @@ -78,6 +78,10 @@ func (c *Conn) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, er return c.Conn().BeginTx(ctx, txOptions) } +func (c *Conn) Ping(ctx context.Context) error { + return c.Conn().Ping(ctx) +} + func (c *Conn) Conn() *pgx.Conn { return c.connResource().conn } diff --git a/pgxpool/pool.go b/pgxpool/pool.go index 503b8617..a036049b 100644 --- a/pgxpool/pool.go +++ b/pgxpool/pool.go @@ -492,3 +492,12 @@ func (p *Pool) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNam return c.Conn().CopyFrom(ctx, tableName, columnNames, rowSrc) } + +func (p *Pool) Ping(ctx context.Context) error { + c, err := p.Acquire(ctx) + if err != nil { + return err + } + defer c.Release() + return c.Ping(ctx) +}