package pgxpool
import (
)
type Conn struct {
res *puddle.Resource[*connResource]
p *Pool
}
func ( *Conn) () {
if .res == nil {
return
}
:= .Conn()
:= .res
.res = nil
if .p.releaseTracer != nil {
.p.releaseTracer.TraceRelease(.p, TraceReleaseData{Conn: })
}
if .IsClosed() || .PgConn().IsBusy() || .PgConn().TxStatus() != 'I' {
.Destroy()
.p.triggerHealthCheck()
return
}
if .p.isExpired() {
atomic.AddInt64(&.p.lifetimeDestroyCount, 1)
.Destroy()
.p.triggerHealthCheck()
return
}
if .p.afterRelease == nil {
.Release()
return
}
go func() {
if .p.afterRelease() {
.Release()
} else {
.Destroy()
.p.triggerHealthCheck()
}
}()
}
func ( *Conn) () *pgx.Conn {
if .res == nil {
panic("cannot hijack already released or hijacked connection")
}
:= .Conn()
:= .res
.res = nil
.Hijack()
return
}
func ( *Conn) ( context.Context, string, ...any) (pgconn.CommandTag, error) {
return .Conn().Exec(, , ...)
}
func ( *Conn) ( context.Context, string, ...any) (pgx.Rows, error) {
return .Conn().Query(, , ...)
}
func ( *Conn) ( context.Context, string, ...any) pgx.Row {
return .Conn().QueryRow(, , ...)
}
func ( *Conn) ( context.Context, *pgx.Batch) pgx.BatchResults {
return .Conn().SendBatch(, )
}
func ( *Conn) ( context.Context, pgx.Identifier, []string, pgx.CopyFromSource) (int64, error) {
return .Conn().CopyFrom(, , , )
}
func ( *Conn) ( context.Context) (pgx.Tx, error) {
return .Conn().Begin()
}
func ( *Conn) ( context.Context, pgx.TxOptions) (pgx.Tx, error) {
return .Conn().BeginTx(, )
}
func ( *Conn) ( context.Context) error {
return .Conn().Ping()
}
func ( *Conn) () *pgx.Conn {
return .connResource().conn
}
func ( *Conn) () *connResource {
return .res.Value()
}
func ( *Conn) ( pgx.Row) *poolRow {
return .connResource().getPoolRow(, )
}
func ( *Conn) ( pgx.Rows) *poolRows {
return .connResource().getPoolRows(, )
}