Add Config.Copy() in pgx and pgxpool packages. Conn.Config() and Pool.Config() return copy of the original config.
This commit is contained in:
@@ -47,6 +47,16 @@ type ConnConfig struct {
|
||||
createdByParseConfig bool // Used to enforce created by ParseConfig rule.
|
||||
}
|
||||
|
||||
// Copy returns a deep copy of the config that is safe to use and modify.
|
||||
// The only exception is the tls.Config:
|
||||
// according to the tls.Config docs it must not be modified after creation.
|
||||
func (cc *ConnConfig) Copy() *ConnConfig {
|
||||
newConfig := new(ConnConfig)
|
||||
*newConfig = *cc
|
||||
newConfig.Config = *newConfig.Config.Copy()
|
||||
return newConfig
|
||||
}
|
||||
|
||||
func (cc *ConnConfig) ConnString() string { return cc.connString }
|
||||
|
||||
// BuildStatementCacheFunc is a function that can be used to create a stmtcache.Cache implementation for connection.
|
||||
@@ -425,8 +435,8 @@ 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 }
|
||||
|
||||
// Config returns config that was used to establish this connection.
|
||||
func (c *Conn) Config() *ConnConfig { return c.config }
|
||||
// Config returns a copy of config that was used to establish this connection.
|
||||
func (c *Conn) Config() *ConnConfig { return c.config.Copy() }
|
||||
|
||||
// Exec executes sql. sql can be either a prepared statement name or an SQL string. arguments should be referenced
|
||||
// positionally from the sql string as $1, $2, etc.
|
||||
|
||||
Reference in New Issue
Block a user