@@ -39,7 +39,7 @@ func (n *NamedStmt) Close() error {
39
39
40
40
// Exec executes a named statement using the struct passed.
41
41
// Any named placeholder parameters are replaced with fields from arg.
42
- func (n * NamedStmt ) Exec (arg interface {} ) (sql.Result , error ) {
42
+ func (n * NamedStmt ) Exec (arg any ) (sql.Result , error ) {
43
43
args , err := bindAnyArgs (n .Params , arg , n .Stmt .Mapper )
44
44
if err != nil {
45
45
return * new (sql.Result ), err
@@ -49,7 +49,7 @@ func (n *NamedStmt) Exec(arg interface{}) (sql.Result, error) {
49
49
50
50
// Query executes a named statement using the struct argument, returning rows.
51
51
// Any named placeholder parameters are replaced with fields from arg.
52
- func (n * NamedStmt ) Query (arg interface {} ) (* sql.Rows , error ) {
52
+ func (n * NamedStmt ) Query (arg any ) (* sql.Rows , error ) {
53
53
args , err := bindAnyArgs (n .Params , arg , n .Stmt .Mapper )
54
54
if err != nil {
55
55
return nil , err
@@ -61,7 +61,7 @@ func (n *NamedStmt) Query(arg interface{}) (*sql.Rows, error) {
61
61
// create a *sql.Row with an error condition pre-set for binding errors, sqlx
62
62
// returns a *sqlx.Row instead.
63
63
// Any named placeholder parameters are replaced with fields from arg.
64
- func (n * NamedStmt ) QueryRow (arg interface {} ) * Row {
64
+ func (n * NamedStmt ) QueryRow (arg any ) * Row {
65
65
args , err := bindAnyArgs (n .Params , arg , n .Stmt .Mapper )
66
66
if err != nil {
67
67
return & Row {err : err }
@@ -71,7 +71,7 @@ func (n *NamedStmt) QueryRow(arg interface{}) *Row {
71
71
72
72
// MustExec execs a NamedStmt, panicing on error
73
73
// Any named placeholder parameters are replaced with fields from arg.
74
- func (n * NamedStmt ) MustExec (arg interface {} ) sql.Result {
74
+ func (n * NamedStmt ) MustExec (arg any ) sql.Result {
75
75
res , err := n .Exec (arg )
76
76
if err != nil {
77
77
panic (err )
@@ -81,7 +81,7 @@ func (n *NamedStmt) MustExec(arg interface{}) sql.Result {
81
81
82
82
// Queryx using this NamedStmt
83
83
// Any named placeholder parameters are replaced with fields from arg.
84
- func (n * NamedStmt ) Queryx (arg interface {} ) (* Rows , error ) {
84
+ func (n * NamedStmt ) Queryx (arg any ) (* Rows , error ) {
85
85
r , err := n .Query (arg )
86
86
if err != nil {
87
87
return nil , err
@@ -92,13 +92,13 @@ func (n *NamedStmt) Queryx(arg interface{}) (*Rows, error) {
92
92
// QueryRowx this NamedStmt. Because of limitations with QueryRow, this is
93
93
// an alias for QueryRow.
94
94
// Any named placeholder parameters are replaced with fields from arg.
95
- func (n * NamedStmt ) QueryRowx (arg interface {} ) * Row {
95
+ func (n * NamedStmt ) QueryRowx (arg any ) * Row {
96
96
return n .QueryRow (arg )
97
97
}
98
98
99
99
// Select using this NamedStmt
100
100
// Any named placeholder parameters are replaced with fields from arg.
101
- func (n * NamedStmt ) Select (dest interface {} , arg interface {} ) error {
101
+ func (n * NamedStmt ) Select (dest any , arg any ) error {
102
102
rows , err := n .Queryx (arg )
103
103
if err != nil {
104
104
return err
@@ -110,7 +110,7 @@ func (n *NamedStmt) Select(dest interface{}, arg interface{}) error {
110
110
111
111
// Get using this NamedStmt
112
112
// Any named placeholder parameters are replaced with fields from arg.
113
- func (n * NamedStmt ) Get (dest interface {} , arg interface {} ) error {
113
+ func (n * NamedStmt ) Get (dest any , arg any ) error {
114
114
r := n .QueryRowx (arg )
115
115
return r .scanAny (dest , false )
116
116
}
@@ -146,21 +146,21 @@ func prepareNamed(p namedPreparer, query string) (*NamedStmt, error) {
146
146
}, nil
147
147
}
148
148
149
- // convertMapStringInterface attempts to convert v to map[string]interface{} .
150
- // Unlike v.(map[string]interface{} ), this function works on named types that
151
- // are convertible to map[string]interface{} as well.
152
- func convertMapStringInterface (v interface {} ) (map [string ]interface {} , bool ) {
153
- var m map [string ]interface {}
149
+ // convertMapStringInterface attempts to convert v to map[string]any .
150
+ // Unlike v.(map[string]any ), this function works on named types that
151
+ // are convertible to map[string]any as well.
152
+ func convertMapStringInterface (v any ) (map [string ]any , bool ) {
153
+ var m map [string ]any
154
154
mtype := reflect .TypeOf (m )
155
155
t := reflect .TypeOf (v )
156
156
if ! t .ConvertibleTo (mtype ) {
157
157
return nil , false
158
158
}
159
- return reflect .ValueOf (v ).Convert (mtype ).Interface ().(map [string ]interface {} ), true
159
+ return reflect .ValueOf (v ).Convert (mtype ).Interface ().(map [string ]any ), true
160
160
161
161
}
162
162
163
- func bindAnyArgs (names []string , arg interface {} , m * reflectx.Mapper ) ([]interface {} , error ) {
163
+ func bindAnyArgs (names []string , arg any , m * reflectx.Mapper ) ([]any , error ) {
164
164
if maparg , ok := convertMapStringInterface (arg ); ok {
165
165
return bindMapArgs (names , maparg )
166
166
}
@@ -170,8 +170,8 @@ func bindAnyArgs(names []string, arg interface{}, m *reflectx.Mapper) ([]interfa
170
170
// private interface to generate a list of interfaces from a given struct
171
171
// type, given a list of names to pull out of the struct. Used by public
172
172
// BindStruct interface.
173
- func bindArgs (names []string , arg interface {} , m * reflectx.Mapper ) ([]interface {} , error ) {
174
- arglist := make ([]interface {} , 0 , len (names ))
173
+ func bindArgs (names []string , arg any , m * reflectx.Mapper ) ([]any , error ) {
174
+ arglist := make ([]any , 0 , len (names ))
175
175
176
176
// grab the indirected value of arg
177
177
v := reflect .ValueOf (arg )
@@ -194,8 +194,8 @@ func bindArgs(names []string, arg interface{}, m *reflectx.Mapper) ([]interface{
194
194
}
195
195
196
196
// like bindArgs, but for maps.
197
- func bindMapArgs (names []string , arg map [string ]interface {} ) ([]interface {} , error ) {
198
- arglist := make ([]interface {} , 0 , len (names ))
197
+ func bindMapArgs (names []string , arg map [string ]any ) ([]any , error ) {
198
+ arglist := make ([]any , 0 , len (names ))
199
199
200
200
for _ , name := range names {
201
201
val , ok := arg [name ]
@@ -210,15 +210,15 @@ func bindMapArgs(names []string, arg map[string]interface{}) ([]interface{}, err
210
210
// bindStruct binds a named parameter query with fields from a struct argument.
211
211
// The rules for binding field names to parameter names follow the same
212
212
// conventions as for StructScan, including obeying the `db` struct tags.
213
- func bindStruct (bindType int , query string , arg interface {} , m * reflectx.Mapper ) (string , []interface {} , error ) {
213
+ func bindStruct (bindType int , query string , arg any , m * reflectx.Mapper ) (string , []any , error ) {
214
214
bound , names , err := compileNamedQuery ([]byte (query ), bindType )
215
215
if err != nil {
216
- return "" , []interface {} {}, err
216
+ return "" , []any {}, err
217
217
}
218
218
219
219
arglist , err := bindAnyArgs (names , arg , m )
220
220
if err != nil {
221
- return "" , []interface {} {}, err
221
+ return "" , []any {}, err
222
222
}
223
223
224
224
return bound , arglist , nil
@@ -270,23 +270,23 @@ func fixBound(bound string, loop int) string {
270
270
271
271
// bindArray binds a named parameter query with fields from an array or slice of
272
272
// structs argument.
273
- func bindArray (bindType int , query string , arg interface {} , m * reflectx.Mapper ) (string , []interface {} , error ) {
273
+ func bindArray (bindType int , query string , arg any , m * reflectx.Mapper ) (string , []any , error ) {
274
274
// do the initial binding with QUESTION; if bindType is not question,
275
275
// we can rebind it at the end.
276
276
bound , names , err := compileNamedQuery ([]byte (query ), QUESTION )
277
277
if err != nil {
278
- return "" , []interface {} {}, err
278
+ return "" , []any {}, err
279
279
}
280
280
arrayValue := reflect .ValueOf (arg )
281
281
arrayLen := arrayValue .Len ()
282
282
if arrayLen == 0 {
283
- return "" , []interface {} {}, fmt .Errorf ("length of array is 0: %#v" , arg )
283
+ return "" , []any {}, fmt .Errorf ("length of array is 0: %#v" , arg )
284
284
}
285
- var arglist = make ([]interface {} , 0 , len (names )* arrayLen )
285
+ var arglist = make ([]any , 0 , len (names )* arrayLen )
286
286
for i := 0 ; i < arrayLen ; i ++ {
287
287
elemArglist , err := bindAnyArgs (names , arrayValue .Index (i ).Interface (), m )
288
288
if err != nil {
289
- return "" , []interface {} {}, err
289
+ return "" , []any {}, err
290
290
}
291
291
arglist = append (arglist , elemArglist ... )
292
292
}
@@ -301,10 +301,10 @@ func bindArray(bindType int, query string, arg interface{}, m *reflectx.Mapper)
301
301
}
302
302
303
303
// bindMap binds a named parameter query with a map of arguments.
304
- func bindMap (bindType int , query string , args map [string ]interface {} ) (string , []interface {} , error ) {
304
+ func bindMap (bindType int , query string , args map [string ]any ) (string , []any , error ) {
305
305
bound , names , err := compileNamedQuery ([]byte (query ), bindType )
306
306
if err != nil {
307
- return "" , []interface {} {}, err
307
+ return "" , []any {}, err
308
308
}
309
309
310
310
arglist , err := bindMapArgs (names , args )
@@ -407,18 +407,18 @@ func compileNamedQuery(qs []byte, bindType int) (query string, names []string, e
407
407
408
408
// BindNamed binds a struct or a map to a query with named parameters.
409
409
// DEPRECATED: use sqlx.Named` instead of this, it may be removed in future.
410
- func BindNamed (bindType int , query string , arg interface {} ) (string , []interface {} , error ) {
410
+ func BindNamed (bindType int , query string , arg any ) (string , []any , error ) {
411
411
return bindNamedMapper (bindType , query , arg , mapper ())
412
412
}
413
413
414
414
// Named takes a query using named parameters and an argument and
415
415
// returns a new query with a list of args that can be executed by
416
416
// a database. The return value uses the `?` bindvar.
417
- func Named (query string , arg interface {} ) (string , []interface {} , error ) {
417
+ func Named (query string , arg any ) (string , []any , error ) {
418
418
return bindNamedMapper (QUESTION , query , arg , mapper ())
419
419
}
420
420
421
- func bindNamedMapper (bindType int , query string , arg interface {} , m * reflectx.Mapper ) (string , []interface {} , error ) {
421
+ func bindNamedMapper (bindType int , query string , arg any , m * reflectx.Mapper ) (string , []any , error ) {
422
422
t := reflect .TypeOf (arg )
423
423
k := t .Kind ()
424
424
switch {
@@ -437,8 +437,8 @@ func bindNamedMapper(bindType int, query string, arg interface{}, m *reflectx.Ma
437
437
438
438
// NamedQuery binds a named query and then runs Query on the result using the
439
439
// provided Ext (sqlx.Tx, sqlx.Db). It works with both structs and with
440
- // map[string]interface{} types.
441
- func NamedQuery (e Ext , query string , arg interface {} ) (* Rows , error ) {
440
+ // map[string]any types.
441
+ func NamedQuery (e Ext , query string , arg any ) (* Rows , error ) {
442
442
q , args , err := bindNamedMapper (BindType (e .DriverName ()), query , arg , mapperFor (e ))
443
443
if err != nil {
444
444
return nil , err
@@ -449,7 +449,7 @@ func NamedQuery(e Ext, query string, arg interface{}) (*Rows, error) {
449
449
// NamedExec uses BindStruct to get a query executable by the driver and
450
450
// then runs Exec on the result. Returns an error from the binding
451
451
// or the query execution itself.
452
- func NamedExec (e Ext , query string , arg interface {} ) (sql.Result , error ) {
452
+ func NamedExec (e Ext , query string , arg any ) (sql.Result , error ) {
453
453
q , args , err := bindNamedMapper (BindType (e .DriverName ()), query , arg , mapperFor (e ))
454
454
if err != nil {
455
455
return nil , err
0 commit comments