avoid bigint converted into float64 when unmarshaling
This commit is contained in:
@@ -83,10 +83,6 @@ func (cc CachedConn) QueryRowIndex(v interface{}, key string, keyer func(primary
|
||||
var primaryKey interface{}
|
||||
var found bool
|
||||
|
||||
// if don't use convert numeric primary key into int64,
|
||||
// then it will be represented as scientific notion, like 2e6
|
||||
// which will make the cache doesn't match with the previous insert one
|
||||
keyer = floatKeyer(keyer)
|
||||
if err := cc.cache.TakeWithExpire(&primaryKey, key, func(val interface{}, expire time.Duration) (err error) {
|
||||
primaryKey, err = indexQuery(cc.db, v)
|
||||
if err != nil {
|
||||
@@ -124,16 +120,3 @@ func (cc CachedConn) SetCache(key string, v interface{}) error {
|
||||
func (cc CachedConn) Transact(fn func(sqlx.Session) error) error {
|
||||
return cc.db.Transact(fn)
|
||||
}
|
||||
|
||||
func floatKeyer(fn func(interface{}) string) func(interface{}) string {
|
||||
return func(primary interface{}) string {
|
||||
switch v := primary.(type) {
|
||||
case float32:
|
||||
return fn(int64(v))
|
||||
case float64:
|
||||
return fn(int64(v))
|
||||
default:
|
||||
return fn(primary)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user