Skip to content

Commit

Permalink
Add Close ability to connection.DB (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
perrito666 authored Oct 17, 2023
1 parent f239b5c commit 8ce8fc2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions db/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions db/postgres/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions db/postgrespq/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8ce8fc2

Please sign in to comment.