Factor out *ConnectionPool createConnection

pgx-vs-pq
Jack Christensen 2013-07-25 07:36:58 -05:00
parent 7450854d50
commit 209a9dfaf5
1 changed files with 15 additions and 7 deletions

View File

@ -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()