mirror of
https://github.com/jackc/pgx.git
synced 2025-04-27 13:14:32 +00:00
DRY ConnPool Begin and BeginIso
This commit is contained in:
parent
6ac98ef613
commit
bc4742b80a
20
conn_pool.go
20
conn_pool.go
@ -214,25 +214,7 @@ func (p *ConnPool) QueryRow(sql string, args ...interface{}) *Row {
|
|||||||
// Begin acquires a connection and begins a transaction on it. When the
|
// Begin acquires a connection and begins a transaction on it. When the
|
||||||
// transaction is closed the connection will be automatically released.
|
// transaction is closed the connection will be automatically released.
|
||||||
func (p *ConnPool) Begin() (*Tx, error) {
|
func (p *ConnPool) Begin() (*Tx, error) {
|
||||||
for {
|
return p.BeginIso("")
|
||||||
c, err := p.Acquire()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
tx, err := c.Begin()
|
|
||||||
if err == ErrDeadConn {
|
|
||||||
p.Release(c)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
p.Release(c)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
tx.pool = p
|
|
||||||
return tx, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BeginIso acquires a connection and begins a transaction in isolation mode iso
|
// BeginIso acquires a connection and begins a transaction in isolation mode iso
|
||||||
|
Loading…
x
Reference in New Issue
Block a user