BeginTx adds an log-id for the transaction and calls the underlying driver BeginTx command if it is supported.
(ctx context.Context, opts *sql.TxOptions)
| 92 | |
| 93 | // BeginTx adds an log-id for the transaction and calls the underlying driver BeginTx command if it is supported. |
| 94 | func (d *DebugDriver) BeginTx(ctx context.Context, opts *sql.TxOptions) (dialect.Tx, error) { |
| 95 | drv, ok := d.Driver.(interface { |
| 96 | BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) |
| 97 | }) |
| 98 | if !ok { |
| 99 | return nil, fmt.Errorf("Driver.BeginTx is not supported") |
| 100 | } |
| 101 | tx, err := drv.BeginTx(ctx, opts) |
| 102 | if err != nil { |
| 103 | return nil, err |
| 104 | } |
| 105 | id := uuid.New().String() |
| 106 | d.log(ctx, fmt.Sprintf("driver.BeginTx(%s): started", id)) |
| 107 | return &DebugTx{tx, id, d.log, ctx}, nil |
| 108 | } |
| 109 | |
| 110 | // DebugTx is a transaction implementation that logs all transaction operations. |
| 111 | type DebugTx struct { |