Documentation
¶
Index ¶
- Constants
- type Conn
- func (c *Conn) Begin(ctx context.Context) (pgx.Tx, error)
- func (c *Conn) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
- func (c *Conn) Conn() *pgx.Conn
- func (c *Conn) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, ...) (int64, error)
- func (c *Conn) Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
- func (c *Conn) Hijack() *pgx.Conn
- func (c *Conn) Ping(ctx context.Context) error
- func (c *Conn) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
- func (c *Conn) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
- func (c *Conn) Release()
- func (c *Conn) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
- type Handle
- type LimitError
- type Options
- type Pool
- func (p *Pool) Close()
- func (p *Pool) Config() *pgxpool.Config
- func (p *Pool) ConnectionLimit() int64
- func (p *Pool) ForShared() Handle
- func (p *Pool) ForTenant(tenantID uuid.UUID) Handle
- func (p *Pool) SharedConnectionLimit() int64
- func (p *Pool) Stat() *pgxpool.Stat
- func (p *Pool) Unwrap() *pgxpool.Pool
Constants ¶
const RetryAfter = time.Second
RetryAfter is how long callers are told to wait before retrying a request that a LimitError rejected. It is a hint: the cap clears as soon as an in-flight checkout is released.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a pooled connection counted against a tenant. Hijack releases the tenant slot immediately, because a hijacked connection no longer occupies the pool. Release returns the connection and the slot.
func (*Conn) Begin ¶
Begin starts a transaction on the checked-out connection. The slot stays held until Release.
func (*Conn) BeginTx ¶
BeginTx starts a transaction with options on the checked-out connection. The slot stays held until Release.
func (*Conn) Conn ¶
Conn returns the underlying pgx connection. It stays owned by the pool and counted against the slot; use Hijack to take it over.
func (*Conn) CopyFrom ¶
func (c *Conn) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
CopyFrom bulk-loads rows over the checked-out connection.
func (*Conn) Hijack ¶
Hijack removes the connection from the pool and frees the tenant slot. The caller owns the returned connection.
func (*Conn) Query ¶
Query runs a query on the checked-out connection. The caller closes the rows; the slot stays held until Release.
type Handle ¶
type Handle interface {
Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
Begin(ctx context.Context) (pgx.Tx, error)
BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
Acquire(ctx context.Context) (*Conn, error)
Stat() *pgxpool.Stat
}
Handle is one tenant's checkout, or the shared checkout. sqlc accepts it anywhere it accepts a DBTX. sqlchelpers.Pool is the smaller begin-a-transaction view of a Handle.
type LimitError ¶
type LimitError struct {
// Key is the gate bucket. Tenants use the tenant id string; shared work uses "shared".
Key string
TenantID uuid.UUID
Limit int64
Waited time.Duration
}
LimitError is returned when a tenant or shared work waits MaxWait without a free slot.
func (*LimitError) Error ¶
func (e *LimitError) Error() string
type Options ¶
Options configures the connection caps.
MaxPercent is the share of the pool one tenant may have in flight. SharedMaxPercent is the same share for the bucket of engine work that is not tied to a tenant (ForShared and a nil tenant id). For both, a value from 1 to 99 installs a cap, and 100 (or 0, the zero value) installs none, so that bucket may hold the whole pool. NewWithConfig rejects values outside 0 to 100.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a pgx pool plus optional connection caps. ForTenant counts a checkout against a tenant and ForShared counts it against shared engine work. Each tenant has its own limit, and the shared bucket has a separate one. Ungated and Unwrap do not count.
func NewWithConfig ¶
NewWithConfig builds a pool from cfg. The tracer already set on cfg is left in place.
func Ungated ¶
Ungated returns a pool that does not cap connections. Tests and call sites that must not take a slot use this instead of ForTenant or ForShared.
func (*Pool) Close ¶
func (p *Pool) Close()
Close closes the underlying pool. It blocks until all checked-out connections are released.
func (*Pool) ConnectionLimit ¶
ConnectionLimit is how many checkouts one tenant may have in flight. Zero means tenants are ungated.
func (*Pool) ForShared ¶
ForShared returns the handle for engine work that is not tied to one tenant. It counts against the shared limit, not a tenant's. A pool with no shared gate returns a handle that does not count.
func (*Pool) ForTenant ¶
ForTenant returns a handle that counts acquires against tenantID. A nil id counts against the shared bucket. A pool with no gate returns a handle that does not count.
func (*Pool) SharedConnectionLimit ¶
SharedConnectionLimit is how many checkouts the shared bucket may have in flight. Zero means the shared bucket is ungated.