Factor out *ConnectionPool createConnection
This commit is contained in:
+15
-7
@@ -22,16 +22,10 @@ func NewConnectionPool(parameters ConnectionParameters, options ConnectionPoolOp
|
|||||||
|
|
||||||
for i := 0; i < p.options.MaxConnections; i++ {
|
for i := 0; i < p.options.MaxConnections; i++ {
|
||||||
var c *Connection
|
var c *Connection
|
||||||
c, err = Connect(p.parameters)
|
c, err = p.createConnection()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if p.options.AfterConnect != nil {
|
|
||||||
err = p.options.AfterConnect(c)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p.connectionChannel <- c
|
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
|
// 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) {
|
func (p *ConnectionPool) SelectFunc(sql string, onDataRow func(*DataRowReader) error, arguments ...interface{}) (err error) {
|
||||||
c := p.Acquire()
|
c := p.Acquire()
|
||||||
|
|||||||
Reference in New Issue
Block a user