diff --git a/db/connection/connection.go b/db/connection/connection.go index 05b4e70..b31b095 100644 --- a/db/connection/connection.go +++ b/db/connection/connection.go @@ -81,6 +81,8 @@ type ResultFetch func(interface{}) error type DB interface { // Clone returns a stateful copy of this connection. Clone() DB + // Close does so for all the underlying connections and returns an error if the driver provides one. + Close() error // QueryIter returns closure allowing to load/fetch roads one by one. QueryIter(ctx context.Context, statement string, fields []string, args ...interface{}) (ResultFetchIter, error) // EQueryIter is QueryIter but will use EscapeArgs. diff --git a/db/postgres/connection.go b/db/postgres/connection.go index 8342b72..a280bb7 100644 --- a/db/postgres/connection.go +++ b/db/postgres/connection.go @@ -111,6 +111,12 @@ func (d *DB) Clone() connection.DB { } } +// Close closes the underlying connection, beware, this makes the DB useless. +func (d *DB) Close() error { + d.conn.Close() + return nil +} + // EQueryIter Calls EscapeArgs before invoking QueryIter func (d *DB) EQueryIter(ctx context.Context, statement string, fields []string, args ...interface{}) (connection.ResultFetchIter, error) { s, a, err := connection.EscapeArgs(statement, args) diff --git a/db/postgrespq/connection.go b/db/postgrespq/connection.go index 8f093c4..c6e2c0b 100644 --- a/db/postgrespq/connection.go +++ b/db/postgrespq/connection.go @@ -105,6 +105,11 @@ func (d *DB) Clone() connection.DB { } } +// Close closes the underlying connection, beware, this makes the DB useless. +func (d *DB) Close() error { + return d.conn.Close() +} + // EQueryIter Calls EscapeArgs before invoking QueryIter func (d *DB) EQueryIter(ctx context.Context, statement string, fields []string, args ...interface{}) (connection.ResultFetchIter, error) { s, a, err := connection.EscapeArgs(statement, args)