mirror of https://github.com/jackc/pgx.git
Rename ConnectionParameters to ConnConfig
parent
4eb597d20b
commit
1ff653ae15
|
@ -21,4 +21,4 @@ _testmain.go
|
|||
|
||||
*.exe
|
||||
|
||||
connection_settings_test.go
|
||||
conn_config_test.go
|
||||
|
|
|
@ -99,7 +99,7 @@ if notification, err := conn.WaitForNotification(time.Second); err != nil {
|
|||
|
||||
### TLS
|
||||
|
||||
The pgx ConnectionParameters struct has a TLSConfig field. If this field is
|
||||
The pgx ConnConfig struct has a TLSConfig field. If this field is
|
||||
nil, then TLS will be disabled. If it is present, then it will be used to
|
||||
configure the TLS connection.
|
||||
|
||||
|
|
|
@ -636,7 +636,7 @@ func BenchmarkTimestampTzBinary(b *testing.B) {
|
|||
|
||||
func BenchmarkConnectionPool(b *testing.B) {
|
||||
options := pgx.ConnectionPoolOptions{MaxConnections: 5}
|
||||
pool, err := pgx.NewConnectionPool(*defaultConnectionParameters, options)
|
||||
pool, err := pgx.NewConnectionPool(*defaultConnConfig, options)
|
||||
if err != nil {
|
||||
b.Fatalf("Unable to create connection pool: %v", err)
|
||||
}
|
||||
|
|
82
conn.go
82
conn.go
|
@ -23,8 +23,8 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// ConnectionParameters contains all the options used to establish a connection.
|
||||
type ConnectionParameters struct {
|
||||
// ConnConfig contains all the options used to establish a connection.
|
||||
type ConnConfig struct {
|
||||
Socket string // path to unix domain socket directory (e.g. /private/tmp)
|
||||
Host string // url (e.g. localhost)
|
||||
Port uint16 // default: 5432
|
||||
|
@ -40,15 +40,15 @@ type ConnectionParameters struct {
|
|||
// Use ConnectionPool to manage access to multiple database connections from multiple
|
||||
// goroutines.
|
||||
type Conn struct {
|
||||
conn net.Conn // the underlying TCP or unix domain socket connection
|
||||
reader *bufio.Reader // buffered reader to improve read performance
|
||||
writer *bufio.Writer // buffered writer to avoid sending tiny packets
|
||||
buf *bytes.Buffer // work buffer to avoid constant alloc and dealloc
|
||||
bufSize int // desired size of buf
|
||||
Pid int32 // backend pid
|
||||
SecretKey int32 // key to use to send a cancel query message to the server
|
||||
RuntimeParams map[string]string // parameters that have been reported by the server
|
||||
parameters ConnectionParameters // parameters used when establishing this connection
|
||||
conn net.Conn // the underlying TCP or unix domain socket connection
|
||||
reader *bufio.Reader // buffered reader to improve read performance
|
||||
writer *bufio.Writer // buffered writer to avoid sending tiny packets
|
||||
buf *bytes.Buffer // work buffer to avoid constant alloc and dealloc
|
||||
bufSize int // desired size of buf
|
||||
Pid int32 // backend pid
|
||||
SecretKey int32 // key to use to send a cancel query message to the server
|
||||
RuntimeParams map[string]string // parameters that have been reported by the server
|
||||
config ConnConfig // config used when establishing this connection
|
||||
TxStatus byte
|
||||
preparedStatements map[string]*preparedStatement
|
||||
notifications []*Notification
|
||||
|
@ -98,42 +98,42 @@ func (e ProtocolError) Error() string {
|
|||
|
||||
var NotificationTimeoutError = errors.New("Notification Timeout")
|
||||
|
||||
// Connect establishes a connection with a PostgreSQL server using parameters. One
|
||||
// of parameters.Socket or parameters.Host must be specified. parameters.User
|
||||
// will default to the OS user name. Other parameters fields are optional.
|
||||
func Connect(parameters ConnectionParameters) (c *Conn, err error) {
|
||||
// Connect establishes a connection with a PostgreSQL server using config. One
|
||||
// of config.Socket or config.Host must be specified. config.User
|
||||
// will default to the OS user name. Other config fields are optional.
|
||||
func Connect(config ConnConfig) (c *Conn, err error) {
|
||||
c = new(Conn)
|
||||
|
||||
c.parameters = parameters
|
||||
if c.parameters.Logger != nil {
|
||||
c.logger = c.parameters.Logger
|
||||
c.config = config
|
||||
if c.config.Logger != nil {
|
||||
c.logger = c.config.Logger
|
||||
} else {
|
||||
c.logger = nullLogger("null")
|
||||
}
|
||||
|
||||
if c.parameters.User == "" {
|
||||
if c.config.User == "" {
|
||||
user, err := user.Current()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.logger.Debug("Using default User " + user.Username)
|
||||
c.parameters.User = user.Username
|
||||
c.config.User = user.Username
|
||||
}
|
||||
|
||||
if c.parameters.Port == 0 {
|
||||
if c.config.Port == 0 {
|
||||
c.logger.Debug("Using default Port")
|
||||
c.parameters.Port = 5432
|
||||
c.config.Port = 5432
|
||||
}
|
||||
if c.parameters.MsgBufSize == 0 {
|
||||
if c.config.MsgBufSize == 0 {
|
||||
c.logger.Debug("Using default MsgBufSize")
|
||||
c.parameters.MsgBufSize = 1024
|
||||
c.config.MsgBufSize = 1024
|
||||
}
|
||||
|
||||
if c.parameters.Socket != "" {
|
||||
if c.config.Socket != "" {
|
||||
// For backward compatibility accept socket file paths -- but directories are now preferred
|
||||
socket := c.parameters.Socket
|
||||
socket := c.config.Socket
|
||||
if !strings.Contains(socket, "/.s.PGSQL.") {
|
||||
socket = filepath.Join(socket, ".s.PGSQL.") + strconv.FormatInt(int64(c.parameters.Port), 10)
|
||||
socket = filepath.Join(socket, ".s.PGSQL.") + strconv.FormatInt(int64(c.config.Port), 10)
|
||||
}
|
||||
|
||||
c.logger.Info(fmt.Sprintf("Dialing PostgreSQL server at socket: %s", socket))
|
||||
|
@ -142,9 +142,9 @@ func Connect(parameters ConnectionParameters) (c *Conn, err error) {
|
|||
c.logger.Error(fmt.Sprintf("Connection failed: %v", err))
|
||||
return nil, err
|
||||
}
|
||||
} else if c.parameters.Host != "" {
|
||||
c.logger.Info(fmt.Sprintf("Dialing PostgreSQL server at host: %s:%d", c.parameters.Host, c.parameters.Port))
|
||||
c.conn, err = net.Dial("tcp", fmt.Sprintf("%s:%d", c.parameters.Host, c.parameters.Port))
|
||||
} else if c.config.Host != "" {
|
||||
c.logger.Info(fmt.Sprintf("Dialing PostgreSQL server at host: %s:%d", c.config.Host, c.config.Port))
|
||||
c.conn, err = net.Dial("tcp", fmt.Sprintf("%s:%d", c.config.Host, c.config.Port))
|
||||
if err != nil {
|
||||
c.logger.Error(fmt.Sprintf("Connection failed: %v", err))
|
||||
return nil, err
|
||||
|
@ -158,13 +158,13 @@ func Connect(parameters ConnectionParameters) (c *Conn, err error) {
|
|||
}
|
||||
}()
|
||||
|
||||
c.bufSize = c.parameters.MsgBufSize
|
||||
c.bufSize = c.config.MsgBufSize
|
||||
c.buf = bytes.NewBuffer(make([]byte, 0, c.bufSize))
|
||||
c.RuntimeParams = make(map[string]string)
|
||||
c.preparedStatements = make(map[string]*preparedStatement)
|
||||
c.alive = true
|
||||
|
||||
if parameters.TLSConfig != nil {
|
||||
if config.TLSConfig != nil {
|
||||
c.logger.Debug("Starting TLS handshake")
|
||||
if err = c.startTLS(); err != nil {
|
||||
c.logger.Error(fmt.Sprintf("TLS failed: %v", err))
|
||||
|
@ -176,9 +176,9 @@ func Connect(parameters ConnectionParameters) (c *Conn, err error) {
|
|||
c.writer = bufio.NewWriter(c.conn)
|
||||
|
||||
msg := newStartupMessage()
|
||||
msg.options["user"] = c.parameters.User
|
||||
if c.parameters.Database != "" {
|
||||
msg.options["database"] = c.parameters.Database
|
||||
msg.options["user"] = c.config.User
|
||||
if c.config.Database != "" {
|
||||
msg.options["database"] = c.config.Database
|
||||
}
|
||||
if err = c.txStartupMessage(msg); err != nil {
|
||||
return
|
||||
|
@ -218,9 +218,9 @@ func (c *Conn) Close() (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
// ParseURI parses a database URI into ConnectionParameters
|
||||
func ParseURI(uri string) (ConnectionParameters, error) {
|
||||
var cp ConnectionParameters
|
||||
// ParseURI parses a database URI into ConnConfig
|
||||
func ParseURI(uri string) (ConnConfig, error) {
|
||||
var cp ConnConfig
|
||||
|
||||
url, err := url.Parse(uri)
|
||||
if err != nil {
|
||||
|
@ -910,10 +910,10 @@ func (c *Conn) rxAuthenticationX(r *MessageReader) (err error) {
|
|||
switch code {
|
||||
case 0: // AuthenticationOk
|
||||
case 3: // AuthenticationCleartextPassword
|
||||
err = c.txPasswordMessage(c.parameters.Password)
|
||||
err = c.txPasswordMessage(c.config.Password)
|
||||
case 5: // AuthenticationMD5Password
|
||||
salt := r.ReadString(4)
|
||||
digestedPassword := "md5" + hexMD5(hexMD5(c.parameters.Password+c.parameters.User)+salt)
|
||||
digestedPassword := "md5" + hexMD5(hexMD5(c.config.Password+c.config.User)+salt)
|
||||
err = c.txPasswordMessage(digestedPassword)
|
||||
default:
|
||||
err = errors.New("Received unknown authentication message")
|
||||
|
@ -1024,7 +1024,7 @@ func (c *Conn) startTLS() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
c.conn = tls.Client(c.conn, c.parameters.TLSConfig)
|
||||
c.conn = tls.Client(c.conn, c.config.TLSConfig)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package pgx_test
|
||||
|
||||
import (
|
||||
"github.com/JackC/pgx"
|
||||
)
|
||||
|
||||
var defaultConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_md5", Password: "secret", Database: "pgx_test"}
|
||||
|
||||
// To skip tests for specific connection / authentication types set that connection param to nil
|
||||
var tcpConnConfig *pgx.ConnConfig = nil
|
||||
var unixSocketConnConfig *pgx.ConnConfig = nil
|
||||
var md5ConnConfig *pgx.ConnConfig = nil
|
||||
var plainPasswordConnConfig *pgx.ConnConfig = nil
|
||||
var noPasswordConnConfig *pgx.ConnConfig = nil
|
||||
var invalidUserConnConfig *pgx.ConnConfig = nil
|
||||
|
||||
// var tcpConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_md5", Password: "secret", Database: "pgx_test"}
|
||||
// var unixSocketConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Socket: "/private/tmp", User: "pgx_none", Database: "pgx_test"}
|
||||
// var md5ConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_md5", Password: "secret", Database: "pgx_test"}
|
||||
// var plainPasswordConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_pw", Password: "secret", Database: "pgx_test"}
|
||||
// var noPasswordConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "pgx_none", Database: "pgx_test"}
|
||||
// var invalidUserConnConfig *pgx.ConnConfig = &pgx.ConnConfig{Host: "127.0.0.1", User: "invalid", Database: "pgx_test"}
|
74
conn_test.go
74
conn_test.go
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func TestConnect(t *testing.T) {
|
||||
conn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
conn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
|
@ -30,12 +30,12 @@ func TestConnect(t *testing.T) {
|
|||
|
||||
var rows []map[string]interface{}
|
||||
rows, err = conn.SelectRows("select current_database()")
|
||||
if err != nil || rows[0]["current_database"] != defaultConnectionParameters.Database {
|
||||
t.Errorf("Did not connect to specified database (%v)", defaultConnectionParameters.Database)
|
||||
if err != nil || rows[0]["current_database"] != defaultConnConfig.Database {
|
||||
t.Errorf("Did not connect to specified database (%v)", defaultConnConfig.Database)
|
||||
}
|
||||
|
||||
if user := mustSelectValue(t, conn, "select current_user"); user != defaultConnectionParameters.User {
|
||||
t.Errorf("Did not connect as specified user (%v)", defaultConnectionParameters.User)
|
||||
if user := mustSelectValue(t, conn, "select current_user"); user != defaultConnConfig.User {
|
||||
t.Errorf("Did not connect as specified user (%v)", defaultConnConfig.User)
|
||||
}
|
||||
|
||||
err = conn.Close()
|
||||
|
@ -46,11 +46,11 @@ func TestConnect(t *testing.T) {
|
|||
|
||||
func TestConnectWithUnixSocketDirectory(t *testing.T) {
|
||||
// /.s.PGSQL.5432
|
||||
if unixSocketConnectionParameters == nil {
|
||||
if unixSocketConnConfig == nil {
|
||||
return
|
||||
}
|
||||
|
||||
conn, err := pgx.Connect(*unixSocketConnectionParameters)
|
||||
conn, err := pgx.Connect(*unixSocketConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
|
@ -62,11 +62,11 @@ func TestConnectWithUnixSocketDirectory(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConnectWithUnixSocketFile(t *testing.T) {
|
||||
if unixSocketConnectionParameters == nil {
|
||||
if unixSocketConnConfig == nil {
|
||||
return
|
||||
}
|
||||
|
||||
connParams := *unixSocketConnectionParameters
|
||||
connParams := *unixSocketConnConfig
|
||||
connParams.Socket = connParams.Socket + "/.s.PGSQL.5432"
|
||||
conn, err := pgx.Connect(connParams)
|
||||
if err != nil {
|
||||
|
@ -80,11 +80,11 @@ func TestConnectWithUnixSocketFile(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConnectWithTcp(t *testing.T) {
|
||||
if tcpConnectionParameters == nil {
|
||||
if tcpConnConfig == nil {
|
||||
return
|
||||
}
|
||||
|
||||
conn, err := pgx.Connect(*tcpConnectionParameters)
|
||||
conn, err := pgx.Connect(*tcpConnConfig)
|
||||
if err != nil {
|
||||
t.Fatal("Unable to establish connection: " + err.Error())
|
||||
}
|
||||
|
@ -96,11 +96,11 @@ func TestConnectWithTcp(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConnectWithTLS(t *testing.T) {
|
||||
if tlsConnectionParameters == nil {
|
||||
if tlsConnConfig == nil {
|
||||
return
|
||||
}
|
||||
|
||||
conn, err := pgx.Connect(*tlsConnectionParameters)
|
||||
conn, err := pgx.Connect(*tlsConnConfig)
|
||||
if err != nil {
|
||||
t.Fatal("Unable to establish connection: " + err.Error())
|
||||
}
|
||||
|
@ -112,11 +112,11 @@ func TestConnectWithTLS(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConnectWithInvalidUser(t *testing.T) {
|
||||
if invalidUserConnectionParameters == nil {
|
||||
if invalidUserConnConfig == nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err := pgx.Connect(*invalidUserConnectionParameters)
|
||||
_, err := pgx.Connect(*invalidUserConnConfig)
|
||||
pgErr, ok := err.(pgx.PgError)
|
||||
if !ok {
|
||||
t.Fatalf("Expected to receive a PgError with code 28000, instead received: %v", err)
|
||||
|
@ -127,11 +127,11 @@ func TestConnectWithInvalidUser(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConnectWithPlainTextPassword(t *testing.T) {
|
||||
if plainPasswordConnectionParameters == nil {
|
||||
if plainPasswordConnConfig == nil {
|
||||
return
|
||||
}
|
||||
|
||||
conn, err := pgx.Connect(*plainPasswordConnectionParameters)
|
||||
conn, err := pgx.Connect(*plainPasswordConnConfig)
|
||||
if err != nil {
|
||||
t.Fatal("Unable to establish connection: " + err.Error())
|
||||
}
|
||||
|
@ -143,11 +143,11 @@ func TestConnectWithPlainTextPassword(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConnectWithMD5Password(t *testing.T) {
|
||||
if md5ConnectionParameters == nil {
|
||||
if md5ConnConfig == nil {
|
||||
return
|
||||
}
|
||||
|
||||
conn, err := pgx.Connect(*md5ConnectionParameters)
|
||||
conn, err := pgx.Connect(*md5ConnConfig)
|
||||
if err != nil {
|
||||
t.Fatal("Unable to establish connection: " + err.Error())
|
||||
}
|
||||
|
@ -161,11 +161,11 @@ func TestConnectWithMD5Password(t *testing.T) {
|
|||
func TestParseURI(t *testing.T) {
|
||||
tests := []struct {
|
||||
url string
|
||||
connParams pgx.ConnectionParameters
|
||||
connParams pgx.ConnConfig
|
||||
}{
|
||||
{
|
||||
url: "postgres://jack:secret@localhost:5432/mydb",
|
||||
connParams: pgx.ConnectionParameters{
|
||||
connParams: pgx.ConnConfig{
|
||||
User: "jack",
|
||||
Password: "secret",
|
||||
Host: "localhost",
|
||||
|
@ -175,7 +175,7 @@ func TestParseURI(t *testing.T) {
|
|||
},
|
||||
{
|
||||
url: "postgresql://jack:secret@localhost:5432/mydb",
|
||||
connParams: pgx.ConnectionParameters{
|
||||
connParams: pgx.ConnConfig{
|
||||
User: "jack",
|
||||
Password: "secret",
|
||||
Host: "localhost",
|
||||
|
@ -185,7 +185,7 @@ func TestParseURI(t *testing.T) {
|
|||
},
|
||||
{
|
||||
url: "postgres://jack@localhost:5432/mydb",
|
||||
connParams: pgx.ConnectionParameters{
|
||||
connParams: pgx.ConnConfig{
|
||||
User: "jack",
|
||||
Host: "localhost",
|
||||
Port: 5432,
|
||||
|
@ -194,7 +194,7 @@ func TestParseURI(t *testing.T) {
|
|||
},
|
||||
{
|
||||
url: "postgres://jack@localhost/mydb",
|
||||
connParams: pgx.ConnectionParameters{
|
||||
connParams: pgx.ConnConfig{
|
||||
User: "jack",
|
||||
Host: "localhost",
|
||||
Database: "mydb",
|
||||
|
@ -243,7 +243,7 @@ func TestExecute(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestExecuteFailure(t *testing.T) {
|
||||
conn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
conn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ func TestSelectFunc(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSelectFuncFailure(t *testing.T) {
|
||||
conn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
conn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ func TestSelectFuncFailure(t *testing.T) {
|
|||
}
|
||||
|
||||
func Example_connectionSelectFunc() {
|
||||
conn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
conn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to establish connection: %v", err)
|
||||
return
|
||||
|
@ -344,7 +344,7 @@ func TestSelectRows(t *testing.T) {
|
|||
}
|
||||
|
||||
func Example_connectionSelectRows() {
|
||||
conn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
conn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to establish connection: %v", err)
|
||||
return
|
||||
|
@ -513,7 +513,7 @@ func TestSelectValues(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrepare(t *testing.T) {
|
||||
conn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
conn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
|
@ -594,7 +594,7 @@ func TestPrepare(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPrepareFailure(t *testing.T) {
|
||||
conn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
conn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
|
@ -610,7 +610,7 @@ func TestPrepareFailure(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTransaction(t *testing.T) {
|
||||
conn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
conn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
|
@ -721,7 +721,7 @@ func TestTransaction(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTransactionIso(t *testing.T) {
|
||||
conn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
conn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
|
@ -742,7 +742,7 @@ func TestTransactionIso(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestListenNotify(t *testing.T) {
|
||||
listener, err := pgx.Connect(*defaultConnectionParameters)
|
||||
listener, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
|
@ -796,7 +796,7 @@ func TestListenNotify(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFatalRxError(t *testing.T) {
|
||||
conn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
conn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
|
@ -812,7 +812,7 @@ func TestFatalRxError(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
otherConn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
otherConn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
|
@ -830,13 +830,13 @@ func TestFatalRxError(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFatalTxError(t *testing.T) {
|
||||
conn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
conn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
otherConn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
otherConn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ type ConnectionPool struct {
|
|||
allConnections []*Conn
|
||||
availableConnections []*Conn
|
||||
cond *sync.Cond
|
||||
parameters ConnectionParameters // parameters used when establishing connection
|
||||
config ConnConfig // config used when establishing connection
|
||||
maxConnections int
|
||||
afterConnect func(*Conn) error
|
||||
logger Logger
|
||||
|
@ -27,11 +27,11 @@ type ConnectionPoolStat struct {
|
|||
AvailableConnections int // unused live connections
|
||||
}
|
||||
|
||||
// NewConnectionPool creates a new ConnectionPool. parameters are passed through to
|
||||
// NewConnectionPool creates a new ConnectionPool. config are passed through to
|
||||
// Connect directly.
|
||||
func NewConnectionPool(parameters ConnectionParameters, options ConnectionPoolOptions) (p *ConnectionPool, err error) {
|
||||
func NewConnectionPool(config ConnConfig, options ConnectionPoolOptions) (p *ConnectionPool, err error) {
|
||||
p = new(ConnectionPool)
|
||||
p.parameters = parameters
|
||||
p.config = config
|
||||
p.maxConnections = options.MaxConnections
|
||||
p.afterConnect = options.AfterConnect
|
||||
if options.Logger != nil {
|
||||
|
@ -143,7 +143,7 @@ func (p *ConnectionPool) CurrentConnectionCount() int {
|
|||
}
|
||||
|
||||
func (p *ConnectionPool) createConnection() (c *Conn, err error) {
|
||||
c, err = Connect(p.parameters)
|
||||
c, err = Connect(p.config)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
func createConnectionPool(t *testing.T, maxConnections int) *pgx.ConnectionPool {
|
||||
options := pgx.ConnectionPoolOptions{MaxConnections: maxConnections}
|
||||
pool, err := pgx.NewConnectionPool(*defaultConnectionParameters, options)
|
||||
pool, err := pgx.NewConnectionPool(*defaultConnConfig, options)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create connection pool: %v", err)
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ func TestNewConnectionPool(t *testing.T) {
|
|||
}
|
||||
|
||||
options := pgx.ConnectionPoolOptions{MaxConnections: 2, AfterConnect: afterConnect}
|
||||
pool, err := pgx.NewConnectionPool(*defaultConnectionParameters, options)
|
||||
pool, err := pgx.NewConnectionPool(*defaultConnConfig, options)
|
||||
if err != nil {
|
||||
t.Fatal("Unable to establish connection pool")
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ func TestNewConnectionPool(t *testing.T) {
|
|||
}
|
||||
|
||||
options = pgx.ConnectionPoolOptions{MaxConnections: 2, AfterConnect: afterConnect}
|
||||
pool, err = pgx.NewConnectionPool(*defaultConnectionParameters, options)
|
||||
pool, err = pgx.NewConnectionPool(*defaultConnConfig, options)
|
||||
if err != errAfterConnect {
|
||||
t.Errorf("Expected errAfterConnect but received unexpected: %v", err)
|
||||
}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package pgx_test
|
||||
|
||||
import (
|
||||
"github.com/JackC/pgx"
|
||||
)
|
||||
|
||||
var defaultConnectionParameters *pgx.ConnectionParameters = &pgx.ConnectionParameters{Host: "127.0.0.1", User: "pgx_md5", Password: "secret", Database: "pgx_test"}
|
||||
|
||||
// To skip tests for specific connection / authentication types set that connection param to nil
|
||||
var tcpConnectionParameters *pgx.ConnectionParameters = nil
|
||||
var unixSocketConnectionParameters *pgx.ConnectionParameters = nil
|
||||
var md5ConnectionParameters *pgx.ConnectionParameters = nil
|
||||
var plainPasswordConnectionParameters *pgx.ConnectionParameters = nil
|
||||
var noPasswordConnectionParameters *pgx.ConnectionParameters = nil
|
||||
var invalidUserConnectionParameters *pgx.ConnectionParameters = nil
|
||||
|
||||
// var tcpConnectionParameters *pgx.ConnectionParameters = &pgx.ConnectionParameters{Host: "127.0.0.1", User: "pgx_md5", Password: "secret", Database: "pgx_test"}
|
||||
// var unixSocketConnectionParameters *pgx.ConnectionParameters = &pgx.ConnectionParameters{Socket: "/private/tmp", User: "pgx_none", Database: "pgx_test"}
|
||||
// var md5ConnectionParameters *pgx.ConnectionParameters = &pgx.ConnectionParameters{Host: "127.0.0.1", User: "pgx_md5", Password: "secret", Database: "pgx_test"}
|
||||
// var plainPasswordConnectionParameters *pgx.ConnectionParameters = &pgx.ConnectionParameters{Host: "127.0.0.1", User: "pgx_pw", Password: "secret", Database: "pgx_test"}
|
||||
// var noPasswordConnectionParameters *pgx.ConnectionParameters = &pgx.ConnectionParameters{Host: "127.0.0.1", User: "pgx_none", Database: "pgx_test"}
|
||||
// var invalidUserConnectionParameters *pgx.ConnectionParameters = &pgx.ConnectionParameters{Host: "127.0.0.1", User: "invalid", Database: "pgx_test"}
|
|
@ -23,7 +23,7 @@ func Example_customValueTranscoder() {
|
|||
DecodeText: decodePointFromText,
|
||||
EncodeTo: encodePoint}
|
||||
|
||||
conn, err := pgx.Connect(*defaultConnectionParameters)
|
||||
conn, err := pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to establish connection: %v", err)
|
||||
return
|
||||
|
|
|
@ -2,7 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jackc/pgx"
|
||||
"github.com/JackC/pgx"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -97,7 +97,7 @@ func urlHandler(w http.ResponseWriter, req *http.Request) {
|
|||
|
||||
func main() {
|
||||
var err error
|
||||
connectionOptions := pgx.ConnectionParameters{
|
||||
connectionOptions := pgx.ConnConfig{
|
||||
Host: "127.0.0.1",
|
||||
User: "jack",
|
||||
Password: "jack",
|
||||
|
|
|
@ -11,7 +11,7 @@ var sharedConnection *pgx.Conn
|
|||
func getSharedConnection(t testing.TB) (c *pgx.Conn) {
|
||||
if sharedConnection == nil || !sharedConnection.IsAlive() {
|
||||
var err error
|
||||
sharedConnection, err = pgx.Connect(*defaultConnectionParameters)
|
||||
sharedConnection, err = pgx.Connect(*defaultConnConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to establish connection: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue