Add Ping method to pgxpool.Conn

Adds the Ping method to pgxpool.Conn, returning the result of calling Ping on
the underlying pgx.Conn.
This commit is contained in:
davidsbond 2021-01-25 17:09:07 +00:00 committed by Jack Christensen
parent 210a217818
commit aa8604b5c2
2 changed files with 13 additions and 0 deletions

View File

@ -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
}

View File

@ -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)
}