mirror of https://github.com/jackc/pgx.git
Require access to ConnString via Config
A Config object may be created via ParseConfig and then further modified. Requiring access to the original ConnString via the Config helps indicate that the Config is the source of truth as to how the connection was actually established.pull/757/head
parent
59a2185dfb
commit
ac6c49c39d
3
conn.go
3
conn.go
|
@ -424,9 +424,6 @@ func (c *Conn) StatementCache() stmtcache.Cache { return c.stmtcache }
|
|||
// ConnInfo returns the connection info used for this connection.
|
||||
func (c *Conn) ConnInfo() *pgtype.ConnInfo { return c.connInfo }
|
||||
|
||||
// ConnString returns the connection string that was used to establish this connection.
|
||||
func (c *Conn) ConnString() string { return c.config.ConnString() }
|
||||
|
||||
// Config returns config that was used to establish this connection.
|
||||
func (c *Conn) Config() *ConnConfig { return c.config }
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ func TestCrateDBConnect(t *testing.T) {
|
|||
defer closeConn(t, conn)
|
||||
|
||||
assert.Equal(t, connString, conn.Config().ConnString())
|
||||
assert.Equal(t, connString, conn.ConnString())
|
||||
|
||||
var result int
|
||||
err = conn.QueryRow(context.Background(), "select 1 +1").Scan(&result)
|
||||
|
@ -53,7 +52,6 @@ func TestConnect(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.Equal(t, connString, conn.Config().ConnString())
|
||||
assert.Equal(t, connString, conn.ConnString())
|
||||
|
||||
var currentDB string
|
||||
err = conn.QueryRow(context.Background(), "select current_database()").Scan(¤tDB)
|
||||
|
|
|
@ -121,6 +121,8 @@ type Config struct {
|
|||
createdByParseConfig bool // Used to enforce created by ParseConfig rule.
|
||||
}
|
||||
|
||||
func (c *Config) ConnString() string { return c.ConnConfig.ConnString() }
|
||||
|
||||
// Connect creates a new Pool and immediately establishes one connection. ctx can be used to cancel this initial
|
||||
// connection. See ParseConfig for information on connString format.
|
||||
func Connect(ctx context.Context, connString string) (*Pool, error) {
|
||||
|
@ -371,9 +373,6 @@ func (p *Pool) AcquireAllIdle(ctx context.Context) []*Conn {
|
|||
return conns
|
||||
}
|
||||
|
||||
// ConnString returns the connection string that was used to initialize this pool.
|
||||
func (p *Pool) ConnString() string { return p.config.ConnConfig.ConnString() }
|
||||
|
||||
// Config returns config that was used to initialize this pool.
|
||||
func (p *Pool) Config() *Config { return p.config }
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ func TestConnect(t *testing.T) {
|
|||
connString := os.Getenv("PGX_TEST_DATABASE")
|
||||
pool, err := pgxpool.Connect(context.Background(), connString)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, connString, pool.ConnString())
|
||||
assert.Equal(t, connString, pool.Config().ConnString())
|
||||
pool.Close()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue