Merge pull request #20 from lonre/pr18

Implements `io.Closer` for `DB`
new-query-chunks-api
Vinícius Garcia 2022-04-19 11:06:10 -03:00 committed by GitHub
commit d2ee98e038
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 0 deletions

View File

@ -38,6 +38,11 @@ func (s SQLAdapter) BeginTx(ctx context.Context) (ksql.Tx, error) {
return SQLTx{Tx: tx}, err return SQLTx{Tx: tx}, err
} }
// Close implements the io.Closer interface
func (s SQLAdapter) Close() error {
return s.DB.Close()
}
// SQLTx is used to implement the DBAdapter interface and implements // SQLTx is used to implement the DBAdapter interface and implements
// the Tx interface // the Tx interface
type SQLTx struct { type SQLTx struct {

View File

@ -42,6 +42,12 @@ func (p PGXAdapter) BeginTx(ctx context.Context) (ksql.Tx, error) {
return PGXTx{tx}, err return PGXTx{tx}, err
} }
// Close implements the io.Closer interface
func (p PGXAdapter) Close() error {
p.db.Close()
return nil
}
// PGXResult is used to implement the DBAdapter interface and implements // PGXResult is used to implement the DBAdapter interface and implements
// the Result interface // the Result interface
type PGXResult struct { type PGXResult struct {

View File

@ -38,6 +38,11 @@ func (s SQLAdapter) BeginTx(ctx context.Context) (ksql.Tx, error) {
return SQLTx{Tx: tx}, err return SQLTx{Tx: tx}, err
} }
// Close implements the io.Closer interface
func (s SQLAdapter) Close() error {
return s.DB.Close()
}
// SQLTx is used to implement the DBAdapter interface and implements // SQLTx is used to implement the DBAdapter interface and implements
// the Tx interface // the Tx interface
type SQLTx struct { type SQLTx struct {

View File

@ -38,6 +38,11 @@ func (s SQLAdapter) BeginTx(ctx context.Context) (ksql.Tx, error) {
return SQLTx{Tx: tx}, err return SQLTx{Tx: tx}, err
} }
// Close implements the io.Closer interface
func (s SQLAdapter) Close() error {
return s.DB.Close()
}
// SQLTx is used to implement the DBAdapter interface and implements // SQLTx is used to implement the DBAdapter interface and implements
// the Tx interface // the Tx interface
type SQLTx struct { type SQLTx struct {

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"io"
"reflect" "reflect"
"strings" "strings"
"unicode" "unicode"
@ -890,6 +891,14 @@ func (c DB) Transaction(ctx context.Context, fn func(Provider) error) error {
} }
} }
func (c DB) Close() error {
closer, ok := c.db.(io.Closer)
if ok {
return closer.Close()
}
return nil
}
type nopScanner struct{} type nopScanner struct{}
var nopScannerValue = reflect.ValueOf(&nopScanner{}).Interface() var nopScannerValue = reflect.ValueOf(&nopScanner{}).Interface()