From 4e231c3ff15d96b2ac967058a7429111a07656a3 Mon Sep 17 00:00:00 2001 From: Wes Burningham Date: Thu, 27 Jun 2024 10:52:09 -0600 Subject: [PATCH] fix: implement sql/driver.Pinger interface The `sql/driver.Pinger` interface is an optional interface to implement. For drivers that do implement the interface, the `Conn` type needs to try to call through. --- sqlhooks.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sqlhooks.go b/sqlhooks.go index 3d52576..527fe28 100644 --- a/sqlhooks.go +++ b/sqlhooks.go @@ -102,6 +102,13 @@ func (conn *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt func (conn *Conn) Prepare(query string) (driver.Stmt, error) { return conn.Conn.Prepare(query) } func (conn *Conn) Close() error { return conn.Conn.Close() } func (conn *Conn) Begin() (driver.Tx, error) { return conn.Conn.Begin() } +func (conn *Conn) Ping(ctx context.Context) error { + p, ok := conn.Conn.(driver.Pinger) + if !ok { + return driver.ErrSkip + } + return p.Ping(ctx) +} func (conn *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) { return conn.Conn.(driver.ConnBeginTx).BeginTx(ctx, opts) }