mirror of https://github.com/jackc/pgx.git
ConnPoolConfig embeds ConnConfig
parent
9f50796f1b
commit
6d6fb4561a
|
@ -635,8 +635,8 @@ func BenchmarkTimestampTzBinary(b *testing.B) {
|
|||
}
|
||||
|
||||
func BenchmarkConnPool(b *testing.B) {
|
||||
options := pgx.ConnPoolConfig{MaxConnections: 5}
|
||||
pool, err := pgx.NewConnPool(*defaultConnConfig, options)
|
||||
config := pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: 5}
|
||||
pool, err := pgx.NewConnPool(config)
|
||||
if err != nil {
|
||||
b.Fatalf("Unable to create connection pool: %v", err)
|
||||
}
|
||||
|
|
16
conn_pool.go
16
conn_pool.go
|
@ -6,9 +6,9 @@ import (
|
|||
)
|
||||
|
||||
type ConnPoolConfig struct {
|
||||
ConnConfig
|
||||
MaxConnections int // max simultaneous connections to use
|
||||
AfterConnect func(*Conn) error
|
||||
Logger Logger
|
||||
}
|
||||
|
||||
type ConnPool struct {
|
||||
|
@ -27,15 +27,15 @@ type ConnPoolStat struct {
|
|||
AvailableConnections int // unused live connections
|
||||
}
|
||||
|
||||
// NewConnPool creates a new ConnPool. config are passed through to
|
||||
// NewConnPool creates a new ConnPool. config.ConnConfig is passed through to
|
||||
// Connect directly.
|
||||
func NewConnPool(config ConnConfig, options ConnPoolConfig) (p *ConnPool, err error) {
|
||||
func NewConnPool(config ConnPoolConfig) (p *ConnPool, err error) {
|
||||
p = new(ConnPool)
|
||||
p.config = config
|
||||
p.maxConnections = options.MaxConnections
|
||||
p.afterConnect = options.AfterConnect
|
||||
if options.Logger != nil {
|
||||
p.logger = options.Logger
|
||||
p.config = config.ConnConfig
|
||||
p.maxConnections = config.MaxConnections
|
||||
p.afterConnect = config.AfterConnect
|
||||
if config.Logger != nil {
|
||||
p.logger = config.Logger
|
||||
} else {
|
||||
p.logger = nullLogger("null")
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
)
|
||||
|
||||
func createConnPool(t *testing.T, maxConnections int) *pgx.ConnPool {
|
||||
options := pgx.ConnPoolConfig{MaxConnections: maxConnections}
|
||||
pool, err := pgx.NewConnPool(*defaultConnConfig, options)
|
||||
config := pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: maxConnections}
|
||||
pool, err := pgx.NewConnPool(config)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create connection pool: %v", err)
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ func TestNewConnPool(t *testing.T) {
|
|||
return nil
|
||||
}
|
||||
|
||||
options := pgx.ConnPoolConfig{MaxConnections: 2, AfterConnect: afterConnect}
|
||||
pool, err := pgx.NewConnPool(*defaultConnConfig, options)
|
||||
config := pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: 2, AfterConnect: afterConnect}
|
||||
pool, err := pgx.NewConnPool(config)
|
||||
if err != nil {
|
||||
t.Fatal("Unable to establish connection pool")
|
||||
}
|
||||
|
@ -43,8 +43,8 @@ func TestNewConnPool(t *testing.T) {
|
|||
return errAfterConnect
|
||||
}
|
||||
|
||||
options = pgx.ConnPoolConfig{MaxConnections: 2, AfterConnect: afterConnect}
|
||||
pool, err = pgx.NewConnPool(*defaultConnConfig, options)
|
||||
config = pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: 2, AfterConnect: afterConnect}
|
||||
pool, err = pgx.NewConnPool(config)
|
||||
if err != errAfterConnect {
|
||||
t.Errorf("Expected errAfterConnect but received unexpected: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue