Skip to content

Commit

Permalink
Implement the Close() method on our connector
Browse files Browse the repository at this point in the history
This allows a call to `db.Close()` to be effective at closing the underlying
connections.
  • Loading branch information
flimzy committed Mar 7, 2024
1 parent 559e65b commit 957d785
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 957d785

Please sign in to comment.