MCPcopy
hub / github.com/jackc/pgx / BeginTx

Method BeginTx

pgxpool/pool.go:806–819  ·  view source on GitHub ↗

BeginTx acquires a connection from the [Pool] and starts a transaction with [pgx.TxOptions] determining the transaction mode. Unlike [database/sql], the context only affects the begin command. i.e. there is no auto-rollback on context cancellation. [*Tx] is returned, which implements the [pgx.Tx] in

(ctx context.Context, txOptions pgx.TxOptions)

Source from the content-addressed store, hash-verified

804// [*Tx] is returned, which implements the [pgx.Tx] interface.
805// [Tx.Commit] or [Tx.Rollback] must be called on the returned transaction to finalize the transaction block.
806func (p *Pool) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error) {
807 c, err := p.Acquire(ctx)
808 if err != nil {
809 return nil, err
810 }
811
812 t, err := c.BeginTx(ctx, txOptions)
813 if err != nil {
814 c.Release()
815 return nil, err
816 }
817
818 return &Tx{t: t, c: c}, nil
819}
820
821func (p *Pool) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error) {
822 c, err := p.Acquire(ctx)

Callers 1

BeginMethod · 0.95

Calls 2

AcquireMethod · 0.95
ReleaseMethod · 0.80

Tested by

no test coverage detected