-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
I set tagMapFunc,but the reflectx.Mapper from conn cannot be passed to stmt when creating stmt from conn. The mapperFor function lacks handling for database connection (conn) types, which prevents the proper propagation of the reflectx.Mapper to statements created from connections.
func setDBTagMapper(db *sqlx.DB, dbtype DBType) {
switch dbtype {
case DBTypeDM, DBTypeORA:
db.Mapper = reflectx.NewMapperTagFunc("db", nil, strings.ToUpper)
}
}
my func
stmt, err := conn.PreparexContext(ctx, querySql)
if err != nil {
t.Error(err)
}
defer stmt.Close()
func PreparexContext(ctx context.Context, p PreparerContext, query string) (*Stmt, error) {
s, err := p.PrepareContext(ctx, query)
if err != nil {
return nil, err
}
return &Stmt{Stmt: s, unsafe: isUnsafe(p), Mapper: mapperFor(p)}, err
}
func mapperFor(i interface{}) *reflectx.Mapper {
switch i := i.(type) {
case DB:
return i.Mapper
case *DB:
return i.Mapper
case Tx:
return i.Mapper
case *Tx:
return i.Mapper
default:
return mapper()
}
}
Metadata
Metadata
Assignees
Labels
No labels