StmtxContext returns a version of the prepared statement which runs within a transaction. Provided stmt can be either *sql.Stmt or *sqlx.Stmt.
(ctx context.Context, stmt interface{})
| 280 | // StmtxContext returns a version of the prepared statement which runs within a |
| 281 | // transaction. Provided stmt can be either *sql.Stmt or *sqlx.Stmt. |
| 282 | func (tx *Tx) StmtxContext(ctx context.Context, stmt interface{}) *Stmt { |
| 283 | var s *sql.Stmt |
| 284 | switch v := stmt.(type) { |
| 285 | case Stmt: |
| 286 | s = v.Stmt |
| 287 | case *Stmt: |
| 288 | s = v.Stmt |
| 289 | case *sql.Stmt: |
| 290 | s = v |
| 291 | default: |
| 292 | panic(fmt.Sprintf("non-statement type %v passed to Stmtx", reflect.ValueOf(stmt).Type())) |
| 293 | } |
| 294 | return &Stmt{Stmt: tx.StmtContext(ctx, s), Mapper: tx.Mapper} |
| 295 | } |
| 296 | |
| 297 | // NamedStmtContext returns a version of the prepared statement which runs |
| 298 | // within a transaction. |