mirror of https://github.com/jackc/pgx.git
parent
a47e836471
commit
255f16b00f
|
@ -66,6 +66,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -85,7 +86,13 @@ func init() {
|
||||||
pgxDriver = &Driver{
|
pgxDriver = &Driver{
|
||||||
configs: make(map[string]*pgx.ConnConfig),
|
configs: make(map[string]*pgx.ConnConfig),
|
||||||
}
|
}
|
||||||
sql.Register("pgx", pgxDriver)
|
|
||||||
|
drivers := sql.Drivers()
|
||||||
|
// if pgx driver was already registered by different pgx major version then we skip registration under the default name.
|
||||||
|
if i := sort.SearchStrings(sql.Drivers(), "pgx"); len(drivers) >= i || drivers[i] != "pgx" {
|
||||||
|
sql.Register("pgx", pgxDriver)
|
||||||
|
}
|
||||||
|
sql.Register("pgx/v5", pgxDriver)
|
||||||
|
|
||||||
databaseSQLResultFormats = pgx.QueryResultFormatsByOID{
|
databaseSQLResultFormats = pgx.QueryResultFormatsByOID{
|
||||||
pgtype.BoolOID: 1,
|
pgtype.BoolOID: 1,
|
||||||
|
|
|
@ -146,9 +146,22 @@ func closeStmt(t *testing.T, stmt *sql.Stmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSQLOpen(t *testing.T) {
|
func TestSQLOpen(t *testing.T) {
|
||||||
db, err := sql.Open("pgx", os.Getenv("PGX_TEST_DATABASE"))
|
tests := []struct {
|
||||||
require.NoError(t, err)
|
driverName string
|
||||||
closeDB(t, db)
|
}{
|
||||||
|
{driverName: "pgx"},
|
||||||
|
{driverName: "pgx/v5"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
tt := tt
|
||||||
|
|
||||||
|
t.Run(tt.driverName, func(t *testing.T) {
|
||||||
|
db, err := sql.Open(tt.driverName, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
closeDB(t, db)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNormalLifeCycle(t *testing.T) {
|
func TestNormalLifeCycle(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue