Skip to content

Commit 8ce8fc2

Browse files
authored
Add Close ability to connection.DB (#66)
1 parent f239b5c commit 8ce8fc2

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

db/connection/connection.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ type ResultFetch func(interface{}) error
8181
type DB interface {
8282
// Clone returns a stateful copy of this connection.
8383
Clone() DB
84+
// Close does so for all the underlying connections and returns an error if the driver provides one.
85+
Close() error
8486
// QueryIter returns closure allowing to load/fetch roads one by one.
8587
QueryIter(ctx context.Context, statement string, fields []string, args ...interface{}) (ResultFetchIter, error)
8688
// EQueryIter is QueryIter but will use EscapeArgs.

db/postgres/connection.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ func (d *DB) Clone() connection.DB {
111111
}
112112
}
113113

114+
// Close closes the underlying connection, beware, this makes the DB useless.
115+
func (d *DB) Close() error {
116+
d.conn.Close()
117+
return nil
118+
}
119+
114120
// EQueryIter Calls EscapeArgs before invoking QueryIter
115121
func (d *DB) EQueryIter(ctx context.Context, statement string, fields []string, args ...interface{}) (connection.ResultFetchIter, error) {
116122
s, a, err := connection.EscapeArgs(statement, args)

db/postgrespq/connection.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ func (d *DB) Clone() connection.DB {
105105
}
106106
}
107107

108+
// Close closes the underlying connection, beware, this makes the DB useless.
109+
func (d *DB) Close() error {
110+
return d.conn.Close()
111+
}
112+
108113
// EQueryIter Calls EscapeArgs before invoking QueryIter
109114
func (d *DB) EQueryIter(ctx context.Context, statement string, fields []string, args ...interface{}) (connection.ResultFetchIter, error) {
110115
s, a, err := connection.EscapeArgs(statement, args)

0 commit comments

Comments
 (0)