@@ -253,6 +253,37 @@ func SelectWithArray(ctx context.Context, db Executor, results interface{}, toAr
253
253
}, sql string , values ... interface {}) error {
254
254
return QueryWithArray (ctx , db , nil , results , toArray , sql , values ... )
255
255
}
256
+ func QueryTx (ctx context.Context , tx * sql.Tx , fieldsIndex map [string ]int , results interface {}, sql string , values ... interface {}) error {
257
+ return QueryTxWithArray (ctx , tx , fieldsIndex , results , nil , sql , values ... )
258
+ }
259
+ func QueryTxWithArray (ctx context.Context , tx * sql.Tx , fieldsIndex map [string ]int , results interface {}, toArray func (interface {}) interface {
260
+ driver.Valuer
261
+ sql.Scanner
262
+ }, sql string , values ... interface {}) error {
263
+ rows , er1 := tx .QueryContext (ctx , sql , values ... )
264
+ if er1 != nil {
265
+ return er1
266
+ }
267
+ defer rows .Close ()
268
+
269
+ modelType := reflect .TypeOf (results ).Elem ().Elem ()
270
+ tb , er3 := Scan (rows , modelType , fieldsIndex , toArray )
271
+ if er3 != nil {
272
+ return er3
273
+ }
274
+ for _ , element := range tb {
275
+ appendToArray (results , element )
276
+ }
277
+ er4 := rows .Close ()
278
+ if er4 != nil {
279
+ return er4
280
+ }
281
+ // Rows.Err will report the last error encountered by Rows.Scan.
282
+ if er5 := rows .Err (); er5 != nil {
283
+ return er5
284
+ }
285
+ return nil
286
+ }
256
287
func QueryAndCount (ctx context.Context , db Executor , fieldsIndex map [string ]int , results interface {}, toArray func (interface {}) interface {
257
288
driver.Valuer
258
289
sql.Scanner
0 commit comments