mirror of https://github.com/jackc/pgx.git
Factor out *ConnectionPool createConnection
parent
7450854d50
commit
209a9dfaf5
|
@ -22,16 +22,10 @@ func NewConnectionPool(parameters ConnectionParameters, options ConnectionPoolOp
|
|||
|
||||
for i := 0; i < p.options.MaxConnections; i++ {
|
||||
var c *Connection
|
||||
c, err = Connect(p.parameters)
|
||||
c, err = p.createConnection()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if p.options.AfterConnect != nil {
|
||||
err = p.options.AfterConnect(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
p.connectionChannel <- c
|
||||
}
|
||||
|
||||
|
@ -60,6 +54,20 @@ func (p *ConnectionPool) Close() {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *ConnectionPool) createConnection() (c *Connection, err error) {
|
||||
c, err = Connect(p.parameters)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if p.options.AfterConnect != nil {
|
||||
err = p.options.AfterConnect(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// SelectFunc acquires a connection, delegates the call to that connection, and releases the connection
|
||||
func (p *ConnectionPool) SelectFunc(sql string, onDataRow func(*DataRowReader) error, arguments ...interface{}) (err error) {
|
||||
c := p.Acquire()
|
||||
|
|
Loading…
Reference in New Issue