From 957d785a8333ca333e0b7f2c6b393ab6c3894b52 Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Thu, 7 Mar 2024 16:52:33 +0100 Subject: [PATCH] Implement the Close() method on our connector This allows a call to `db.Close()` to be effective at closing the underlying connections. --- db.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/db.go b/db.go index 6550b0a..2a4ac08 100644 --- a/db.go +++ b/db.go @@ -161,6 +161,17 @@ func (c *txConnector) Driver() driver.Driver { return c.driver } +// Close is called when [database/sql.DB.Close] is called, and the Close method +// on any opened connections. +func (c *txConnector) Close() error { + for _, conn := range c.driver.conns { + if err := conn.Close(); err != nil { + return err + } + } + return nil +} + func (d *TxDriver) DB() *sql.DB { return d.db }