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)
| 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. |
| 100 | func (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 | // |