@@ -124,10 +124,10 @@ func QueryMap(ctx context.Context, db *sql.DB, transform func(s string) string,
124
124
}
125
125
return res , nil
126
126
}
127
- func Query (ctx context.Context , db * sql. DB , fieldsIndex map [string ]int , results interface {}, sql string , values ... interface {}) error {
127
+ func Query (ctx context.Context , db Executor , fieldsIndex map [string ]int , results interface {}, sql string , values ... interface {}) error {
128
128
return QueryWithArray (ctx , db , fieldsIndex , results , nil , sql , values ... )
129
129
}
130
- func ExecContext (ctx context.Context , db * sql. DB , query string , args ... interface {}) (sql.Result , error ){
130
+ func ExecContext (ctx context.Context , db Executor , query string , args ... interface {}) (sql.Result , error ){
131
131
tx := GetTx (ctx )
132
132
if tx != nil {
133
133
return tx .ExecContext (ctx , query , args ... )
@@ -204,7 +204,7 @@ func QueryContextWithArray(ctx context.Context, db *sql.DB, fieldsIndex map[stri
204
204
}
205
205
return nil
206
206
}
207
- func QueryWithArray (ctx context.Context , db * sql. DB , fieldsIndex map [string ]int , results interface {}, toArray func (interface {}) interface {
207
+ func QueryWithArray (ctx context.Context , db Executor , fieldsIndex map [string ]int , results interface {}, toArray func (interface {}) interface {
208
208
driver.Valuer
209
209
sql.Scanner
210
210
}, sql string , values ... interface {}) error {
@@ -231,10 +231,10 @@ func QueryWithArray(ctx context.Context, db *sql.DB, fieldsIndex map[string]int,
231
231
}
232
232
return nil
233
233
}
234
- func QueryWithMap (ctx context.Context , db * sql. DB , results interface {}, sql string , values []interface {}, options ... map [string ]int ) error {
234
+ func QueryWithMap (ctx context.Context , db Executor , results interface {}, sql string , values []interface {}, options ... map [string ]int ) error {
235
235
return QueryWithMapAndArray (ctx , db , results , nil , sql , values , options ... )
236
236
}
237
- func QueryWithMapAndArray (ctx context.Context , db * sql. DB , results interface {}, toArray func (interface {}) interface {
237
+ func QueryWithMapAndArray (ctx context.Context , db Executor , results interface {}, toArray func (interface {}) interface {
238
238
driver.Valuer
239
239
sql.Scanner
240
240
}, sql string , values []interface {}, options ... map [string ]int ) error {
@@ -244,75 +244,16 @@ func QueryWithMapAndArray(ctx context.Context, db *sql.DB, results interface{},
244
244
}
245
245
return QueryWithArray (ctx , db , fieldsIndex , results , toArray , sql , values ... )
246
246
}
247
- func Select (ctx context.Context , db * sql. DB , results interface {}, sql string , values ... interface {}) error {
247
+ func Select (ctx context.Context , db Executor , results interface {}, sql string , values ... interface {}) error {
248
248
return SelectWithArray (ctx , db , results , nil , sql , values ... )
249
249
}
250
- func SelectWithArray (ctx context.Context , db * sql. DB , results interface {}, toArray func (interface {}) interface {
250
+ func SelectWithArray (ctx context.Context , db Executor , results interface {}, toArray func (interface {}) interface {
251
251
driver.Valuer
252
252
sql.Scanner
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
- }
287
- func QueryByStatement (ctx context.Context , stm * sql.Stmt , fieldsIndex map [string ]int , results interface {}, toArray func (interface {}) interface {
288
- driver.Valuer
289
- sql.Scanner
290
- }, values ... interface {}) error {
291
- rows , er1 := stm .QueryContext (ctx , values ... )
292
- if er1 != nil {
293
- return er1
294
- }
295
- defer rows .Close ()
296
-
297
- modelType := reflect .TypeOf (results ).Elem ().Elem ()
298
- tb , er3 := Scan (rows , modelType , fieldsIndex , toArray )
299
- if er3 != nil {
300
- return er3
301
- }
302
- for _ , element := range tb {
303
- appendToArray (results , element )
304
- }
305
- er4 := rows .Close ()
306
- if er4 != nil {
307
- return er4
308
- }
309
- // Rows.Err will report the last error encountered by Rows.Scan.
310
- if er5 := rows .Err (); er5 != nil {
311
- return er5
312
- }
313
- return nil
314
- }
315
- func QueryAndCount (ctx context.Context , db * sql.DB , fieldsIndex map [string ]int , results interface {}, toArray func (interface {}) interface {
256
+ func QueryAndCount (ctx context.Context , db Executor , fieldsIndex map [string ]int , results interface {}, toArray func (interface {}) interface {
316
257
driver.Valuer
317
258
sql.Scanner
318
259
}, count * int64 , sql string , values ... interface {}) error {
0 commit comments