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

Method BeginTx

stdlib/sql.go:456–486  ·  view source on GitHub ↗
(ctx context.Context, opts driver.TxOptions)

Source from the content-addressed store, hash-verified

454}
455
456func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
457 if c.conn.IsClosed() {
458 return nil, driver.ErrBadConn
459 }
460
461 var pgxOpts pgx.TxOptions
462 switch sql.IsolationLevel(opts.Isolation) {
463 case sql.LevelDefault:
464 case sql.LevelReadUncommitted:
465 pgxOpts.IsoLevel = pgx.ReadUncommitted
466 case sql.LevelReadCommitted:
467 pgxOpts.IsoLevel = pgx.ReadCommitted
468 case sql.LevelRepeatableRead, sql.LevelSnapshot:
469 pgxOpts.IsoLevel = pgx.RepeatableRead
470 case sql.LevelSerializable:
471 pgxOpts.IsoLevel = pgx.Serializable
472 default:
473 return nil, fmt.Errorf("unsupported isolation: %v", opts.Isolation)
474 }
475
476 if opts.ReadOnly {
477 pgxOpts.AccessMode = pgx.ReadOnly
478 }
479
480 tx, err := c.conn.BeginTx(ctx, pgxOpts)
481 if err != nil {
482 return nil, err
483 }
484
485 return wrapTx{ctx: ctx, tx: tx}, nil
486}
487
488func (c *Conn) ExecContext(ctx context.Context, query string, argsV []driver.NamedValue) (driver.Result, error) {
489 if c.conn.IsClosed() {

Callers 4

BeginMethod · 0.95
TestConnBeginTxIsolationFunction · 0.45
TestConnBeginTxReadOnlyFunction · 0.45
TestBeginTxContextCancelFunction · 0.45

Calls 1

IsClosedMethod · 0.45

Tested by 3

TestConnBeginTxIsolationFunction · 0.36
TestConnBeginTxReadOnlyFunction · 0.36
TestBeginTxContextCancelFunction · 0.36