@@ -208,6 +208,74 @@ func (db *DB) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
208208 return & Tx {Tx : tx , driverName : db .driverName , unsafe : db .unsafe , Mapper : db .Mapper }, err
209209}
210210
211+ // Connx returns an *sqlx.Conn instead of an *sql.Conn.
212+ func (db * DB ) Connx (ctx context.Context ) (* Conn , error ) {
213+ conn , err := db .DB .Conn (ctx )
214+ if err != nil {
215+ return nil , err
216+ }
217+
218+ return & Conn {Conn : conn , driverName : db .driverName , unsafe : db .unsafe , Mapper : db .Mapper }, nil
219+ }
220+
221+ // BeginTxx begins a transaction and returns an *sqlx.Tx instead of an
222+ // *sql.Tx.
223+ //
224+ // The provided context is used until the transaction is committed or rolled
225+ // back. If the context is canceled, the sql package will roll back the
226+ // transaction. Tx.Commit will return an error if the context provided to
227+ // BeginxContext is canceled.
228+ func (c * Conn ) BeginTxx (ctx context.Context , opts * sql.TxOptions ) (* Tx , error ) {
229+ tx , err := c .Conn .BeginTx (ctx , opts )
230+ if err != nil {
231+ return nil , err
232+ }
233+ return & Tx {Tx : tx , driverName : c .driverName , unsafe : c .unsafe , Mapper : c .Mapper }, err
234+ }
235+
236+ // SelectContext using this Conn.
237+ // Any placeholder parameters are replaced with supplied args.
238+ func (c * Conn ) SelectContext (ctx context.Context , dest interface {}, query string , args ... interface {}) error {
239+ return SelectContext (ctx , c , dest , query , args ... )
240+ }
241+
242+ // GetContext using this Conn.
243+ // Any placeholder parameters are replaced with supplied args.
244+ // An error is returned if the result set is empty.
245+ func (c * Conn ) GetContext (ctx context.Context , dest interface {}, query string , args ... interface {}) error {
246+ return GetContext (ctx , c , dest , query , args ... )
247+ }
248+
249+ // PreparexContext returns an sqlx.Stmt instead of a sql.Stmt.
250+ //
251+ // The provided context is used for the preparation of the statement, not for
252+ // the execution of the statement.
253+ func (c * Conn ) PreparexContext (ctx context.Context , query string ) (* Stmt , error ) {
254+ return PreparexContext (ctx , c , query )
255+ }
256+
257+ // QueryxContext queries the database and returns an *sqlx.Rows.
258+ // Any placeholder parameters are replaced with supplied args.
259+ func (c * Conn ) QueryxContext (ctx context.Context , query string , args ... interface {}) (* Rows , error ) {
260+ r , err := c .Conn .QueryContext (ctx , query , args ... )
261+ if err != nil {
262+ return nil , err
263+ }
264+ return & Rows {Rows : r , unsafe : c .unsafe , Mapper : c .Mapper }, err
265+ }
266+
267+ // QueryRowxContext queries the database and returns an *sqlx.Row.
268+ // Any placeholder parameters are replaced with supplied args.
269+ func (c * Conn ) QueryRowxContext (ctx context.Context , query string , args ... interface {}) * Row {
270+ rows , err := c .Conn .QueryContext (ctx , query , args ... )
271+ return & Row {rows : rows , err : err , unsafe : c .unsafe , Mapper : c .Mapper }
272+ }
273+
274+ // Rebind a query within a Conn's bindvar type.
275+ func (c * Conn ) Rebind (query string ) string {
276+ return Rebind (BindType (c .driverName ), query )
277+ }
278+
211279// StmtxContext returns a version of the prepared statement which runs within a
212280// transaction. Provided stmt can be either *sql.Stmt or *sqlx.Stmt.
213281func (tx * Tx ) StmtxContext (ctx context.Context , stmt interface {}) * Stmt {
0 commit comments