fix postgresql connection leak (#2611)

This commit is contained in:
James
2017-04-04 20:37:44 -04:00
committed by Daniel Nelson
parent 8bf193dc06
commit 5ffc9fd379
5 changed files with 28 additions and 39 deletions

View File

@@ -1,15 +1,11 @@
package postgresql
import (
"database/sql"
"fmt"
"net"
"net/url"
"sort"
"strings"
"github.com/jackc/pgx"
"github.com/jackc/pgx/stdlib"
)
// pulled from lib/pq
@@ -79,21 +75,3 @@ func ParseURL(uri string) (string, error) {
sort.Strings(kvs) // Makes testing easier (not a performance concern)
return strings.Join(kvs, " "), nil
}
func Connect(address string) (*sql.DB, error) {
if strings.HasPrefix(address, "postgres://") || strings.HasPrefix(address, "postgresql://") {
return sql.Open("pgx", address)
}
config, err := pgx.ParseDSN(address)
if err != nil {
return nil, err
}
pool, err := pgx.NewConnPool(pgx.ConnPoolConfig{ConnConfig: config})
if err != nil {
return nil, err
}
return stdlib.OpenFromConnPool(pool)
}