@@ -21,7 +21,7 @@ import (
2121// NameMapper is used to map column names to struct field names. By default,
2222// it uses strings.ToLower to lowercase struct field names. It can be set
2323// to whatever you want, but it is encouraged to be set before sqlx is used
24- // as field -to-name mappings are cached after first use on a type.
24+ // as name -to-field mappings are cached after first use on a type.
2525var NameMapper = strings .ToLower
2626var origMapper = reflect .ValueOf (NameMapper )
2727
@@ -33,51 +33,49 @@ var mpr *reflectx.Mapper
3333func mapper () * reflectx.Mapper {
3434 if mpr == nil {
3535 mpr = reflectx .NewMapperFunc ("db" , NameMapper )
36- }
37- if origMapper != reflect . ValueOf ( NameMapper ) {
36+ } else if origMapper != reflect . ValueOf ( NameMapper ) {
37+ // if NameMapper has changed, create a new mapper
3838 mpr = reflectx .NewMapperFunc ("db" , NameMapper )
3939 origMapper = reflect .ValueOf (NameMapper )
4040 }
4141 return mpr
4242}
4343
44- // ColScanner is an interface for something which can Scan and return a list
45- // of columns (Row, Rows)
44+ // ColScanner is an interface used by MapScan and SliceScan
4645type ColScanner interface {
4746 Columns () ([]string , error )
4847 Scan (dest ... interface {}) error
4948 Err () error
5049}
5150
52- // Queryer is an interface for something which can Query (Tx, DB, Stmt)
51+ // Queryer is an interface used by Get and Select
5352type Queryer interface {
5453 Query (query string , args ... interface {}) (* sql.Rows , error )
5554 Queryx (query string , args ... interface {}) (* Rows , error )
5655 QueryRowx (query string , args ... interface {}) * Row
5756}
5857
59- // Execer is an interface for something which can Exec (Tx, DB, Stmt)
58+ // Execer is an interface used by MustExec and LoadFile
6059type Execer interface {
6160 Exec (query string , args ... interface {}) (sql.Result , error )
6261}
6362
6463// Binder is an interface for something which can bind queries (Tx, DB)
65- type Binder interface {
64+ type binder interface {
6665 DriverName () string
6766 Rebind (string ) string
68- BindMap (string , map [string ]interface {}) (string , []interface {}, error )
69- BindStruct (string , interface {}) (string , []interface {}, error )
67+ BindNamed (string , interface {}) (string , []interface {}, error )
7068}
7169
72- // Ext is a union interface which can bind, query, and exec (Tx, DB), used for
73- // NamedQuery and NamedExec, which requires exec/query and BindMap/Struct
70+ // Ext is a union interface which can bind, query, and exec, used by
71+ // NamedQuery and NamedExec.
7472type Ext interface {
75- Binder
73+ binder
7674 Queryer
7775 Execer
7876}
7977
80- // Preparer is an interface for something which can prepare sql statements (Tx, DB)
78+ // Preparer is an interface used by Preparex.
8179type Preparer interface {
8280 Prepare (query string ) (* sql.Stmt , error )
8381}
@@ -192,7 +190,7 @@ func (db *DB) DriverName() string {
192190 return db .driverName
193191}
194192
195- // Open is the same as database/ sql's Open, but returns an *sqlx.DB instead.
193+ // Open is the same as sql. Open, but returns an *sqlx.DB instead.
196194func Open (driverName , dataSourceName string ) (* DB , error ) {
197195 db , err := sql .Open (driverName , dataSourceName )
198196 if err != nil {
@@ -214,14 +212,9 @@ func (db *DB) Unsafe() *DB {
214212 return & DB {DB : db .DB , driverName : db .driverName , unsafe : true }
215213}
216214
217- // BindMap binds a query using the DB driver's bindvar type.
218- func (db * DB ) BindMap (query string , argmap map [string ]interface {}) (string , []interface {}, error ) {
219- return BindMap (BindType (db .driverName ), query , argmap )
220- }
221-
222- // BindStruct binds a query using the DB driver's bindvar type.
223- func (db * DB ) BindStruct (query string , arg interface {}) (string , []interface {}, error ) {
224- return BindStruct (BindType (db .driverName ), query , arg )
215+ // BindNamed binds a query using the DB driver's bindvar type.
216+ func (db * DB ) BindNamed (query string , arg interface {}) (string , []interface {}, error ) {
217+ return BindNamed (BindType (db .driverName ), query , arg )
225218}
226219
227220// NamedQuery using this DB.
@@ -293,7 +286,7 @@ func (db *DB) PrepareNamed(query string) (*NamedStmt, error) {
293286 return prepareNamed (db , query )
294287}
295288
296- // Tx is an sqlx wrapper around database/ sql's Tx with extra functionality
289+ // Tx is an sqlx wrapper around sql. Tx with extra functionality
297290type Tx struct {
298291 * sql.Tx
299292 driverName string
@@ -316,14 +309,9 @@ func (tx *Tx) Unsafe() *Tx {
316309 return & Tx {Tx : tx .Tx , driverName : tx .driverName , unsafe : true }
317310}
318311
319- // BindMap binds a query within a transaction's bindvar type.
320- func (tx * Tx ) BindMap (query string , argmap map [string ]interface {}) (string , []interface {}, error ) {
321- return BindMap (BindType (tx .driverName ), query , argmap )
322- }
323-
324- // BindStruct binds a query within a transaction's bindvar type.
325- func (tx * Tx ) BindStruct (query string , arg interface {}) (string , []interface {}, error ) {
326- return BindStruct (BindType (tx .driverName ), query , arg )
312+ // BindNamed binds a query within a transaction's bindvar type.
313+ func (tx * Tx ) BindNamed (query string , arg interface {}) (string , []interface {}, error ) {
314+ return BindNamed (BindType (tx .driverName ), query , arg )
327315}
328316
329317// NamedQuery within a transaction.
@@ -404,7 +392,7 @@ func (tx *Tx) PrepareNamed(query string) (*NamedStmt, error) {
404392 return prepareNamed (tx , query )
405393}
406394
407- // Stmt is an sqlx wrapper around database/ sql's Stmt with extra functionality
395+ // Stmt is an sqlx wrapper around sql. Stmt with extra functionality
408396type Stmt struct {
409397 * sql.Stmt
410398 unsafe bool
0 commit comments