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

Method BeginTx

tx.go:100–113  ·  tx.go::Conn.BeginTx

BeginTx starts a transaction with 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.

(ctx context.Context, txOptions TxOptions)

Source from the content-addressed store, hash-verified

98// BeginTx starts a transaction with txOptions determining the transaction mode. Unlike [database/sql], the context only
99// affects the begin command. i.e. there is no auto-rollback on context cancellation.
100func (c *Conn) BeginTx(ctx context.Context, txOptions TxOptions) (Tx, error) {
101 _, err := c.Exec(ctx, txOptions.beginSQL())
102 if err != nil {
103 // begin should never fail unless there is an underlying connection issue or
104 // a context timeout. In either case, the connection is possibly broken.
105 c.die()
106 return nil, err
107 }
108
109 return &dbTx{
110 conn: c,
111 commitQuery: txOptions.CommitQuery,
112 }, nil
113}
114
115// Tx represents a database transaction.
116//

Callers 6

BeginMethod · 0.95
BeginTxFuncFunction · 0.45
TestBeginIsoLevelsFunction · 0.45
TestBeginReadOnlyFunction · 0.45
TestBeginTxBeginQueryFunction · 0.45

Calls 3

ExecMethod · 0.95
dieMethod · 0.95
beginSQLMethod · 0.80

Tested by 4

TestBeginIsoLevelsFunction · 0.36
TestBeginReadOnlyFunction · 0.36
TestBeginTxBeginQueryFunction · 0.36