chore: change interface{} to any (#2818)

* chore: change interface{} to any

* chore: update goctl version to 1.5.0

* chore: update goctl deps
This commit is contained in:
Kevin Wan
2023-01-24 16:32:02 +08:00
committed by GitHub
parent 7e0ac77139
commit ae87114282
221 changed files with 1910 additions and 2207 deletions

View File

@@ -9,7 +9,7 @@ import (
const dbTag = "db"
// RawFieldNames converts golang struct field into slice string.
func RawFieldNames(in interface{}, postgresSql ...bool) []string {
func RawFieldNames(in any, postgresSql ...bool) []string {
out := make([]string, 0)
v := reflect.ValueOf(in)
if v.Kind() == reflect.Ptr {

View File

@@ -20,32 +20,32 @@ type (
// DelCtx deletes cached values with keys.
DelCtx(ctx context.Context, keys ...string) error
// Get gets the cache with key and fills into v.
Get(key string, val interface{}) error
Get(key string, val any) error
// GetCtx gets the cache with key and fills into v.
GetCtx(ctx context.Context, key string, val interface{}) error
GetCtx(ctx context.Context, key string, val any) error
// IsNotFound checks if the given error is the defined errNotFound.
IsNotFound(err error) bool
// Set sets the cache with key and v, using c.expiry.
Set(key string, val interface{}) error
Set(key string, val any) error
// SetCtx sets the cache with key and v, using c.expiry.
SetCtx(ctx context.Context, key string, val interface{}) error
SetCtx(ctx context.Context, key string, val any) error
// SetWithExpire sets the cache with key and v, using given expire.
SetWithExpire(key string, val interface{}, expire time.Duration) error
SetWithExpire(key string, val any, expire time.Duration) error
// SetWithExpireCtx sets the cache with key and v, using given expire.
SetWithExpireCtx(ctx context.Context, key string, val interface{}, expire time.Duration) error
SetWithExpireCtx(ctx context.Context, key string, val any, expire time.Duration) error
// Take takes the result from cache first, if not found,
// query from DB and set cache using c.expiry, then return the result.
Take(val interface{}, key string, query func(val interface{}) error) error
Take(val any, key string, query func(val any) error) error
// TakeCtx takes the result from cache first, if not found,
// query from DB and set cache using c.expiry, then return the result.
TakeCtx(ctx context.Context, val interface{}, key string, query func(val interface{}) error) error
TakeCtx(ctx context.Context, val any, key string, query func(val any) error) error
// TakeWithExpire takes the result from cache first, if not found,
// query from DB and set cache using given expire, then return the result.
TakeWithExpire(val interface{}, key string, query func(val interface{}, expire time.Duration) error) error
TakeWithExpire(val any, key string, query func(val any, expire time.Duration) error) error
// TakeWithExpireCtx takes the result from cache first, if not found,
// query from DB and set cache using given expire, then return the result.
TakeWithExpireCtx(ctx context.Context, val interface{}, key string,
query func(val interface{}, expire time.Duration) error) error
TakeWithExpireCtx(ctx context.Context, val any, key string,
query func(val any, expire time.Duration) error) error
}
cacheCluster struct {
@@ -97,7 +97,7 @@ func (cc cacheCluster) DelCtx(ctx context.Context, keys ...string) error {
return c.(Cache).DelCtx(ctx, key)
default:
var be errorx.BatchError
nodes := make(map[interface{}][]string)
nodes := make(map[any][]string)
for _, key := range keys {
c, ok := cc.dispatcher.Get(key)
if !ok {
@@ -118,12 +118,12 @@ func (cc cacheCluster) DelCtx(ctx context.Context, keys ...string) error {
}
// Get gets the cache with key and fills into v.
func (cc cacheCluster) Get(key string, val interface{}) error {
func (cc cacheCluster) Get(key string, val any) error {
return cc.GetCtx(context.Background(), key, val)
}
// GetCtx gets the cache with key and fills into v.
func (cc cacheCluster) GetCtx(ctx context.Context, key string, val interface{}) error {
func (cc cacheCluster) GetCtx(ctx context.Context, key string, val any) error {
c, ok := cc.dispatcher.Get(key)
if !ok {
return cc.errNotFound
@@ -138,12 +138,12 @@ func (cc cacheCluster) IsNotFound(err error) bool {
}
// Set sets the cache with key and v, using c.expiry.
func (cc cacheCluster) Set(key string, val interface{}) error {
func (cc cacheCluster) Set(key string, val any) error {
return cc.SetCtx(context.Background(), key, val)
}
// SetCtx sets the cache with key and v, using c.expiry.
func (cc cacheCluster) SetCtx(ctx context.Context, key string, val interface{}) error {
func (cc cacheCluster) SetCtx(ctx context.Context, key string, val any) error {
c, ok := cc.dispatcher.Get(key)
if !ok {
return cc.errNotFound
@@ -153,12 +153,12 @@ func (cc cacheCluster) SetCtx(ctx context.Context, key string, val interface{})
}
// SetWithExpire sets the cache with key and v, using given expire.
func (cc cacheCluster) SetWithExpire(key string, val interface{}, expire time.Duration) error {
func (cc cacheCluster) SetWithExpire(key string, val any, expire time.Duration) error {
return cc.SetWithExpireCtx(context.Background(), key, val, expire)
}
// SetWithExpireCtx sets the cache with key and v, using given expire.
func (cc cacheCluster) SetWithExpireCtx(ctx context.Context, key string, val interface{}, expire time.Duration) error {
func (cc cacheCluster) SetWithExpireCtx(ctx context.Context, key string, val any, expire time.Duration) error {
c, ok := cc.dispatcher.Get(key)
if !ok {
return cc.errNotFound
@@ -169,13 +169,13 @@ func (cc cacheCluster) SetWithExpireCtx(ctx context.Context, key string, val int
// Take takes the result from cache first, if not found,
// query from DB and set cache using c.expiry, then return the result.
func (cc cacheCluster) Take(val interface{}, key string, query func(val interface{}) error) error {
func (cc cacheCluster) Take(val any, key string, query func(val any) error) error {
return cc.TakeCtx(context.Background(), val, key, query)
}
// TakeCtx takes the result from cache first, if not found,
// query from DB and set cache using c.expiry, then return the result.
func (cc cacheCluster) TakeCtx(ctx context.Context, val interface{}, key string, query func(val interface{}) error) error {
func (cc cacheCluster) TakeCtx(ctx context.Context, val any, key string, query func(val any) error) error {
c, ok := cc.dispatcher.Get(key)
if !ok {
return cc.errNotFound
@@ -186,13 +186,13 @@ func (cc cacheCluster) TakeCtx(ctx context.Context, val interface{}, key string,
// TakeWithExpire takes the result from cache first, if not found,
// query from DB and set cache using given expire, then return the result.
func (cc cacheCluster) TakeWithExpire(val interface{}, key string, query func(val interface{}, expire time.Duration) error) error {
func (cc cacheCluster) TakeWithExpire(val any, key string, query func(val any, expire time.Duration) error) error {
return cc.TakeWithExpireCtx(context.Background(), val, key, query)
}
// TakeWithExpireCtx takes the result from cache first, if not found,
// query from DB and set cache using given expire, then return the result.
func (cc cacheCluster) TakeWithExpireCtx(ctx context.Context, val interface{}, key string, query func(val interface{}, expire time.Duration) error) error {
func (cc cacheCluster) TakeWithExpireCtx(ctx context.Context, val any, key string, query func(val any, expire time.Duration) error) error {
c, ok := cc.dispatcher.Get(key)
if !ok {
return cc.errNotFound

View File

@@ -44,11 +44,11 @@ func (mc *mockedNode) DelCtx(_ context.Context, keys ...string) error {
return be.Err()
}
func (mc *mockedNode) Get(key string, val interface{}) error {
func (mc *mockedNode) Get(key string, val any) error {
return mc.GetCtx(context.Background(), key, val)
}
func (mc *mockedNode) GetCtx(ctx context.Context, key string, val interface{}) error {
func (mc *mockedNode) GetCtx(ctx context.Context, key string, val any) error {
bs, ok := mc.vals[key]
if ok {
return json.Unmarshal(bs, val)
@@ -61,11 +61,11 @@ func (mc *mockedNode) IsNotFound(err error) bool {
return errors.Is(err, mc.errNotFound)
}
func (mc *mockedNode) Set(key string, val interface{}) error {
func (mc *mockedNode) Set(key string, val any) error {
return mc.SetCtx(context.Background(), key, val)
}
func (mc *mockedNode) SetCtx(ctx context.Context, key string, val interface{}) error {
func (mc *mockedNode) SetCtx(ctx context.Context, key string, val any) error {
data, err := json.Marshal(val)
if err != nil {
return err
@@ -75,19 +75,19 @@ func (mc *mockedNode) SetCtx(ctx context.Context, key string, val interface{}) e
return nil
}
func (mc *mockedNode) SetWithExpire(key string, val interface{}, expire time.Duration) error {
func (mc *mockedNode) SetWithExpire(key string, val any, expire time.Duration) error {
return mc.SetWithExpireCtx(context.Background(), key, val, expire)
}
func (mc *mockedNode) SetWithExpireCtx(ctx context.Context, key string, val interface{}, expire time.Duration) error {
func (mc *mockedNode) SetWithExpireCtx(ctx context.Context, key string, val any, expire time.Duration) error {
return mc.Set(key, val)
}
func (mc *mockedNode) Take(val interface{}, key string, query func(val interface{}) error) error {
func (mc *mockedNode) Take(val any, key string, query func(val any) error) error {
return mc.TakeCtx(context.Background(), val, key, query)
}
func (mc *mockedNode) TakeCtx(ctx context.Context, val interface{}, key string, query func(val interface{}) error) error {
func (mc *mockedNode) TakeCtx(ctx context.Context, val any, key string, query func(val any) error) error {
if _, ok := mc.vals[key]; ok {
return mc.GetCtx(ctx, key, val)
}
@@ -99,12 +99,12 @@ func (mc *mockedNode) TakeCtx(ctx context.Context, val interface{}, key string,
return mc.SetCtx(ctx, key, val)
}
func (mc *mockedNode) TakeWithExpire(val interface{}, key string, query func(val interface{}, expire time.Duration) error) error {
func (mc *mockedNode) TakeWithExpire(val any, key string, query func(val any, expire time.Duration) error) error {
return mc.TakeWithExpireCtx(context.Background(), val, key, query)
}
func (mc *mockedNode) TakeWithExpireCtx(ctx context.Context, val interface{}, key string, query func(val interface{}, expire time.Duration) error) error {
return mc.Take(val, key, func(val interface{}) error {
func (mc *mockedNode) TakeWithExpireCtx(ctx context.Context, val any, key string, query func(val any, expire time.Duration) error) error {
return mc.Take(val, key, func(val any) error {
return query(val, 0)
})
}
@@ -279,13 +279,13 @@ func TestCache_Balance(t *testing.T) {
for i := 0; i < total/10; i++ {
var val int
if i%2 == 0 {
assert.Nil(t, c.Take(&val, strconv.Itoa(i*10), func(val interface{}) error {
assert.Nil(t, c.Take(&val, strconv.Itoa(i*10), func(val any) error {
*val.(*int) = i
count++
return nil
}))
} else {
assert.Nil(t, c.TakeWithExpire(&val, strconv.Itoa(i*10), func(val interface{}, expire time.Duration) error {
assert.Nil(t, c.TakeWithExpire(&val, strconv.Itoa(i*10), func(val any, expire time.Duration) error {
*val.(*int) = i
count++
return nil
@@ -307,10 +307,10 @@ func TestCacheNoNode(t *testing.T) {
assert.NotNil(t, c.Get("foo", nil))
assert.NotNil(t, c.Set("foo", nil))
assert.NotNil(t, c.SetWithExpire("foo", nil, time.Second))
assert.NotNil(t, c.Take(nil, "foo", func(val interface{}) error {
assert.NotNil(t, c.Take(nil, "foo", func(val any) error {
return nil
}))
assert.NotNil(t, c.TakeWithExpire(nil, "foo", func(val interface{}, duration time.Duration) error {
assert.NotNil(t, c.TakeWithExpire(nil, "foo", func(val any, duration time.Duration) error {
return nil
}))
}

View File

@@ -89,12 +89,12 @@ func (c cacheNode) DelCtx(ctx context.Context, keys ...string) error {
}
// Get gets the cache with key and fills into v.
func (c cacheNode) Get(key string, val interface{}) error {
func (c cacheNode) Get(key string, val any) error {
return c.GetCtx(context.Background(), key, val)
}
// GetCtx gets the cache with key and fills into v.
func (c cacheNode) GetCtx(ctx context.Context, key string, val interface{}) error {
func (c cacheNode) GetCtx(ctx context.Context, key string, val any) error {
err := c.doGetCache(ctx, key, val)
if err == errPlaceholder {
return c.errNotFound
@@ -109,22 +109,22 @@ func (c cacheNode) IsNotFound(err error) bool {
}
// Set sets the cache with key and v, using c.expiry.
func (c cacheNode) Set(key string, val interface{}) error {
func (c cacheNode) Set(key string, val any) error {
return c.SetCtx(context.Background(), key, val)
}
// SetCtx sets the cache with key and v, using c.expiry.
func (c cacheNode) SetCtx(ctx context.Context, key string, val interface{}) error {
func (c cacheNode) SetCtx(ctx context.Context, key string, val any) error {
return c.SetWithExpireCtx(ctx, key, val, c.aroundDuration(c.expiry))
}
// SetWithExpire sets the cache with key and v, using given expire.
func (c cacheNode) SetWithExpire(key string, val interface{}, expire time.Duration) error {
func (c cacheNode) SetWithExpire(key string, val any, expire time.Duration) error {
return c.SetWithExpireCtx(context.Background(), key, val, expire)
}
// SetWithExpireCtx sets the cache with key and v, using given expire.
func (c cacheNode) SetWithExpireCtx(ctx context.Context, key string, val interface{},
func (c cacheNode) SetWithExpireCtx(ctx context.Context, key string, val any,
expire time.Duration) error {
data, err := jsonx.Marshal(val)
if err != nil {
@@ -141,34 +141,34 @@ func (c cacheNode) String() string {
// Take takes the result from cache first, if not found,
// query from DB and set cache using c.expiry, then return the result.
func (c cacheNode) Take(val interface{}, key string, query func(val interface{}) error) error {
func (c cacheNode) Take(val any, key string, query func(val any) error) error {
return c.TakeCtx(context.Background(), val, key, query)
}
// TakeCtx takes the result from cache first, if not found,
// query from DB and set cache using c.expiry, then return the result.
func (c cacheNode) TakeCtx(ctx context.Context, val interface{}, key string,
query func(val interface{}) error) error {
return c.doTake(ctx, val, key, query, func(v interface{}) error {
func (c cacheNode) TakeCtx(ctx context.Context, val any, key string,
query func(val any) error) error {
return c.doTake(ctx, val, key, query, func(v any) error {
return c.SetCtx(ctx, key, v)
})
}
// TakeWithExpire takes the result from cache first, if not found,
// query from DB and set cache using given expire, then return the result.
func (c cacheNode) TakeWithExpire(val interface{}, key string, query func(val interface{},
func (c cacheNode) TakeWithExpire(val any, key string, query func(val any,
expire time.Duration) error) error {
return c.TakeWithExpireCtx(context.Background(), val, key, query)
}
// TakeWithExpireCtx takes the result from cache first, if not found,
// query from DB and set cache using given expire, then return the result.
func (c cacheNode) TakeWithExpireCtx(ctx context.Context, val interface{}, key string,
query func(val interface{}, expire time.Duration) error) error {
func (c cacheNode) TakeWithExpireCtx(ctx context.Context, val any, key string,
query func(val any, expire time.Duration) error) error {
expire := c.aroundDuration(c.expiry)
return c.doTake(ctx, val, key, func(v interface{}) error {
return c.doTake(ctx, val, key, func(v any) error {
return query(v, expire)
}, func(v interface{}) error {
}, func(v any) error {
return c.SetWithExpireCtx(ctx, key, v, expire)
})
}
@@ -184,7 +184,7 @@ func (c cacheNode) asyncRetryDelCache(keys ...string) {
}, keys...)
}
func (c cacheNode) doGetCache(ctx context.Context, key string, v interface{}) error {
func (c cacheNode) doGetCache(ctx context.Context, key string, v any) error {
c.stat.IncrementTotal()
data, err := c.rds.GetCtx(ctx, key)
if err != nil {
@@ -205,10 +205,10 @@ func (c cacheNode) doGetCache(ctx context.Context, key string, v interface{}) er
return c.processCache(ctx, key, data, v)
}
func (c cacheNode) doTake(ctx context.Context, v interface{}, key string,
query func(v interface{}) error, cacheVal func(v interface{}) error) error {
func (c cacheNode) doTake(ctx context.Context, v any, key string,
query func(v any) error, cacheVal func(v any) error) error {
logger := logx.WithContext(ctx)
val, fresh, err := c.barrier.DoEx(key, func() (interface{}, error) {
val, fresh, err := c.barrier.DoEx(key, func() (any, error) {
if err := c.doGetCache(ctx, key, v); err != nil {
if err == errPlaceholder {
return nil, c.errNotFound
@@ -255,7 +255,7 @@ func (c cacheNode) doTake(ctx context.Context, v interface{}, key string,
return jsonx.Unmarshal(val.([]byte), v)
}
func (c cacheNode) processCache(ctx context.Context, key, data string, v interface{}) error {
func (c cacheNode) processCache(ctx context.Context, key, data string, v any) error {
err := jsonx.Unmarshal([]byte(data), v)
if err == nil {
return nil

View File

@@ -62,7 +62,7 @@ func TestCacheNode_DelCache(t *testing.T) {
ticker := timex.NewFakeTicker()
var err error
timingWheel, err = collection.NewTimingWheelWithTicker(
time.Millisecond, timingWheelSlots, func(key, value interface{}) {
time.Millisecond, timingWheelSlots, func(key, value any) {
clean(key, value)
}, ticker)
assert.NoError(t, err)
@@ -146,7 +146,7 @@ func TestCacheNode_Take(t *testing.T) {
cn := NewNode(store, syncx.NewSingleFlight(), NewStat("any"), errTestNotFound,
WithExpiry(time.Second), WithNotFoundExpiry(time.Second))
var str string
err = cn.Take(&str, "any", func(v interface{}) error {
err = cn.Take(&str, "any", func(v any) error {
*v.(*string) = "value"
return nil
})
@@ -167,7 +167,7 @@ func TestCacheNode_TakeBadRedis(t *testing.T) {
cn := NewNode(redis.New(r.Addr()), syncx.NewSingleFlight(), NewStat("any"),
errTestNotFound, WithExpiry(time.Second), WithNotFoundExpiry(time.Second))
var str string
assert.Error(t, cn.Take(&str, "any", func(v interface{}) error {
assert.Error(t, cn.Take(&str, "any", func(v any) error {
*v.(*string) = "value"
return nil
}))
@@ -188,7 +188,7 @@ func TestCacheNode_TakeNotFound(t *testing.T) {
errNotFound: errTestNotFound,
}
var str string
err = cn.Take(&str, "any", func(v interface{}) error {
err = cn.Take(&str, "any", func(v any) error {
return errTestNotFound
})
assert.True(t, cn.IsNotFound(err))
@@ -198,7 +198,7 @@ func TestCacheNode_TakeNotFound(t *testing.T) {
assert.Equal(t, `*`, val)
store.Set("any", "*")
err = cn.Take(&str, "any", func(v interface{}) error {
err = cn.Take(&str, "any", func(v any) error {
return nil
})
assert.True(t, cn.IsNotFound(err))
@@ -206,7 +206,7 @@ func TestCacheNode_TakeNotFound(t *testing.T) {
store.Del("any")
errDummy := errors.New("dummy")
err = cn.Take(&str, "any", func(v interface{}) error {
err = cn.Take(&str, "any", func(v any) error {
return errDummy
})
assert.Equal(t, errDummy, err)
@@ -227,7 +227,7 @@ func TestCacheNode_TakeWithExpire(t *testing.T) {
errNotFound: errors.New("any"),
}
var str string
err = cn.TakeWithExpire(&str, "any", func(v interface{}, expire time.Duration) error {
err = cn.TakeWithExpire(&str, "any", func(v any, expire time.Duration) error {
*v.(*string) = "value"
return nil
})
@@ -277,7 +277,7 @@ func TestCacheValueWithBigInt(t *testing.T) {
)
assert.Nil(t, cn.Set(key, value))
var val interface{}
var val any
assert.Nil(t, cn.Get(key, &val))
assert.Equal(t, strconv.FormatInt(value, 10), fmt.Sprintf("%v", val))
}

View File

@@ -48,7 +48,7 @@ func AddCleanTask(task func() error, keys ...string) {
}, time.Second)
}
func clean(key, value interface{}) {
func clean(key, value any) {
taskRunner.Schedule(func() {
dt := value.(delayTask)
err := dt.task()

View File

@@ -23,8 +23,8 @@ type (
DecrbyCtx(ctx context.Context, key string, decrement int64) (int64, error)
Del(keys ...string) (int, error)
DelCtx(ctx context.Context, keys ...string) (int, error)
Eval(script, key string, args ...interface{}) (interface{}, error)
EvalCtx(ctx context.Context, script, key string, args ...interface{}) (interface{}, error)
Eval(script, key string, args ...any) (any, error)
EvalCtx(ctx context.Context, script, key string, args ...any) (any, error)
Exists(key string) (bool, error)
ExistsCtx(ctx context.Context, key string) (bool, error)
Expire(key string, seconds int) error
@@ -69,22 +69,22 @@ type (
LlenCtx(ctx context.Context, key string) (int, error)
Lpop(key string) (string, error)
LpopCtx(ctx context.Context, key string) (string, error)
Lpush(key string, values ...interface{}) (int, error)
LpushCtx(ctx context.Context, key string, values ...interface{}) (int, error)
Lpush(key string, values ...any) (int, error)
LpushCtx(ctx context.Context, key string, values ...any) (int, error)
Lrange(key string, start, stop int) ([]string, error)
LrangeCtx(ctx context.Context, key string, start, stop int) ([]string, error)
Lrem(key string, count int, value string) (int, error)
LremCtx(ctx context.Context, key string, count int, value string) (int, error)
Persist(key string) (bool, error)
PersistCtx(ctx context.Context, key string) (bool, error)
Pfadd(key string, values ...interface{}) (bool, error)
PfaddCtx(ctx context.Context, key string, values ...interface{}) (bool, error)
Pfadd(key string, values ...any) (bool, error)
PfaddCtx(ctx context.Context, key string, values ...any) (bool, error)
Pfcount(key string) (int64, error)
PfcountCtx(ctx context.Context, key string) (int64, error)
Rpush(key string, values ...interface{}) (int, error)
RpushCtx(ctx context.Context, key string, values ...interface{}) (int, error)
Sadd(key string, values ...interface{}) (int, error)
SaddCtx(ctx context.Context, key string, values ...interface{}) (int, error)
Rpush(key string, values ...any) (int, error)
RpushCtx(ctx context.Context, key string, values ...any) (int, error)
Sadd(key string, values ...any) (int, error)
SaddCtx(ctx context.Context, key string, values ...any) (int, error)
Scard(key string) (int64, error)
ScardCtx(ctx context.Context, key string) (int64, error)
Set(key, value string) error
@@ -95,16 +95,16 @@ type (
SetnxCtx(ctx context.Context, key, value string) (bool, error)
SetnxEx(key, value string, seconds int) (bool, error)
SetnxExCtx(ctx context.Context, key, value string, seconds int) (bool, error)
Sismember(key string, value interface{}) (bool, error)
SismemberCtx(ctx context.Context, key string, value interface{}) (bool, error)
Sismember(key string, value any) (bool, error)
SismemberCtx(ctx context.Context, key string, value any) (bool, error)
Smembers(key string) ([]string, error)
SmembersCtx(ctx context.Context, key string) ([]string, error)
Spop(key string) (string, error)
SpopCtx(ctx context.Context, key string) (string, error)
Srandmember(key string, count int) ([]string, error)
SrandmemberCtx(ctx context.Context, key string, count int) ([]string, error)
Srem(key string, values ...interface{}) (int, error)
SremCtx(ctx context.Context, key string, values ...interface{}) (int, error)
Srem(key string, values ...any) (int, error)
SremCtx(ctx context.Context, key string, values ...any) (int, error)
Sscan(key string, cursor uint64, match string, count int64) (keys []string, cur uint64, err error)
SscanCtx(ctx context.Context, key string, cursor uint64, match string, count int64) (keys []string, cur uint64, err error)
Ttl(key string) (int, error)
@@ -131,8 +131,8 @@ type (
ZrangebyscoreWithScoresAndLimitCtx(ctx context.Context, key string, start, stop int64, page, size int) ([]redis.Pair, error)
Zrank(key, field string) (int64, error)
ZrankCtx(ctx context.Context, key, field string) (int64, error)
Zrem(key string, values ...interface{}) (int, error)
ZremCtx(ctx context.Context, key string, values ...interface{}) (int, error)
Zrem(key string, values ...any) (int, error)
ZremCtx(ctx context.Context, key string, values ...any) (int, error)
Zremrangebyrank(key string, start, stop int64) (int, error)
ZremrangebyrankCtx(ctx context.Context, key string, start, stop int64) (int, error)
Zremrangebyscore(key string, start, stop int64) (int, error)
@@ -224,11 +224,11 @@ func (cs clusterStore) DelCtx(ctx context.Context, keys ...string) (int, error)
return val, be.Err()
}
func (cs clusterStore) Eval(script, key string, args ...interface{}) (interface{}, error) {
func (cs clusterStore) Eval(script, key string, args ...any) (any, error) {
return cs.EvalCtx(context.Background(), script, key, args...)
}
func (cs clusterStore) EvalCtx(ctx context.Context, script, key string, args ...interface{}) (interface{}, error) {
func (cs clusterStore) EvalCtx(ctx context.Context, script, key string, args ...any) (any, error) {
node, err := cs.getRedis(key)
if err != nil {
return nil, err
@@ -510,11 +510,11 @@ func (cs clusterStore) LpopCtx(ctx context.Context, key string) (string, error)
return node.LpopCtx(ctx, key)
}
func (cs clusterStore) Lpush(key string, values ...interface{}) (int, error) {
func (cs clusterStore) Lpush(key string, values ...any) (int, error) {
return cs.LpushCtx(context.Background(), key, values...)
}
func (cs clusterStore) LpushCtx(ctx context.Context, key string, values ...interface{}) (int, error) {
func (cs clusterStore) LpushCtx(ctx context.Context, key string, values ...any) (int, error) {
node, err := cs.getRedis(key)
if err != nil {
return 0, err
@@ -562,11 +562,11 @@ func (cs clusterStore) PersistCtx(ctx context.Context, key string) (bool, error)
return node.PersistCtx(ctx, key)
}
func (cs clusterStore) Pfadd(key string, values ...interface{}) (bool, error) {
func (cs clusterStore) Pfadd(key string, values ...any) (bool, error) {
return cs.PfaddCtx(context.Background(), key, values...)
}
func (cs clusterStore) PfaddCtx(ctx context.Context, key string, values ...interface{}) (bool, error) {
func (cs clusterStore) PfaddCtx(ctx context.Context, key string, values ...any) (bool, error) {
node, err := cs.getRedis(key)
if err != nil {
return false, err
@@ -588,11 +588,11 @@ func (cs clusterStore) PfcountCtx(ctx context.Context, key string) (int64, error
return node.PfcountCtx(ctx, key)
}
func (cs clusterStore) Rpush(key string, values ...interface{}) (int, error) {
func (cs clusterStore) Rpush(key string, values ...any) (int, error) {
return cs.RpushCtx(context.Background(), key, values...)
}
func (cs clusterStore) RpushCtx(ctx context.Context, key string, values ...interface{}) (int, error) {
func (cs clusterStore) RpushCtx(ctx context.Context, key string, values ...any) (int, error) {
node, err := cs.getRedis(key)
if err != nil {
return 0, err
@@ -601,11 +601,11 @@ func (cs clusterStore) RpushCtx(ctx context.Context, key string, values ...inter
return node.RpushCtx(ctx, key, values...)
}
func (cs clusterStore) Sadd(key string, values ...interface{}) (int, error) {
func (cs clusterStore) Sadd(key string, values ...any) (int, error) {
return cs.SaddCtx(context.Background(), key, values...)
}
func (cs clusterStore) SaddCtx(ctx context.Context, key string, values ...interface{}) (int, error) {
func (cs clusterStore) SaddCtx(ctx context.Context, key string, values ...any) (int, error) {
node, err := cs.getRedis(key)
if err != nil {
return 0, err
@@ -692,11 +692,11 @@ func (cs clusterStore) GetSetCtx(ctx context.Context, key, value string) (string
return node.GetSetCtx(ctx, key, value)
}
func (cs clusterStore) Sismember(key string, value interface{}) (bool, error) {
func (cs clusterStore) Sismember(key string, value any) (bool, error) {
return cs.SismemberCtx(context.Background(), key, value)
}
func (cs clusterStore) SismemberCtx(ctx context.Context, key string, value interface{}) (bool, error) {
func (cs clusterStore) SismemberCtx(ctx context.Context, key string, value any) (bool, error) {
node, err := cs.getRedis(key)
if err != nil {
return false, err
@@ -744,11 +744,11 @@ func (cs clusterStore) SrandmemberCtx(ctx context.Context, key string, count int
return node.SrandmemberCtx(ctx, key, count)
}
func (cs clusterStore) Srem(key string, values ...interface{}) (int, error) {
func (cs clusterStore) Srem(key string, values ...any) (int, error) {
return cs.SremCtx(context.Background(), key, values...)
}
func (cs clusterStore) SremCtx(ctx context.Context, key string, values ...interface{}) (int, error) {
func (cs clusterStore) SremCtx(ctx context.Context, key string, values ...any) (int, error) {
node, err := cs.getRedis(key)
if err != nil {
return 0, err
@@ -925,11 +925,11 @@ func (cs clusterStore) ZrangebyscoreWithScoresAndLimitCtx(ctx context.Context, k
return node.ZrangebyscoreWithScoresAndLimitCtx(ctx, key, start, stop, page, size)
}
func (cs clusterStore) Zrem(key string, values ...interface{}) (int, error) {
func (cs clusterStore) Zrem(key string, values ...any) (int, error) {
return cs.ZremCtx(context.Background(), key, values...)
}
func (cs clusterStore) ZremCtx(ctx context.Context, key string, values ...interface{}) (int, error) {
func (cs clusterStore) ZremCtx(ctx context.Context, key string, values ...any) (int, error) {
node, err := cs.getRedis(key)
if err != nil {
return 0, err

View File

@@ -53,7 +53,7 @@ func (bi *BulkInserter) Flush() {
}
// Insert inserts doc.
func (bi *BulkInserter) Insert(doc interface{}) {
func (bi *BulkInserter) Insert(doc any) {
bi.executor.Add(doc)
}
@@ -66,17 +66,17 @@ func (bi *BulkInserter) SetResultHandler(handler ResultHandler) {
type dbInserter struct {
collection *mongo.Collection
documents []interface{}
documents []any
resultHandler ResultHandler
}
func (in *dbInserter) AddTask(doc interface{}) bool {
func (in *dbInserter) AddTask(doc any) bool {
in.documents = append(in.documents, doc)
return len(in.documents) >= maxBulkRows
}
func (in *dbInserter) Execute(objs interface{}) {
docs := objs.([]interface{})
func (in *dbInserter) Execute(objs any) {
docs := objs.([]any)
if len(docs) == 0 {
return
}
@@ -89,7 +89,7 @@ func (in *dbInserter) Execute(objs interface{}) {
}
}
func (in *dbInserter) RemoveAll() interface{} {
func (in *dbInserter) RemoveAll() any {
documents := in.documents
in.documents = nil
return documents

View File

@@ -46,7 +46,7 @@ type (
// Collection defines a MongoDB collection.
Collection interface {
// Aggregate executes an aggregation pipeline.
Aggregate(ctx context.Context, pipeline interface{}, opts ...*mopt.AggregateOptions) (
Aggregate(ctx context.Context, pipeline any, opts ...*mopt.AggregateOptions) (
*mongo.Cursor, error)
// BulkWrite performs a bulk write operation.
BulkWrite(ctx context.Context, models []mongo.WriteModel, opts ...*mopt.BulkWriteOptions) (
@@ -54,64 +54,64 @@ type (
// Clone creates a copy of this collection with the same settings.
Clone(opts ...*mopt.CollectionOptions) (*mongo.Collection, error)
// CountDocuments returns the number of documents in the collection that match the filter.
CountDocuments(ctx context.Context, filter interface{}, opts ...*mopt.CountOptions) (int64, error)
CountDocuments(ctx context.Context, filter any, opts ...*mopt.CountOptions) (int64, error)
// Database returns the database that this collection is a part of.
Database() *mongo.Database
// DeleteMany deletes documents from the collection that match the filter.
DeleteMany(ctx context.Context, filter interface{}, opts ...*mopt.DeleteOptions) (
DeleteMany(ctx context.Context, filter any, opts ...*mopt.DeleteOptions) (
*mongo.DeleteResult, error)
// DeleteOne deletes at most one document from the collection that matches the filter.
DeleteOne(ctx context.Context, filter interface{}, opts ...*mopt.DeleteOptions) (
DeleteOne(ctx context.Context, filter any, opts ...*mopt.DeleteOptions) (
*mongo.DeleteResult, error)
// Distinct returns a list of distinct values for the given key across the collection.
Distinct(ctx context.Context, fieldName string, filter interface{},
opts ...*mopt.DistinctOptions) ([]interface{}, error)
Distinct(ctx context.Context, fieldName string, filter any,
opts ...*mopt.DistinctOptions) ([]any, error)
// Drop drops this collection from database.
Drop(ctx context.Context) error
// EstimatedDocumentCount returns an estimate of the count of documents in a collection
// using collection metadata.
EstimatedDocumentCount(ctx context.Context, opts ...*mopt.EstimatedDocumentCountOptions) (int64, error)
// Find finds the documents matching the provided filter.
Find(ctx context.Context, filter interface{}, opts ...*mopt.FindOptions) (*mongo.Cursor, error)
Find(ctx context.Context, filter any, opts ...*mopt.FindOptions) (*mongo.Cursor, error)
// FindOne returns up to one document that matches the provided filter.
FindOne(ctx context.Context, filter interface{}, opts ...*mopt.FindOneOptions) (
FindOne(ctx context.Context, filter any, opts ...*mopt.FindOneOptions) (
*mongo.SingleResult, error)
// FindOneAndDelete returns at most one document that matches the filter. If the filter
// matches multiple documents, only the first document is deleted.
FindOneAndDelete(ctx context.Context, filter interface{}, opts ...*mopt.FindOneAndDeleteOptions) (
FindOneAndDelete(ctx context.Context, filter any, opts ...*mopt.FindOneAndDeleteOptions) (
*mongo.SingleResult, error)
// FindOneAndReplace returns at most one document that matches the filter. If the filter
// matches multiple documents, FindOneAndReplace returns the first document in the
// collection that matches the filter.
FindOneAndReplace(ctx context.Context, filter, replacement interface{},
FindOneAndReplace(ctx context.Context, filter, replacement any,
opts ...*mopt.FindOneAndReplaceOptions) (*mongo.SingleResult, error)
// FindOneAndUpdate returns at most one document that matches the filter. If the filter
// matches multiple documents, FindOneAndUpdate returns the first document in the
// collection that matches the filter.
FindOneAndUpdate(ctx context.Context, filter, update interface{},
FindOneAndUpdate(ctx context.Context, filter, update any,
opts ...*mopt.FindOneAndUpdateOptions) (*mongo.SingleResult, error)
// Indexes returns the index view for this collection.
Indexes() mongo.IndexView
// InsertMany inserts the provided documents.
InsertMany(ctx context.Context, documents []interface{}, opts ...*mopt.InsertManyOptions) (
InsertMany(ctx context.Context, documents []any, opts ...*mopt.InsertManyOptions) (
*mongo.InsertManyResult, error)
// InsertOne inserts the provided document.
InsertOne(ctx context.Context, document interface{}, opts ...*mopt.InsertOneOptions) (
InsertOne(ctx context.Context, document any, opts ...*mopt.InsertOneOptions) (
*mongo.InsertOneResult, error)
// ReplaceOne replaces at most one document that matches the filter.
ReplaceOne(ctx context.Context, filter, replacement interface{},
ReplaceOne(ctx context.Context, filter, replacement any,
opts ...*mopt.ReplaceOptions) (*mongo.UpdateResult, error)
// UpdateByID updates a single document matching the provided filter.
UpdateByID(ctx context.Context, id, update interface{},
UpdateByID(ctx context.Context, id, update any,
opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error)
// UpdateMany updates the provided documents.
UpdateMany(ctx context.Context, filter, update interface{},
UpdateMany(ctx context.Context, filter, update any,
opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error)
// UpdateOne updates a single document matching the provided filter.
UpdateOne(ctx context.Context, filter, update interface{},
UpdateOne(ctx context.Context, filter, update any,
opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error)
// Watch returns a change stream cursor used to receive notifications of changes to the collection.
Watch(ctx context.Context, pipeline interface{}, opts ...*mopt.ChangeStreamOptions) (
Watch(ctx context.Context, pipeline any, opts ...*mopt.ChangeStreamOptions) (
*mongo.ChangeStream, error)
}
@@ -135,7 +135,7 @@ func newCollection(collection *mongo.Collection, brk breaker.Breaker) Collection
}
}
func (c *decoratedCollection) Aggregate(ctx context.Context, pipeline interface{},
func (c *decoratedCollection) Aggregate(ctx context.Context, pipeline any,
opts ...*mopt.AggregateOptions) (cur *mongo.Cursor, err error) {
ctx, span := startSpan(ctx, aggregate)
defer func() {
@@ -175,7 +175,7 @@ func (c *decoratedCollection) BulkWrite(ctx context.Context, models []mongo.Writ
return
}
func (c *decoratedCollection) CountDocuments(ctx context.Context, filter interface{},
func (c *decoratedCollection) CountDocuments(ctx context.Context, filter any,
opts ...*mopt.CountOptions) (count int64, err error) {
ctx, span := startSpan(ctx, countDocuments)
defer func() {
@@ -195,7 +195,7 @@ func (c *decoratedCollection) CountDocuments(ctx context.Context, filter interfa
return
}
func (c *decoratedCollection) DeleteMany(ctx context.Context, filter interface{},
func (c *decoratedCollection) DeleteMany(ctx context.Context, filter any,
opts ...*mopt.DeleteOptions) (res *mongo.DeleteResult, err error) {
ctx, span := startSpan(ctx, deleteMany)
defer func() {
@@ -215,7 +215,7 @@ func (c *decoratedCollection) DeleteMany(ctx context.Context, filter interface{}
return
}
func (c *decoratedCollection) DeleteOne(ctx context.Context, filter interface{},
func (c *decoratedCollection) DeleteOne(ctx context.Context, filter any,
opts ...*mopt.DeleteOptions) (res *mongo.DeleteResult, err error) {
ctx, span := startSpan(ctx, deleteOne)
defer func() {
@@ -235,8 +235,8 @@ func (c *decoratedCollection) DeleteOne(ctx context.Context, filter interface{},
return
}
func (c *decoratedCollection) Distinct(ctx context.Context, fieldName string, filter interface{},
opts ...*mopt.DistinctOptions) (val []interface{}, err error) {
func (c *decoratedCollection) Distinct(ctx context.Context, fieldName string, filter any,
opts ...*mopt.DistinctOptions) (val []any, err error) {
ctx, span := startSpan(ctx, distinct)
defer func() {
endSpan(span, err)
@@ -275,7 +275,7 @@ func (c *decoratedCollection) EstimatedDocumentCount(ctx context.Context,
return
}
func (c *decoratedCollection) Find(ctx context.Context, filter interface{},
func (c *decoratedCollection) Find(ctx context.Context, filter any,
opts ...*mopt.FindOptions) (cur *mongo.Cursor, err error) {
ctx, span := startSpan(ctx, find)
defer func() {
@@ -295,7 +295,7 @@ func (c *decoratedCollection) Find(ctx context.Context, filter interface{},
return
}
func (c *decoratedCollection) FindOne(ctx context.Context, filter interface{},
func (c *decoratedCollection) FindOne(ctx context.Context, filter any,
opts ...*mopt.FindOneOptions) (res *mongo.SingleResult, err error) {
ctx, span := startSpan(ctx, findOne)
defer func() {
@@ -316,7 +316,7 @@ func (c *decoratedCollection) FindOne(ctx context.Context, filter interface{},
return
}
func (c *decoratedCollection) FindOneAndDelete(ctx context.Context, filter interface{},
func (c *decoratedCollection) FindOneAndDelete(ctx context.Context, filter any,
opts ...*mopt.FindOneAndDeleteOptions) (res *mongo.SingleResult, err error) {
ctx, span := startSpan(ctx, findOneAndDelete)
defer func() {
@@ -337,8 +337,8 @@ func (c *decoratedCollection) FindOneAndDelete(ctx context.Context, filter inter
return
}
func (c *decoratedCollection) FindOneAndReplace(ctx context.Context, filter interface{},
replacement interface{}, opts ...*mopt.FindOneAndReplaceOptions) (
func (c *decoratedCollection) FindOneAndReplace(ctx context.Context, filter any,
replacement any, opts ...*mopt.FindOneAndReplaceOptions) (
res *mongo.SingleResult, err error) {
ctx, span := startSpan(ctx, findOneAndReplace)
defer func() {
@@ -359,7 +359,7 @@ func (c *decoratedCollection) FindOneAndReplace(ctx context.Context, filter inte
return
}
func (c *decoratedCollection) FindOneAndUpdate(ctx context.Context, filter, update interface{},
func (c *decoratedCollection) FindOneAndUpdate(ctx context.Context, filter, update any,
opts ...*mopt.FindOneAndUpdateOptions) (res *mongo.SingleResult, err error) {
ctx, span := startSpan(ctx, findOneAndUpdate)
defer func() {
@@ -380,7 +380,7 @@ func (c *decoratedCollection) FindOneAndUpdate(ctx context.Context, filter, upda
return
}
func (c *decoratedCollection) InsertMany(ctx context.Context, documents []interface{},
func (c *decoratedCollection) InsertMany(ctx context.Context, documents []any,
opts ...*mopt.InsertManyOptions) (res *mongo.InsertManyResult, err error) {
ctx, span := startSpan(ctx, insertMany)
defer func() {
@@ -400,7 +400,7 @@ func (c *decoratedCollection) InsertMany(ctx context.Context, documents []interf
return
}
func (c *decoratedCollection) InsertOne(ctx context.Context, document interface{},
func (c *decoratedCollection) InsertOne(ctx context.Context, document any,
opts ...*mopt.InsertOneOptions) (res *mongo.InsertOneResult, err error) {
ctx, span := startSpan(ctx, insertOne)
defer func() {
@@ -420,7 +420,7 @@ func (c *decoratedCollection) InsertOne(ctx context.Context, document interface{
return
}
func (c *decoratedCollection) ReplaceOne(ctx context.Context, filter, replacement interface{},
func (c *decoratedCollection) ReplaceOne(ctx context.Context, filter, replacement any,
opts ...*mopt.ReplaceOptions) (res *mongo.UpdateResult, err error) {
ctx, span := startSpan(ctx, replaceOne)
defer func() {
@@ -440,7 +440,7 @@ func (c *decoratedCollection) ReplaceOne(ctx context.Context, filter, replacemen
return
}
func (c *decoratedCollection) UpdateByID(ctx context.Context, id, update interface{},
func (c *decoratedCollection) UpdateByID(ctx context.Context, id, update any,
opts ...*mopt.UpdateOptions) (res *mongo.UpdateResult, err error) {
ctx, span := startSpan(ctx, updateByID)
defer func() {
@@ -460,7 +460,7 @@ func (c *decoratedCollection) UpdateByID(ctx context.Context, id, update interfa
return
}
func (c *decoratedCollection) UpdateMany(ctx context.Context, filter, update interface{},
func (c *decoratedCollection) UpdateMany(ctx context.Context, filter, update any,
opts ...*mopt.UpdateOptions) (res *mongo.UpdateResult, err error) {
ctx, span := startSpan(ctx, updateMany)
defer func() {
@@ -480,7 +480,7 @@ func (c *decoratedCollection) UpdateMany(ctx context.Context, filter, update int
return
}
func (c *decoratedCollection) UpdateOne(ctx context.Context, filter, update interface{},
func (c *decoratedCollection) UpdateOne(ctx context.Context, filter, update any,
opts ...*mopt.UpdateOptions) (res *mongo.UpdateResult, err error) {
ctx, span := startSpan(ctx, updateOne)
defer func() {
@@ -501,7 +501,7 @@ func (c *decoratedCollection) UpdateOne(ctx context.Context, filter, update inte
}
func (c *decoratedCollection) logDuration(ctx context.Context, method string,
startTime time.Duration, err error, docs ...interface{}) {
startTime time.Duration, err error, docs ...any) {
duration := timex.Since(startTime)
logger := logx.WithContext(ctx).WithDuration(duration)

View File

@@ -422,7 +422,7 @@ func TestCollection_InsertMany(t *testing.T) {
brk: breaker.NewBreaker(),
}
mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "ok", Value: 1}}...))
res, err := c.InsertMany(context.Background(), []interface{}{
res, err := c.InsertMany(context.Background(), []any{
bson.D{{Key: "foo", Value: "bar"}},
bson.D{{Key: "foo", Value: "baz"}},
})
@@ -431,7 +431,7 @@ func TestCollection_InsertMany(t *testing.T) {
assert.Equal(t, 2, len(res.InsertedIDs))
c.brk = new(dropBreaker)
_, err = c.InsertMany(context.Background(), []interface{}{bson.D{{Key: "foo", Value: "bar"}}})
_, err = c.InsertMany(context.Background(), []any{bson.D{{Key: "foo", Value: "bar"}}})
assert.Equal(t, errDummy, err)
})
}

View File

@@ -96,7 +96,7 @@ func (m *Model) StartSession(opts ...*mopt.SessionOptions) (sess mongo.Session,
}
// Aggregate executes an aggregation pipeline.
func (m *Model) Aggregate(ctx context.Context, v, pipeline interface{}, opts ...*mopt.AggregateOptions) error {
func (m *Model) Aggregate(ctx context.Context, v, pipeline any, opts ...*mopt.AggregateOptions) error {
cur, err := m.Collection.Aggregate(ctx, pipeline, opts...)
if err != nil {
return err
@@ -107,7 +107,7 @@ func (m *Model) Aggregate(ctx context.Context, v, pipeline interface{}, opts ...
}
// DeleteMany deletes documents that match the filter.
func (m *Model) DeleteMany(ctx context.Context, filter interface{}, opts ...*mopt.DeleteOptions) (int64, error) {
func (m *Model) DeleteMany(ctx context.Context, filter any, opts ...*mopt.DeleteOptions) (int64, error) {
res, err := m.Collection.DeleteMany(ctx, filter, opts...)
if err != nil {
return 0, err
@@ -117,7 +117,7 @@ func (m *Model) DeleteMany(ctx context.Context, filter interface{}, opts ...*mop
}
// DeleteOne deletes the first document that matches the filter.
func (m *Model) DeleteOne(ctx context.Context, filter interface{}, opts ...*mopt.DeleteOptions) (int64, error) {
func (m *Model) DeleteOne(ctx context.Context, filter any, opts ...*mopt.DeleteOptions) (int64, error) {
res, err := m.Collection.DeleteOne(ctx, filter, opts...)
if err != nil {
return 0, err
@@ -127,7 +127,7 @@ func (m *Model) DeleteOne(ctx context.Context, filter interface{}, opts ...*mopt
}
// Find finds documents that match the filter.
func (m *Model) Find(ctx context.Context, v, filter interface{}, opts ...*mopt.FindOptions) error {
func (m *Model) Find(ctx context.Context, v, filter any, opts ...*mopt.FindOptions) error {
cur, err := m.Collection.Find(ctx, filter, opts...)
if err != nil {
return err
@@ -138,7 +138,7 @@ func (m *Model) Find(ctx context.Context, v, filter interface{}, opts ...*mopt.F
}
// FindOne finds the first document that matches the filter.
func (m *Model) FindOne(ctx context.Context, v, filter interface{}, opts ...*mopt.FindOneOptions) error {
func (m *Model) FindOne(ctx context.Context, v, filter any, opts ...*mopt.FindOneOptions) error {
res, err := m.Collection.FindOne(ctx, filter, opts...)
if err != nil {
return err
@@ -148,7 +148,7 @@ func (m *Model) FindOne(ctx context.Context, v, filter interface{}, opts ...*mop
}
// FindOneAndDelete finds a single document and deletes it.
func (m *Model) FindOneAndDelete(ctx context.Context, v, filter interface{},
func (m *Model) FindOneAndDelete(ctx context.Context, v, filter any,
opts ...*mopt.FindOneAndDeleteOptions) error {
res, err := m.Collection.FindOneAndDelete(ctx, filter, opts...)
if err != nil {
@@ -159,7 +159,7 @@ func (m *Model) FindOneAndDelete(ctx context.Context, v, filter interface{},
}
// FindOneAndReplace finds a single document and replaces it.
func (m *Model) FindOneAndReplace(ctx context.Context, v, filter, replacement interface{},
func (m *Model) FindOneAndReplace(ctx context.Context, v, filter, replacement any,
opts ...*mopt.FindOneAndReplaceOptions) error {
res, err := m.Collection.FindOneAndReplace(ctx, filter, replacement, opts...)
if err != nil {
@@ -170,7 +170,7 @@ func (m *Model) FindOneAndReplace(ctx context.Context, v, filter, replacement in
}
// FindOneAndUpdate finds a single document and updates it.
func (m *Model) FindOneAndUpdate(ctx context.Context, v, filter, update interface{},
func (m *Model) FindOneAndUpdate(ctx context.Context, v, filter, update any,
opts ...*mopt.FindOneAndUpdateOptions) error {
res, err := m.Collection.FindOneAndUpdate(ctx, filter, update, opts...)
if err != nil {
@@ -217,9 +217,9 @@ func (w *wrappedSession) CommitTransaction(ctx context.Context) (err error) {
// WithTransaction implements the mongo.Session interface.
func (w *wrappedSession) WithTransaction(
ctx context.Context,
fn func(sessCtx mongo.SessionContext) (interface{}, error),
fn func(sessCtx mongo.SessionContext) (any, error),
opts ...*mopt.TransactionOptions,
) (res interface{}, err error) {
) (res any, err error) {
ctx, span := startSpan(ctx, withTransaction)
defer func() {
endSpan(span, err)

View File

@@ -20,7 +20,7 @@ func TestModel_StartSession(t *testing.T) {
assert.Nil(t, err)
defer sess.EndSession(context.Background())
_, err = sess.WithTransaction(context.Background(), func(sessCtx mongo.SessionContext) (interface{}, error) {
_, err = sess.WithTransaction(context.Background(), func(sessCtx mongo.SessionContext) (any, error) {
_ = sessCtx.StartTransaction()
sessCtx.Client().Database("1")
sessCtx.EndSession(context.Background())
@@ -57,7 +57,7 @@ func TestModel_Aggregate(t *testing.T) {
"DBName.CollectionName",
mtest.NextBatch)
mt.AddMockResponses(find, getMore, killCursors)
var result []interface{}
var result []any
err := m.Aggregate(context.Background(), &result, mongo.Pipeline{})
assert.Nil(t, err)
assert.Equal(t, 2, len(result))
@@ -128,7 +128,7 @@ func TestModel_Find(t *testing.T) {
"DBName.CollectionName",
mtest.NextBatch)
mt.AddMockResponses(find, getMore, killCursors)
var result []interface{}
var result []any
err := m.Find(context.Background(), &result, bson.D{})
assert.Nil(t, err)
assert.Equal(t, 2, len(result))

View File

@@ -83,7 +83,7 @@ func (mm *Model) DelCache(ctx context.Context, keys ...string) error {
}
// DeleteOne deletes the document with given filter, and remove it from cache.
func (mm *Model) DeleteOne(ctx context.Context, key string, filter interface{},
func (mm *Model) DeleteOne(ctx context.Context, key string, filter any,
opts ...*mopt.DeleteOptions) (int64, error) {
val, err := mm.Model.DeleteOne(ctx, filter, opts...)
if err != nil {
@@ -98,27 +98,27 @@ func (mm *Model) DeleteOne(ctx context.Context, key string, filter interface{},
}
// DeleteOneNoCache deletes the document with given filter.
func (mm *Model) DeleteOneNoCache(ctx context.Context, filter interface{},
func (mm *Model) DeleteOneNoCache(ctx context.Context, filter any,
opts ...*mopt.DeleteOptions) (int64, error) {
return mm.Model.DeleteOne(ctx, filter, opts...)
}
// FindOne unmarshals a record into v with given key and query.
func (mm *Model) FindOne(ctx context.Context, key string, v, filter interface{},
func (mm *Model) FindOne(ctx context.Context, key string, v, filter any,
opts ...*mopt.FindOneOptions) error {
return mm.cache.TakeCtx(ctx, v, key, func(v interface{}) error {
return mm.cache.TakeCtx(ctx, v, key, func(v any) error {
return mm.Model.FindOne(ctx, v, filter, opts...)
})
}
// FindOneNoCache unmarshals a record into v with query, without cache.
func (mm *Model) FindOneNoCache(ctx context.Context, v, filter interface{},
func (mm *Model) FindOneNoCache(ctx context.Context, v, filter any,
opts ...*mopt.FindOneOptions) error {
return mm.Model.FindOne(ctx, v, filter, opts...)
}
// FindOneAndDelete deletes the document with given filter, and unmarshals it into v.
func (mm *Model) FindOneAndDelete(ctx context.Context, key string, v, filter interface{},
func (mm *Model) FindOneAndDelete(ctx context.Context, key string, v, filter any,
opts ...*mopt.FindOneAndDeleteOptions) error {
if err := mm.Model.FindOneAndDelete(ctx, v, filter, opts...); err != nil {
return err
@@ -128,14 +128,14 @@ func (mm *Model) FindOneAndDelete(ctx context.Context, key string, v, filter int
}
// FindOneAndDeleteNoCache deletes the document with given filter, and unmarshals it into v.
func (mm *Model) FindOneAndDeleteNoCache(ctx context.Context, v, filter interface{},
func (mm *Model) FindOneAndDeleteNoCache(ctx context.Context, v, filter any,
opts ...*mopt.FindOneAndDeleteOptions) error {
return mm.Model.FindOneAndDelete(ctx, v, filter, opts...)
}
// FindOneAndReplace replaces the document with given filter with replacement, and unmarshals it into v.
func (mm *Model) FindOneAndReplace(ctx context.Context, key string, v, filter interface{},
replacement interface{}, opts ...*mopt.FindOneAndReplaceOptions) error {
func (mm *Model) FindOneAndReplace(ctx context.Context, key string, v, filter any,
replacement any, opts ...*mopt.FindOneAndReplaceOptions) error {
if err := mm.Model.FindOneAndReplace(ctx, v, filter, replacement, opts...); err != nil {
return err
}
@@ -144,14 +144,14 @@ func (mm *Model) FindOneAndReplace(ctx context.Context, key string, v, filter in
}
// FindOneAndReplaceNoCache replaces the document with given filter with replacement, and unmarshals it into v.
func (mm *Model) FindOneAndReplaceNoCache(ctx context.Context, v, filter interface{},
replacement interface{}, opts ...*mopt.FindOneAndReplaceOptions) error {
func (mm *Model) FindOneAndReplaceNoCache(ctx context.Context, v, filter any,
replacement any, opts ...*mopt.FindOneAndReplaceOptions) error {
return mm.Model.FindOneAndReplace(ctx, v, filter, replacement, opts...)
}
// FindOneAndUpdate updates the document with given filter with update, and unmarshals it into v.
func (mm *Model) FindOneAndUpdate(ctx context.Context, key string, v, filter interface{},
update interface{}, opts ...*mopt.FindOneAndUpdateOptions) error {
func (mm *Model) FindOneAndUpdate(ctx context.Context, key string, v, filter any,
update any, opts ...*mopt.FindOneAndUpdateOptions) error {
if err := mm.Model.FindOneAndUpdate(ctx, v, filter, update, opts...); err != nil {
return err
}
@@ -160,18 +160,18 @@ func (mm *Model) FindOneAndUpdate(ctx context.Context, key string, v, filter int
}
// FindOneAndUpdateNoCache updates the document with given filter with update, and unmarshals it into v.
func (mm *Model) FindOneAndUpdateNoCache(ctx context.Context, v, filter interface{},
update interface{}, opts ...*mopt.FindOneAndUpdateOptions) error {
func (mm *Model) FindOneAndUpdateNoCache(ctx context.Context, v, filter any,
update any, opts ...*mopt.FindOneAndUpdateOptions) error {
return mm.Model.FindOneAndUpdate(ctx, v, filter, update, opts...)
}
// GetCache unmarshal the cache into v with given key.
func (mm *Model) GetCache(key string, v interface{}) error {
func (mm *Model) GetCache(key string, v any) error {
return mm.cache.Get(key, v)
}
// InsertOne inserts a single document into the collection, and remove the cache placeholder.
func (mm *Model) InsertOne(ctx context.Context, key string, document interface{},
func (mm *Model) InsertOne(ctx context.Context, key string, document any,
opts ...*mopt.InsertOneOptions) (*mongo.InsertOneResult, error) {
res, err := mm.Model.InsertOne(ctx, document, opts...)
if err != nil {
@@ -186,13 +186,13 @@ func (mm *Model) InsertOne(ctx context.Context, key string, document interface{}
}
// InsertOneNoCache inserts a single document into the collection.
func (mm *Model) InsertOneNoCache(ctx context.Context, document interface{},
func (mm *Model) InsertOneNoCache(ctx context.Context, document any,
opts ...*mopt.InsertOneOptions) (*mongo.InsertOneResult, error) {
return mm.Model.InsertOne(ctx, document, opts...)
}
// ReplaceOne replaces a single document in the collection, and remove the cache.
func (mm *Model) ReplaceOne(ctx context.Context, key string, filter, replacement interface{},
func (mm *Model) ReplaceOne(ctx context.Context, key string, filter, replacement any,
opts ...*mopt.ReplaceOptions) (*mongo.UpdateResult, error) {
res, err := mm.Model.ReplaceOne(ctx, filter, replacement, opts...)
if err != nil {
@@ -207,18 +207,18 @@ func (mm *Model) ReplaceOne(ctx context.Context, key string, filter, replacement
}
// ReplaceOneNoCache replaces a single document in the collection.
func (mm *Model) ReplaceOneNoCache(ctx context.Context, filter, replacement interface{},
func (mm *Model) ReplaceOneNoCache(ctx context.Context, filter, replacement any,
opts ...*mopt.ReplaceOptions) (*mongo.UpdateResult, error) {
return mm.Model.ReplaceOne(ctx, filter, replacement, opts...)
}
// SetCache sets the cache with given key and value.
func (mm *Model) SetCache(key string, v interface{}) error {
func (mm *Model) SetCache(key string, v any) error {
return mm.cache.Set(key, v)
}
// UpdateByID updates the document with given id with update, and remove the cache.
func (mm *Model) UpdateByID(ctx context.Context, key string, id, update interface{},
func (mm *Model) UpdateByID(ctx context.Context, key string, id, update any,
opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) {
res, err := mm.Model.UpdateByID(ctx, id, update, opts...)
if err != nil {
@@ -233,13 +233,13 @@ func (mm *Model) UpdateByID(ctx context.Context, key string, id, update interfac
}
// UpdateByIDNoCache updates the document with given id with update.
func (mm *Model) UpdateByIDNoCache(ctx context.Context, id, update interface{},
func (mm *Model) UpdateByIDNoCache(ctx context.Context, id, update any,
opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) {
return mm.Model.UpdateByID(ctx, id, update, opts...)
}
// UpdateMany updates the documents that match filter with update, and remove the cache.
func (mm *Model) UpdateMany(ctx context.Context, keys []string, filter, update interface{},
func (mm *Model) UpdateMany(ctx context.Context, keys []string, filter, update any,
opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) {
res, err := mm.Model.UpdateMany(ctx, filter, update, opts...)
if err != nil {
@@ -254,13 +254,13 @@ func (mm *Model) UpdateMany(ctx context.Context, keys []string, filter, update i
}
// UpdateManyNoCache updates the documents that match filter with update.
func (mm *Model) UpdateManyNoCache(ctx context.Context, filter, update interface{},
func (mm *Model) UpdateManyNoCache(ctx context.Context, filter, update any,
opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) {
return mm.Model.UpdateMany(ctx, filter, update, opts...)
}
// UpdateOne updates the first document that matches filter with update, and remove the cache.
func (mm *Model) UpdateOne(ctx context.Context, key string, filter, update interface{},
func (mm *Model) UpdateOne(ctx context.Context, key string, filter, update any,
opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) {
res, err := mm.Model.UpdateOne(ctx, filter, update, opts...)
if err != nil {
@@ -275,7 +275,7 @@ func (mm *Model) UpdateOne(ctx context.Context, key string, filter, update inter
}
// UpdateOneNoCache updates the first document that matches filter with update.
func (mm *Model) UpdateOneNoCache(ctx context.Context, filter, update interface{},
func (mm *Model) UpdateOneNoCache(ctx context.Context, filter, update any,
opts ...*mopt.UpdateOptions) (*mongo.UpdateResult, error) {
return mm.Model.UpdateOne(ctx, filter, update, opts...)
}

View File

@@ -352,13 +352,13 @@ func (s *Redis) DelCtx(ctx context.Context, keys ...string) (val int, err error)
}
// Eval is the implementation of redis eval command.
func (s *Redis) Eval(script string, keys []string, args ...interface{}) (interface{}, error) {
func (s *Redis) Eval(script string, keys []string, args ...any) (any, error) {
return s.EvalCtx(context.Background(), script, keys, args...)
}
// EvalCtx is the implementation of redis eval command.
func (s *Redis) EvalCtx(ctx context.Context, script string, keys []string,
args ...interface{}) (val interface{}, err error) {
args ...any) (val any, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
@@ -373,13 +373,13 @@ func (s *Redis) EvalCtx(ctx context.Context, script string, keys []string,
}
// EvalSha is the implementation of redis evalsha command.
func (s *Redis) EvalSha(sha string, keys []string, args ...interface{}) (interface{}, error) {
func (s *Redis) EvalSha(sha string, keys []string, args ...any) (any, error) {
return s.EvalShaCtx(context.Background(), sha, keys, args...)
}
// EvalShaCtx is the implementation of redis evalsha command.
func (s *Redis) EvalShaCtx(ctx context.Context, sha string, keys []string,
args ...interface{}) (val interface{}, err error) {
args ...any) (val any, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
@@ -934,7 +934,7 @@ func (s *Redis) HmsetCtx(ctx context.Context, key string, fieldsAndValues map[st
return err
}
vals := make(map[string]interface{}, len(fieldsAndValues))
vals := make(map[string]any, len(fieldsAndValues))
for k, v := range fieldsAndValues {
vals[k] = v
}
@@ -1131,12 +1131,12 @@ func (s *Redis) LpopCtx(ctx context.Context, key string) (val string, err error)
}
// Lpush is the implementation of redis lpush command.
func (s *Redis) Lpush(key string, values ...interface{}) (int, error) {
func (s *Redis) Lpush(key string, values ...any) (int, error) {
return s.LpushCtx(context.Background(), key, values...)
}
// LpushCtx is the implementation of redis lpush command.
func (s *Redis) LpushCtx(ctx context.Context, key string, values ...interface{}) (val int, err error) {
func (s *Redis) LpushCtx(ctx context.Context, key string, values ...any) (val int, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
@@ -1263,12 +1263,12 @@ func (s *Redis) PersistCtx(ctx context.Context, key string) (val bool, err error
}
// Pfadd is the implementation of redis pfadd command.
func (s *Redis) Pfadd(key string, values ...interface{}) (bool, error) {
func (s *Redis) Pfadd(key string, values ...any) (bool, error) {
return s.PfaddCtx(context.Background(), key, values...)
}
// PfaddCtx is the implementation of redis pfadd command.
func (s *Redis) PfaddCtx(ctx context.Context, key string, values ...interface{}) (val bool, err error) {
func (s *Redis) PfaddCtx(ctx context.Context, key string, values ...any) (val bool, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
@@ -1393,12 +1393,12 @@ func (s *Redis) RpopCtx(ctx context.Context, key string) (val string, err error)
}
// Rpush is the implementation of redis rpush command.
func (s *Redis) Rpush(key string, values ...interface{}) (int, error) {
func (s *Redis) Rpush(key string, values ...any) (int, error) {
return s.RpushCtx(context.Background(), key, values...)
}
// RpushCtx is the implementation of redis rpush command.
func (s *Redis) RpushCtx(ctx context.Context, key string, values ...interface{}) (val int, err error) {
func (s *Redis) RpushCtx(ctx context.Context, key string, values ...any) (val int, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
@@ -1418,12 +1418,12 @@ func (s *Redis) RpushCtx(ctx context.Context, key string, values ...interface{})
}
// Sadd is the implementation of redis sadd command.
func (s *Redis) Sadd(key string, values ...interface{}) (int, error) {
func (s *Redis) Sadd(key string, values ...any) (int, error) {
return s.SaddCtx(context.Background(), key, values...)
}
// SaddCtx is the implementation of redis sadd command.
func (s *Redis) SaddCtx(ctx context.Context, key string, values ...interface{}) (val int, err error) {
func (s *Redis) SaddCtx(ctx context.Context, key string, values ...any) (val int, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
@@ -1620,12 +1620,12 @@ func (s *Redis) SetnxExCtx(ctx context.Context, key, value string, seconds int)
}
// Sismember is the implementation of redis sismember command.
func (s *Redis) Sismember(key string, value interface{}) (bool, error) {
func (s *Redis) Sismember(key string, value any) (bool, error) {
return s.SismemberCtx(context.Background(), key, value)
}
// SismemberCtx is the implementation of redis sismember command.
func (s *Redis) SismemberCtx(ctx context.Context, key string, value interface{}) (val bool, err error) {
func (s *Redis) SismemberCtx(ctx context.Context, key string, value any) (val bool, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
@@ -1700,12 +1700,12 @@ func (s *Redis) SrandmemberCtx(ctx context.Context, key string, count int) (val
}
// Srem is the implementation of redis srem command.
func (s *Redis) Srem(key string, values ...interface{}) (int, error) {
func (s *Redis) Srem(key string, values ...any) (int, error) {
return s.SremCtx(context.Background(), key, values...)
}
// SremCtx is the implementation of redis srem command.
func (s *Redis) SremCtx(ctx context.Context, key string, values ...interface{}) (val int, err error) {
func (s *Redis) SremCtx(ctx context.Context, key string, values ...any) (val int, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
@@ -2127,12 +2127,12 @@ func (s *Redis) ZrankCtx(ctx context.Context, key, field string) (val int64, err
}
// Zrem is the implementation of redis zrem command.
func (s *Redis) Zrem(key string, values ...interface{}) (int, error) {
func (s *Redis) Zrem(key string, values ...any) (int, error) {
return s.ZremCtx(context.Background(), key, values...)
}
// ZremCtx is the implementation of redis zrem command.
func (s *Redis) ZremCtx(ctx context.Context, key string, values ...interface{}) (val int, err error) {
func (s *Redis) ZremCtx(ctx context.Context, key string, values ...any) (val int, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
@@ -2770,7 +2770,7 @@ func toFloatPairs(vals []red.Z) []FloatPair {
return pairs
}
func toStrings(vals []interface{}) []string {
func toStrings(vals []any) []string {
ret := make([]string, len(vals))
for i, val := range vals {

View File

@@ -1518,7 +1518,7 @@ func TestRedis_Zscan(t *testing.T) {
}
func TestRedisToStrings(t *testing.T) {
vals := toStrings([]interface{}{1, 2})
vals := toStrings([]any{1, 2})
assert.EqualValues(t, []string{"1", "2"}, vals)
}

View File

@@ -29,17 +29,17 @@ type (
// ExecCtxFn defines the sql exec method.
ExecCtxFn func(ctx context.Context, conn sqlx.SqlConn) (sql.Result, error)
// IndexQueryFn defines the query method that based on unique indexes.
IndexQueryFn func(conn sqlx.SqlConn, v interface{}) (interface{}, error)
IndexQueryFn func(conn sqlx.SqlConn, v any) (any, error)
// IndexQueryCtxFn defines the query method that based on unique indexes.
IndexQueryCtxFn func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (interface{}, error)
IndexQueryCtxFn func(ctx context.Context, conn sqlx.SqlConn, v any) (any, error)
// PrimaryQueryFn defines the query method that based on primary keys.
PrimaryQueryFn func(conn sqlx.SqlConn, v, primary interface{}) error
PrimaryQueryFn func(conn sqlx.SqlConn, v, primary any) error
// PrimaryQueryCtxFn defines the query method that based on primary keys.
PrimaryQueryCtxFn func(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error
PrimaryQueryCtxFn func(ctx context.Context, conn sqlx.SqlConn, v, primary any) error
// QueryFn defines the query method.
QueryFn func(conn sqlx.SqlConn, v interface{}) error
QueryFn func(conn sqlx.SqlConn, v any) error
// QueryCtxFn defines the query method.
QueryCtxFn func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error
QueryCtxFn func(ctx context.Context, conn sqlx.SqlConn, v any) error
// A CachedConn is a DB connection with cache capability.
CachedConn struct {
@@ -79,12 +79,12 @@ func (cc CachedConn) DelCacheCtx(ctx context.Context, keys ...string) error {
}
// GetCache unmarshals cache with given key into v.
func (cc CachedConn) GetCache(key string, v interface{}) error {
func (cc CachedConn) GetCache(key string, v any) error {
return cc.GetCacheCtx(context.Background(), key, v)
}
// GetCacheCtx unmarshals cache with given key into v.
func (cc CachedConn) GetCacheCtx(ctx context.Context, key string, v interface{}) error {
func (cc CachedConn) GetCacheCtx(ctx context.Context, key string, v any) error {
return cc.cache.GetCtx(ctx, key, v)
}
@@ -112,38 +112,38 @@ func (cc CachedConn) ExecCtx(ctx context.Context, exec ExecCtxFn, keys ...string
}
// ExecNoCache runs exec with given sql statement, without affecting cache.
func (cc CachedConn) ExecNoCache(q string, args ...interface{}) (sql.Result, error) {
func (cc CachedConn) ExecNoCache(q string, args ...any) (sql.Result, error) {
return cc.ExecNoCacheCtx(context.Background(), q, args...)
}
// ExecNoCacheCtx runs exec with given sql statement, without affecting cache.
func (cc CachedConn) ExecNoCacheCtx(ctx context.Context, q string, args ...interface{}) (
func (cc CachedConn) ExecNoCacheCtx(ctx context.Context, q string, args ...any) (
sql.Result, error) {
return cc.db.ExecCtx(ctx, q, args...)
}
// QueryRow unmarshals into v with given key and query func.
func (cc CachedConn) QueryRow(v interface{}, key string, query QueryFn) error {
queryCtx := func(_ context.Context, conn sqlx.SqlConn, v interface{}) error {
func (cc CachedConn) QueryRow(v any, key string, query QueryFn) error {
queryCtx := func(_ context.Context, conn sqlx.SqlConn, v any) error {
return query(conn, v)
}
return cc.QueryRowCtx(context.Background(), v, key, queryCtx)
}
// QueryRowCtx unmarshals into v with given key and query func.
func (cc CachedConn) QueryRowCtx(ctx context.Context, v interface{}, key string, query QueryCtxFn) error {
return cc.cache.TakeCtx(ctx, v, key, func(v interface{}) error {
func (cc CachedConn) QueryRowCtx(ctx context.Context, v any, key string, query QueryCtxFn) error {
return cc.cache.TakeCtx(ctx, v, key, func(v any) error {
return query(ctx, cc.db, v)
})
}
// QueryRowIndex unmarshals into v with given key.
func (cc CachedConn) QueryRowIndex(v interface{}, key string, keyer func(primary interface{}) string,
func (cc CachedConn) QueryRowIndex(v any, key string, keyer func(primary any) string,
indexQuery IndexQueryFn, primaryQuery PrimaryQueryFn) error {
indexQueryCtx := func(_ context.Context, conn sqlx.SqlConn, v interface{}) (interface{}, error) {
indexQueryCtx := func(_ context.Context, conn sqlx.SqlConn, v any) (any, error) {
return indexQuery(conn, v)
}
primaryQueryCtx := func(_ context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
primaryQueryCtx := func(_ context.Context, conn sqlx.SqlConn, v, primary any) error {
return primaryQuery(conn, v, primary)
}
@@ -151,14 +151,14 @@ func (cc CachedConn) QueryRowIndex(v interface{}, key string, keyer func(primary
}
// QueryRowIndexCtx unmarshals into v with given key.
func (cc CachedConn) QueryRowIndexCtx(ctx context.Context, v interface{}, key string,
keyer func(primary interface{}) string, indexQuery IndexQueryCtxFn,
func (cc CachedConn) QueryRowIndexCtx(ctx context.Context, v any, key string,
keyer func(primary any) string, indexQuery IndexQueryCtxFn,
primaryQuery PrimaryQueryCtxFn) error {
var primaryKey interface{}
var primaryKey any
var found bool
if err := cc.cache.TakeWithExpireCtx(ctx, &primaryKey, key,
func(val interface{}, expire time.Duration) (err error) {
func(val any, expire time.Duration) (err error) {
primaryKey, err = indexQuery(ctx, cc.db, v)
if err != nil {
return
@@ -175,42 +175,42 @@ func (cc CachedConn) QueryRowIndexCtx(ctx context.Context, v interface{}, key st
return nil
}
return cc.cache.TakeCtx(ctx, v, keyer(primaryKey), func(v interface{}) error {
return cc.cache.TakeCtx(ctx, v, keyer(primaryKey), func(v any) error {
return primaryQuery(ctx, cc.db, v, primaryKey)
})
}
// QueryRowNoCache unmarshals into v with given statement.
func (cc CachedConn) QueryRowNoCache(v interface{}, q string, args ...interface{}) error {
func (cc CachedConn) QueryRowNoCache(v any, q string, args ...any) error {
return cc.QueryRowNoCacheCtx(context.Background(), v, q, args...)
}
// QueryRowNoCacheCtx unmarshals into v with given statement.
func (cc CachedConn) QueryRowNoCacheCtx(ctx context.Context, v interface{}, q string,
args ...interface{}) error {
func (cc CachedConn) QueryRowNoCacheCtx(ctx context.Context, v any, q string,
args ...any) error {
return cc.db.QueryRowCtx(ctx, v, q, args...)
}
// QueryRowsNoCache unmarshals into v with given statement.
// It doesn't use cache, because it might cause consistency problem.
func (cc CachedConn) QueryRowsNoCache(v interface{}, q string, args ...interface{}) error {
func (cc CachedConn) QueryRowsNoCache(v any, q string, args ...any) error {
return cc.QueryRowsNoCacheCtx(context.Background(), v, q, args...)
}
// QueryRowsNoCacheCtx unmarshals into v with given statement.
// It doesn't use cache, because it might cause consistency problem.
func (cc CachedConn) QueryRowsNoCacheCtx(ctx context.Context, v interface{}, q string,
args ...interface{}) error {
func (cc CachedConn) QueryRowsNoCacheCtx(ctx context.Context, v any, q string,
args ...any) error {
return cc.db.QueryRowsCtx(ctx, v, q, args...)
}
// SetCache sets v into cache with given key.
func (cc CachedConn) SetCache(key string, val interface{}) error {
func (cc CachedConn) SetCache(key string, val any) error {
return cc.SetCacheCtx(context.Background(), key, val)
}
// SetCacheCtx sets v into cache with given key.
func (cc CachedConn) SetCacheCtx(ctx context.Context, key string, val interface{}) error {
func (cc CachedConn) SetCacheCtx(ctx context.Context, key string, val any) error {
return cc.cache.SetCtx(ctx, key, val)
}

View File

@@ -57,7 +57,7 @@ func TestStat(t *testing.T) {
for i := 0; i < 10; i++ {
var str string
err = c.QueryRow(&str, "name", func(conn sqlx.SqlConn, v interface{}) error {
err = c.QueryRow(&str, "name", func(conn sqlx.SqlConn, v any) error {
*v.(*string) = "zero"
return nil
})
@@ -87,24 +87,24 @@ func TestCachedConn_QueryRowIndex_NoCache(t *testing.T) {
}, cache.WithExpiry(time.Second*10))
var str string
err = c.QueryRowIndex(&str, "index", func(s interface{}) string {
err = c.QueryRowIndex(&str, "index", func(s any) string {
return fmt.Sprintf("%s/1234", s)
}, func(conn sqlx.SqlConn, v interface{}) (interface{}, error) {
}, func(conn sqlx.SqlConn, v any) (any, error) {
*v.(*string) = "zero"
return "primary", errors.New("foo")
}, func(conn sqlx.SqlConn, v, pri interface{}) error {
}, func(conn sqlx.SqlConn, v, pri any) error {
assert.Equal(t, "primary", pri)
*v.(*string) = "xin"
return nil
})
assert.NotNil(t, err)
err = c.QueryRowIndex(&str, "index", func(s interface{}) string {
err = c.QueryRowIndex(&str, "index", func(s any) string {
return fmt.Sprintf("%s/1234", s)
}, func(conn sqlx.SqlConn, v interface{}) (interface{}, error) {
}, func(conn sqlx.SqlConn, v any) (any, error) {
*v.(*string) = "zero"
return "primary", nil
}, func(conn sqlx.SqlConn, v, pri interface{}) error {
}, func(conn sqlx.SqlConn, v, pri any) error {
assert.Equal(t, "primary", pri)
*v.(*string) = "xin"
return nil
@@ -130,12 +130,12 @@ func TestCachedConn_QueryRowIndex_HasCache(t *testing.T) {
var str string
r.Set("index", `"primary"`)
err = c.QueryRowIndex(&str, "index", func(s interface{}) string {
err = c.QueryRowIndex(&str, "index", func(s any) string {
return fmt.Sprintf("%s/1234", s)
}, func(conn sqlx.SqlConn, v interface{}) (interface{}, error) {
}, func(conn sqlx.SqlConn, v any) (any, error) {
assert.Fail(t, "should not go here")
return "primary", nil
}, func(conn sqlx.SqlConn, v, primary interface{}) error {
}, func(conn sqlx.SqlConn, v, primary any) error {
*v.(*string) = "xin"
assert.Equal(t, "primary", primary)
return nil
@@ -163,7 +163,7 @@ func TestCachedConn_QueryRowIndex_HasCache_IntPrimary(t *testing.T) {
)
tests := []struct {
name string
primary interface{}
primary any
primaryCache string
}{
{
@@ -220,12 +220,12 @@ func TestCachedConn_QueryRowIndex_HasCache_IntPrimary(t *testing.T) {
var str string
r.Set("index", test.primaryCache)
err = c.QueryRowIndex(&str, "index", func(s interface{}) string {
err = c.QueryRowIndex(&str, "index", func(s any) string {
return fmt.Sprintf("%v/1234", s)
}, func(conn sqlx.SqlConn, v interface{}) (interface{}, error) {
}, func(conn sqlx.SqlConn, v any) (any, error) {
assert.Fail(t, "should not go here")
return test.primary, nil
}, func(conn sqlx.SqlConn, v, primary interface{}) error {
}, func(conn sqlx.SqlConn, v, primary any) error {
*v.(*string) = "xin"
assert.Equal(t, primary, primary)
return nil
@@ -260,12 +260,12 @@ func TestCachedConn_QueryRowIndex_HasWrongCache(t *testing.T) {
var str string
r.Set(k, v)
err = c.QueryRowIndex(&str, "index", func(s interface{}) string {
err = c.QueryRowIndex(&str, "index", func(s any) string {
return fmt.Sprintf("%s/1234", s)
}, func(conn sqlx.SqlConn, v interface{}) (interface{}, error) {
}, func(conn sqlx.SqlConn, v any) (any, error) {
*v.(*string) = "xin"
return "primary", nil
}, func(conn sqlx.SqlConn, v, primary interface{}) error {
}, func(conn sqlx.SqlConn, v, primary any) error {
*v.(*string) = "xin"
assert.Equal(t, "primary", primary)
return nil
@@ -292,7 +292,7 @@ func TestStatCacheFails(t *testing.T) {
for i := 0; i < 20; i++ {
var str string
err := c.QueryRow(&str, "name", func(conn sqlx.SqlConn, v interface{}) error {
err := c.QueryRow(&str, "name", func(conn sqlx.SqlConn, v any) error {
return errors.New("db failed")
})
assert.NotNil(t, err)
@@ -314,7 +314,7 @@ func TestStatDbFails(t *testing.T) {
for i := 0; i < 20; i++ {
var str string
err = c.QueryRow(&str, "name", func(conn sqlx.SqlConn, v interface{}) error {
err = c.QueryRow(&str, "name", func(conn sqlx.SqlConn, v any) error {
return errors.New("db failed")
})
assert.NotNil(t, err)
@@ -339,7 +339,7 @@ func TestStatFromMemory(t *testing.T) {
wait.Add(4)
go func() {
var str string
err := c.QueryRow(&str, "name", func(conn sqlx.SqlConn, v interface{}) error {
err := c.QueryRow(&str, "name", func(conn sqlx.SqlConn, v any) error {
*v.(*string) = "zero"
return nil
})
@@ -355,7 +355,7 @@ func TestStatFromMemory(t *testing.T) {
go func() {
var str string
wait.Done()
err := c.QueryRow(&str, "name", func(conn sqlx.SqlConn, v interface{}) error {
err := c.QueryRow(&str, "name", func(conn sqlx.SqlConn, v any) error {
*v.(*string) = "zero"
return nil
})
@@ -368,7 +368,7 @@ func TestStatFromMemory(t *testing.T) {
for i := 0; i < 5; i++ {
go func() {
var str string
err := c.QueryRow(&str, "name", func(conn sqlx.SqlConn, v interface{}) error {
err := c.QueryRow(&str, "name", func(conn sqlx.SqlConn, v any) error {
*v.(*string) = "zero"
return nil
})
@@ -397,7 +397,7 @@ func TestCachedConnQueryRow(t *testing.T) {
var user string
var ran bool
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*30))
err = c.QueryRow(&user, key, func(conn sqlx.SqlConn, v interface{}) error {
err = c.QueryRow(&user, key, func(conn sqlx.SqlConn, v any) error {
ran = true
user = value
return nil
@@ -426,7 +426,7 @@ func TestCachedConnQueryRowFromCache(t *testing.T) {
var ran bool
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*30))
assert.Nil(t, c.SetCache(key, value))
err = c.QueryRow(&user, key, func(conn sqlx.SqlConn, v interface{}) error {
err = c.QueryRow(&user, key, func(conn sqlx.SqlConn, v any) error {
ran = true
user = value
return nil
@@ -452,7 +452,7 @@ func TestQueryRowNotFound(t *testing.T) {
var ran int
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*30))
for i := 0; i < 20; i++ {
err = c.QueryRow(&user, key, func(conn sqlx.SqlConn, v interface{}) error {
err = c.QueryRow(&user, key, func(conn sqlx.SqlConn, v any) error {
ran++
return sql.ErrNoRows
})
@@ -551,7 +551,7 @@ func TestQueryRowNoCache(t *testing.T) {
)
var user string
var ran bool
conn := dummySqlConn{queryRow: func(v interface{}, q string, args ...interface{}) error {
conn := dummySqlConn{queryRow: func(v any, q string, args ...any) error {
user = value
ran = true
return nil
@@ -583,10 +583,10 @@ func resetStats() {
}
type dummySqlConn struct {
queryRow func(interface{}, string, ...interface{}) error
queryRow func(any, string, ...any) error
}
func (d dummySqlConn) ExecCtx(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
func (d dummySqlConn) ExecCtx(ctx context.Context, query string, args ...any) (sql.Result, error) {
return nil, nil
}
@@ -594,15 +594,15 @@ func (d dummySqlConn) PrepareCtx(ctx context.Context, query string) (sqlx.StmtSe
return nil, nil
}
func (d dummySqlConn) QueryRowPartialCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error {
func (d dummySqlConn) QueryRowPartialCtx(ctx context.Context, v any, query string, args ...any) error {
return nil
}
func (d dummySqlConn) QueryRowsCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error {
func (d dummySqlConn) QueryRowsCtx(ctx context.Context, v any, query string, args ...any) error {
return nil
}
func (d dummySqlConn) QueryRowsPartialCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error {
func (d dummySqlConn) QueryRowsPartialCtx(ctx context.Context, v any, query string, args ...any) error {
return nil
}
@@ -610,7 +610,7 @@ func (d dummySqlConn) TransactCtx(ctx context.Context, fn func(context.Context,
return nil
}
func (d dummySqlConn) Exec(query string, args ...interface{}) (sql.Result, error) {
func (d dummySqlConn) Exec(query string, args ...any) (sql.Result, error) {
return nil, nil
}
@@ -618,26 +618,26 @@ func (d dummySqlConn) Prepare(query string) (sqlx.StmtSession, error) {
return nil, nil
}
func (d dummySqlConn) QueryRow(v interface{}, query string, args ...interface{}) error {
func (d dummySqlConn) QueryRow(v any, query string, args ...any) error {
return d.QueryRowCtx(context.Background(), v, query, args...)
}
func (d dummySqlConn) QueryRowCtx(_ context.Context, v interface{}, query string, args ...interface{}) error {
func (d dummySqlConn) QueryRowCtx(_ context.Context, v any, query string, args ...any) error {
if d.queryRow != nil {
return d.queryRow(v, query, args...)
}
return nil
}
func (d dummySqlConn) QueryRowPartial(v interface{}, query string, args ...interface{}) error {
func (d dummySqlConn) QueryRowPartial(v any, query string, args ...any) error {
return nil
}
func (d dummySqlConn) QueryRows(v interface{}, query string, args ...interface{}) error {
func (d dummySqlConn) QueryRows(v any, query string, args ...any) error {
return nil
}
func (d dummySqlConn) QueryRowsPartial(v interface{}, query string, args ...interface{}) error {
func (d dummySqlConn) QueryRowsPartial(v any, query string, args ...any) error {
return nil
}
@@ -656,20 +656,20 @@ type trackedConn struct {
transactValue bool
}
func (c *trackedConn) Exec(query string, args ...interface{}) (sql.Result, error) {
func (c *trackedConn) Exec(query string, args ...any) (sql.Result, error) {
return c.ExecCtx(context.Background(), query, args...)
}
func (c *trackedConn) ExecCtx(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
func (c *trackedConn) ExecCtx(ctx context.Context, query string, args ...any) (sql.Result, error) {
c.execValue = true
return c.dummySqlConn.ExecCtx(ctx, query, args...)
}
func (c *trackedConn) QueryRows(v interface{}, query string, args ...interface{}) error {
func (c *trackedConn) QueryRows(v any, query string, args ...any) error {
return c.QueryRowsCtx(context.Background(), v, query, args...)
}
func (c *trackedConn) QueryRowsCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error {
func (c *trackedConn) QueryRowsCtx(ctx context.Context, v any, query string, args ...any) error {
c.queryRowsValue = true
return c.dummySqlConn.QueryRowsCtx(ctx, v, query, args...)
}

View File

@@ -64,7 +64,7 @@ func (bi *BulkInserter) Flush() {
}
// Insert inserts given args.
func (bi *BulkInserter) Insert(args ...interface{}) error {
func (bi *BulkInserter) Insert(args ...any) error {
value, err := format(bi.stmt.valueFormat, args...)
if err != nil {
return err
@@ -110,12 +110,12 @@ type dbInserter struct {
resultHandler ResultHandler
}
func (in *dbInserter) AddTask(task interface{}) bool {
func (in *dbInserter) AddTask(task any) bool {
in.values = append(in.values, task.(string))
return len(in.values) >= maxBulkRows
}
func (in *dbInserter) Execute(bulk interface{}) {
func (in *dbInserter) Execute(bulk any) {
values := bulk.([]string)
if len(values) == 0 {
return
@@ -135,7 +135,7 @@ func (in *dbInserter) Execute(bulk interface{}) {
}
}
func (in *dbInserter) RemoveAll() interface{} {
func (in *dbInserter) RemoveAll() any {
values := in.values
in.values = nil
return values

View File

@@ -14,11 +14,11 @@ import (
type mockedConn struct {
query string
args []interface{}
args []any
execErr error
}
func (c *mockedConn) ExecCtx(_ context.Context, query string, args ...interface{}) (sql.Result, error) {
func (c *mockedConn) ExecCtx(_ context.Context, query string, args ...any) (sql.Result, error) {
c.query = query
c.args = args
return nil, c.execErr
@@ -28,19 +28,19 @@ func (c *mockedConn) PrepareCtx(ctx context.Context, query string) (StmtSession,
panic("implement me")
}
func (c *mockedConn) QueryRowCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error {
func (c *mockedConn) QueryRowCtx(ctx context.Context, v any, query string, args ...any) error {
panic("implement me")
}
func (c *mockedConn) QueryRowPartialCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error {
func (c *mockedConn) QueryRowPartialCtx(ctx context.Context, v any, query string, args ...any) error {
panic("implement me")
}
func (c *mockedConn) QueryRowsCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error {
func (c *mockedConn) QueryRowsCtx(ctx context.Context, v any, query string, args ...any) error {
panic("implement me")
}
func (c *mockedConn) QueryRowsPartialCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error {
func (c *mockedConn) QueryRowsPartialCtx(ctx context.Context, v any, query string, args ...any) error {
panic("implement me")
}
@@ -48,7 +48,7 @@ func (c *mockedConn) TransactCtx(ctx context.Context, fn func(context.Context, S
panic("should not called")
}
func (c *mockedConn) Exec(query string, args ...interface{}) (sql.Result, error) {
func (c *mockedConn) Exec(query string, args ...any) (sql.Result, error) {
return c.ExecCtx(context.Background(), query, args...)
}
@@ -56,19 +56,19 @@ func (c *mockedConn) Prepare(query string) (StmtSession, error) {
panic("should not called")
}
func (c *mockedConn) QueryRow(v interface{}, query string, args ...interface{}) error {
func (c *mockedConn) QueryRow(v any, query string, args ...any) error {
panic("should not called")
}
func (c *mockedConn) QueryRowPartial(v interface{}, query string, args ...interface{}) error {
func (c *mockedConn) QueryRowPartial(v any, query string, args ...any) error {
panic("should not called")
}
func (c *mockedConn) QueryRows(v interface{}, query string, args ...interface{}) error {
func (c *mockedConn) QueryRows(v any, query string, args ...any) error {
panic("should not called")
}
func (c *mockedConn) QueryRowsPartial(v interface{}, query string, args ...interface{}) error {
func (c *mockedConn) QueryRowsPartial(v any, query string, args ...any) error {
panic("should not called")
}

View File

@@ -25,13 +25,13 @@ type rowsScanner interface {
Columns() ([]string, error)
Err() error
Next() bool
Scan(v ...interface{}) error
Scan(v ...any) error
}
func getTaggedFieldValueMap(v reflect.Value) (map[string]interface{}, error) {
func getTaggedFieldValueMap(v reflect.Value) (map[string]any, error) {
rt := mapping.Deref(v.Type())
size := rt.NumField()
result := make(map[string]interface{}, size)
result := make(map[string]any, size)
for i := 0; i < size; i++ {
key := parseTagName(rt.Field(i))
@@ -61,7 +61,7 @@ func getTaggedFieldValueMap(v reflect.Value) (map[string]interface{}, error) {
return result, nil
}
func mapStructFieldsIntoSlice(v reflect.Value, columns []string, strict bool) ([]interface{}, error) {
func mapStructFieldsIntoSlice(v reflect.Value, columns []string, strict bool) ([]any, error) {
fields := unwrapFields(v)
if strict && len(columns) < len(fields) {
return nil, ErrNotMatchDestination
@@ -72,7 +72,7 @@ func mapStructFieldsIntoSlice(v reflect.Value, columns []string, strict bool) ([
return nil, err
}
values := make([]interface{}, len(columns))
values := make([]any, len(columns))
if len(taggedMap) == 0 {
for i := 0; i < len(values); i++ {
valueField := fields[i]
@@ -98,7 +98,7 @@ func mapStructFieldsIntoSlice(v reflect.Value, columns []string, strict bool) ([
if tagged, ok := taggedMap[column]; ok {
values[i] = tagged
} else {
var anonymous interface{}
var anonymous any
values[i] = &anonymous
}
}
@@ -117,7 +117,7 @@ func parseTagName(field reflect.StructField) string {
return options[0]
}
func unmarshalRow(v interface{}, scanner rowsScanner, strict bool) error {
func unmarshalRow(v any, scanner rowsScanner, strict bool) error {
if !scanner.Next() {
if err := scanner.Err(); err != nil {
return err
@@ -160,7 +160,7 @@ func unmarshalRow(v interface{}, scanner rowsScanner, strict bool) error {
}
}
func unmarshalRows(v interface{}, scanner rowsScanner, strict bool) error {
func unmarshalRows(v any, scanner rowsScanner, strict bool) error {
rv := reflect.ValueOf(v)
if err := mapping.ValidatePtr(&rv); err != nil {
return err
@@ -180,7 +180,7 @@ func unmarshalRows(v interface{}, scanner rowsScanner, strict bool) error {
rve.Set(reflect.Append(rve, reflect.Indirect(item)))
}
}
fillFn := func(value interface{}) error {
fillFn := func(value any) error {
if rve.CanSet() {
if err := scanner.Scan(value); err != nil {
return err

View File

@@ -1080,6 +1080,6 @@ func (m *mockedScanner) Next() bool {
return false
}
func (m *mockedScanner) Scan(v ...interface{}) error {
func (m *mockedScanner) Scan(v ...any) error {
return m.scanErr
}

View File

@@ -17,18 +17,18 @@ var ErrNotFound = sql.ErrNoRows
type (
// Session stands for raw connections or transaction sessions
Session interface {
Exec(query string, args ...interface{}) (sql.Result, error)
ExecCtx(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Exec(query string, args ...any) (sql.Result, error)
ExecCtx(ctx context.Context, query string, args ...any) (sql.Result, error)
Prepare(query string) (StmtSession, error)
PrepareCtx(ctx context.Context, query string) (StmtSession, error)
QueryRow(v interface{}, query string, args ...interface{}) error
QueryRowCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error
QueryRowPartial(v interface{}, query string, args ...interface{}) error
QueryRowPartialCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error
QueryRows(v interface{}, query string, args ...interface{}) error
QueryRowsCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error
QueryRowsPartial(v interface{}, query string, args ...interface{}) error
QueryRowsPartialCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error
QueryRow(v any, query string, args ...any) error
QueryRowCtx(ctx context.Context, v any, query string, args ...any) error
QueryRowPartial(v any, query string, args ...any) error
QueryRowPartialCtx(ctx context.Context, v any, query string, args ...any) error
QueryRows(v any, query string, args ...any) error
QueryRowsCtx(ctx context.Context, v any, query string, args ...any) error
QueryRowsPartial(v any, query string, args ...any) error
QueryRowsPartialCtx(ctx context.Context, v any, query string, args ...any) error
}
// SqlConn only stands for raw connections, so Transact method can be called.
@@ -47,16 +47,16 @@ type (
// StmtSession interface represents a session that can be used to execute statements.
StmtSession interface {
Close() error
Exec(args ...interface{}) (sql.Result, error)
ExecCtx(ctx context.Context, args ...interface{}) (sql.Result, error)
QueryRow(v interface{}, args ...interface{}) error
QueryRowCtx(ctx context.Context, v interface{}, args ...interface{}) error
QueryRowPartial(v interface{}, args ...interface{}) error
QueryRowPartialCtx(ctx context.Context, v interface{}, args ...interface{}) error
QueryRows(v interface{}, args ...interface{}) error
QueryRowsCtx(ctx context.Context, v interface{}, args ...interface{}) error
QueryRowsPartial(v interface{}, args ...interface{}) error
QueryRowsPartialCtx(ctx context.Context, v interface{}, args ...interface{}) error
Exec(args ...any) (sql.Result, error)
ExecCtx(ctx context.Context, args ...any) (sql.Result, error)
QueryRow(v any, args ...any) error
QueryRowCtx(ctx context.Context, v any, args ...any) error
QueryRowPartial(v any, args ...any) error
QueryRowPartialCtx(ctx context.Context, v any, args ...any) error
QueryRows(v any, args ...any) error
QueryRowsCtx(ctx context.Context, v any, args ...any) error
QueryRowsPartial(v any, args ...any) error
QueryRowsPartialCtx(ctx context.Context, v any, args ...any) error
}
// thread-safe
@@ -73,10 +73,10 @@ type (
connProvider func() (*sql.DB, error)
sessionConn interface {
Exec(query string, args ...interface{}) (sql.Result, error)
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
Exec(query string, args ...any) (sql.Result, error)
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
Query(query string, args ...any) (*sql.Rows, error)
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}
statement struct {
@@ -85,10 +85,10 @@ type (
}
stmtConn interface {
Exec(args ...interface{}) (sql.Result, error)
ExecContext(ctx context.Context, args ...interface{}) (sql.Result, error)
Query(args ...interface{}) (*sql.Rows, error)
QueryContext(ctx context.Context, args ...interface{}) (*sql.Rows, error)
Exec(args ...any) (sql.Result, error)
ExecContext(ctx context.Context, args ...any) (sql.Result, error)
Query(args ...any) (*sql.Rows, error)
QueryContext(ctx context.Context, args ...any) (*sql.Rows, error)
}
)
@@ -131,11 +131,11 @@ func NewSqlConnFromDB(db *sql.DB, opts ...SqlOption) SqlConn {
return conn
}
func (db *commonSqlConn) Exec(q string, args ...interface{}) (result sql.Result, err error) {
func (db *commonSqlConn) Exec(q string, args ...any) (result sql.Result, err error) {
return db.ExecCtx(context.Background(), q, args...)
}
func (db *commonSqlConn) ExecCtx(ctx context.Context, q string, args ...interface{}) (
func (db *commonSqlConn) ExecCtx(ctx context.Context, q string, args ...any) (
result sql.Result, err error) {
ctx, span := startSpan(ctx, "Exec")
defer func() {
@@ -196,12 +196,12 @@ func (db *commonSqlConn) PrepareCtx(ctx context.Context, query string) (stmt Stm
return
}
func (db *commonSqlConn) QueryRow(v interface{}, q string, args ...interface{}) error {
func (db *commonSqlConn) QueryRow(v any, q string, args ...any) error {
return db.QueryRowCtx(context.Background(), v, q, args...)
}
func (db *commonSqlConn) QueryRowCtx(ctx context.Context, v interface{}, q string,
args ...interface{}) (err error) {
func (db *commonSqlConn) QueryRowCtx(ctx context.Context, v any, q string,
args ...any) (err error) {
ctx, span := startSpan(ctx, "QueryRow")
defer func() {
endSpan(span, err)
@@ -212,12 +212,12 @@ func (db *commonSqlConn) QueryRowCtx(ctx context.Context, v interface{}, q strin
}, q, args...)
}
func (db *commonSqlConn) QueryRowPartial(v interface{}, q string, args ...interface{}) error {
func (db *commonSqlConn) QueryRowPartial(v any, q string, args ...any) error {
return db.QueryRowPartialCtx(context.Background(), v, q, args...)
}
func (db *commonSqlConn) QueryRowPartialCtx(ctx context.Context, v interface{},
q string, args ...interface{}) (err error) {
func (db *commonSqlConn) QueryRowPartialCtx(ctx context.Context, v any,
q string, args ...any) (err error) {
ctx, span := startSpan(ctx, "QueryRowPartial")
defer func() {
endSpan(span, err)
@@ -228,12 +228,12 @@ func (db *commonSqlConn) QueryRowPartialCtx(ctx context.Context, v interface{},
}, q, args...)
}
func (db *commonSqlConn) QueryRows(v interface{}, q string, args ...interface{}) error {
func (db *commonSqlConn) QueryRows(v any, q string, args ...any) error {
return db.QueryRowsCtx(context.Background(), v, q, args...)
}
func (db *commonSqlConn) QueryRowsCtx(ctx context.Context, v interface{}, q string,
args ...interface{}) (err error) {
func (db *commonSqlConn) QueryRowsCtx(ctx context.Context, v any, q string,
args ...any) (err error) {
ctx, span := startSpan(ctx, "QueryRows")
defer func() {
endSpan(span, err)
@@ -244,12 +244,12 @@ func (db *commonSqlConn) QueryRowsCtx(ctx context.Context, v interface{}, q stri
}, q, args...)
}
func (db *commonSqlConn) QueryRowsPartial(v interface{}, q string, args ...interface{}) error {
func (db *commonSqlConn) QueryRowsPartial(v any, q string, args ...any) error {
return db.QueryRowsPartialCtx(context.Background(), v, q, args...)
}
func (db *commonSqlConn) QueryRowsPartialCtx(ctx context.Context, v interface{},
q string, args ...interface{}) (err error) {
func (db *commonSqlConn) QueryRowsPartialCtx(ctx context.Context, v any,
q string, args ...any) (err error) {
ctx, span := startSpan(ctx, "QueryRowsPartial")
defer func() {
endSpan(span, err)
@@ -296,7 +296,7 @@ func (db *commonSqlConn) acceptable(err error) bool {
}
func (db *commonSqlConn) queryRows(ctx context.Context, scanner func(*sql.Rows) error,
q string, args ...interface{}) (err error) {
q string, args ...any) (err error) {
var qerr error
err = db.brk.DoWithAcceptable(func() error {
conn, err := db.connProv()
@@ -323,11 +323,11 @@ func (s statement) Close() error {
return s.stmt.Close()
}
func (s statement) Exec(args ...interface{}) (sql.Result, error) {
func (s statement) Exec(args ...any) (sql.Result, error) {
return s.ExecCtx(context.Background(), args...)
}
func (s statement) ExecCtx(ctx context.Context, args ...interface{}) (result sql.Result, err error) {
func (s statement) ExecCtx(ctx context.Context, args ...any) (result sql.Result, err error) {
ctx, span := startSpan(ctx, "Exec")
defer func() {
endSpan(span, err)
@@ -336,11 +336,11 @@ func (s statement) ExecCtx(ctx context.Context, args ...interface{}) (result sql
return execStmt(ctx, s.stmt, s.query, args...)
}
func (s statement) QueryRow(v interface{}, args ...interface{}) error {
func (s statement) QueryRow(v any, args ...any) error {
return s.QueryRowCtx(context.Background(), v, args...)
}
func (s statement) QueryRowCtx(ctx context.Context, v interface{}, args ...interface{}) (err error) {
func (s statement) QueryRowCtx(ctx context.Context, v any, args ...any) (err error) {
ctx, span := startSpan(ctx, "QueryRow")
defer func() {
endSpan(span, err)
@@ -351,11 +351,11 @@ func (s statement) QueryRowCtx(ctx context.Context, v interface{}, args ...inter
}, s.query, args...)
}
func (s statement) QueryRowPartial(v interface{}, args ...interface{}) error {
func (s statement) QueryRowPartial(v any, args ...any) error {
return s.QueryRowPartialCtx(context.Background(), v, args...)
}
func (s statement) QueryRowPartialCtx(ctx context.Context, v interface{}, args ...interface{}) (err error) {
func (s statement) QueryRowPartialCtx(ctx context.Context, v any, args ...any) (err error) {
ctx, span := startSpan(ctx, "QueryRowPartial")
defer func() {
endSpan(span, err)
@@ -366,11 +366,11 @@ func (s statement) QueryRowPartialCtx(ctx context.Context, v interface{}, args .
}, s.query, args...)
}
func (s statement) QueryRows(v interface{}, args ...interface{}) error {
func (s statement) QueryRows(v any, args ...any) error {
return s.QueryRowsCtx(context.Background(), v, args...)
}
func (s statement) QueryRowsCtx(ctx context.Context, v interface{}, args ...interface{}) (err error) {
func (s statement) QueryRowsCtx(ctx context.Context, v any, args ...any) (err error) {
ctx, span := startSpan(ctx, "QueryRows")
defer func() {
endSpan(span, err)
@@ -381,11 +381,11 @@ func (s statement) QueryRowsCtx(ctx context.Context, v interface{}, args ...inte
}, s.query, args...)
}
func (s statement) QueryRowsPartial(v interface{}, args ...interface{}) error {
func (s statement) QueryRowsPartial(v any, args ...any) error {
return s.QueryRowsPartialCtx(context.Background(), v, args...)
}
func (s statement) QueryRowsPartialCtx(ctx context.Context, v interface{}, args ...interface{}) (err error) {
func (s statement) QueryRowsPartialCtx(ctx context.Context, v any, args ...any) (err error) {
ctx, span := startSpan(ctx, "QueryRowsPartial")
defer func() {
endSpan(span, err)

View File

@@ -34,7 +34,7 @@ func SetSlowThreshold(threshold time.Duration) {
slowThreshold.Set(threshold)
}
func exec(ctx context.Context, conn sessionConn, q string, args ...interface{}) (sql.Result, error) {
func exec(ctx context.Context, conn sessionConn, q string, args ...any) (sql.Result, error) {
guard := newGuard("exec")
if err := guard.start(q, args...); err != nil {
return nil, err
@@ -46,7 +46,7 @@ func exec(ctx context.Context, conn sessionConn, q string, args ...interface{})
return result, err
}
func execStmt(ctx context.Context, conn stmtConn, q string, args ...interface{}) (sql.Result, error) {
func execStmt(ctx context.Context, conn stmtConn, q string, args ...any) (sql.Result, error) {
guard := newGuard("execStmt")
if err := guard.start(q, args...); err != nil {
return nil, err
@@ -59,7 +59,7 @@ func execStmt(ctx context.Context, conn stmtConn, q string, args ...interface{})
}
func query(ctx context.Context, conn sessionConn, scanner func(*sql.Rows) error,
q string, args ...interface{}) error {
q string, args ...any) error {
guard := newGuard("query")
if err := guard.start(q, args...); err != nil {
return err
@@ -76,7 +76,7 @@ func query(ctx context.Context, conn sessionConn, scanner func(*sql.Rows) error,
}
func queryStmt(ctx context.Context, conn stmtConn, scanner func(*sql.Rows) error,
q string, args ...interface{}) error {
q string, args ...any) error {
guard := newGuard("queryStmt")
if err := guard.start(q, args...); err != nil {
return err
@@ -94,7 +94,7 @@ func queryStmt(ctx context.Context, conn stmtConn, scanner func(*sql.Rows) error
type (
sqlGuard interface {
start(q string, args ...interface{}) error
start(q string, args ...any) error
finish(ctx context.Context, err error)
}
@@ -117,7 +117,7 @@ func newGuard(command string) sqlGuard {
return nilGuard{}
}
func (n nilGuard) start(_ string, _ ...interface{}) error {
func (n nilGuard) start(_ string, _ ...any) error {
return nil
}
@@ -139,7 +139,7 @@ func (e *realSqlGuard) finish(ctx context.Context, err error) {
metricReqDur.Observe(int64(duration/time.Millisecond), e.command)
}
func (e *realSqlGuard) start(q string, args ...interface{}) error {
func (e *realSqlGuard) start(q string, args ...any) error {
stmt, err := format(q, args...)
if err != nil {
return err

View File

@@ -16,7 +16,7 @@ func TestStmt_exec(t *testing.T) {
tests := []struct {
name string
query string
args []interface{}
args []any
delay bool
hasError bool
err error
@@ -26,28 +26,28 @@ func TestStmt_exec(t *testing.T) {
{
name: "normal",
query: "select user from users where id=?",
args: []interface{}{1},
args: []any{1},
lastInsertId: 1,
rowsAffected: 2,
},
{
name: "exec error",
query: "select user from users where id=?",
args: []interface{}{1},
args: []any{1},
hasError: true,
err: errors.New("exec"),
},
{
name: "exec more args error",
query: "select user from users where id=? and name=?",
args: []interface{}{1},
args: []any{1},
hasError: true,
err: errors.New("exec"),
},
{
name: "slowcall",
query: "select user from users where id=?",
args: []interface{}{1},
args: []any{1},
delay: true,
lastInsertId: 1,
rowsAffected: 2,
@@ -56,8 +56,8 @@ func TestStmt_exec(t *testing.T) {
for _, test := range tests {
test := test
fns := []func(args ...interface{}) (sql.Result, error){
func(args ...interface{}) (sql.Result, error) {
fns := []func(args ...any) (sql.Result, error){
func(args ...any) (sql.Result, error) {
return exec(context.Background(), &mockedSessionConn{
lastInsertId: test.lastInsertId,
rowsAffected: test.rowsAffected,
@@ -65,7 +65,7 @@ func TestStmt_exec(t *testing.T) {
delay: test.delay,
}, test.query, args...)
},
func(args ...interface{}) (sql.Result, error) {
func(args ...any) (sql.Result, error) {
return execStmt(context.Background(), &mockedStmtConn{
lastInsertId: test.lastInsertId,
rowsAffected: test.rowsAffected,
@@ -102,7 +102,7 @@ func TestStmt_query(t *testing.T) {
tests := []struct {
name string
query string
args []interface{}
args []any
delay bool
hasError bool
err error
@@ -110,34 +110,34 @@ func TestStmt_query(t *testing.T) {
{
name: "normal",
query: "select user from users where id=?",
args: []interface{}{1},
args: []any{1},
},
{
name: "query error",
query: "select user from users where id=?",
args: []interface{}{1},
args: []any{1},
hasError: true,
err: errors.New("exec"),
},
{
name: "query more args error",
query: "select user from users where id=? and name=?",
args: []interface{}{1},
args: []any{1},
hasError: true,
err: errors.New("exec"),
},
{
name: "slowcall",
query: "select user from users where id=?",
args: []interface{}{1},
args: []any{1},
delay: true,
},
}
for _, test := range tests {
test := test
fns := []func(args ...interface{}) error{
func(args ...interface{}) error {
fns := []func(args ...any) error{
func(args ...any) error {
return query(context.Background(), &mockedSessionConn{
err: test.err,
delay: test.delay,
@@ -145,7 +145,7 @@ func TestStmt_query(t *testing.T) {
return nil
}, test.query, args...)
},
func(args ...interface{}) error {
func(args ...any) error {
return queryStmt(context.Background(), &mockedStmtConn{
err: test.err,
delay: test.delay,
@@ -226,11 +226,11 @@ type mockedSessionConn struct {
delay bool
}
func (m *mockedSessionConn) Exec(query string, args ...interface{}) (sql.Result, error) {
func (m *mockedSessionConn) Exec(query string, args ...any) (sql.Result, error) {
return m.ExecContext(context.Background(), query, args...)
}
func (m *mockedSessionConn) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
func (m *mockedSessionConn) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) {
if m.delay {
time.Sleep(defaultSlowThreshold + time.Millisecond)
}
@@ -240,11 +240,11 @@ func (m *mockedSessionConn) ExecContext(ctx context.Context, query string, args
}, m.err
}
func (m *mockedSessionConn) Query(query string, args ...interface{}) (*sql.Rows, error) {
func (m *mockedSessionConn) Query(query string, args ...any) (*sql.Rows, error) {
return m.QueryContext(context.Background(), query, args...)
}
func (m *mockedSessionConn) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
func (m *mockedSessionConn) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) {
if m.delay {
time.Sleep(defaultSlowThreshold + time.Millisecond)
}
@@ -263,11 +263,11 @@ type mockedStmtConn struct {
delay bool
}
func (m *mockedStmtConn) Exec(args ...interface{}) (sql.Result, error) {
func (m *mockedStmtConn) Exec(args ...any) (sql.Result, error) {
return m.ExecContext(context.Background(), args...)
}
func (m *mockedStmtConn) ExecContext(_ context.Context, _ ...interface{}) (sql.Result, error) {
func (m *mockedStmtConn) ExecContext(_ context.Context, _ ...any) (sql.Result, error) {
if m.delay {
time.Sleep(defaultSlowThreshold + time.Millisecond)
}
@@ -277,11 +277,11 @@ func (m *mockedStmtConn) ExecContext(_ context.Context, _ ...interface{}) (sql.R
}, m.err
}
func (m *mockedStmtConn) Query(args ...interface{}) (*sql.Rows, error) {
func (m *mockedStmtConn) Query(args ...any) (*sql.Rows, error) {
return m.QueryContext(context.Background(), args...)
}
func (m *mockedStmtConn) QueryContext(_ context.Context, _ ...interface{}) (*sql.Rows, error) {
func (m *mockedStmtConn) QueryContext(_ context.Context, _ ...any) (*sql.Rows, error) {
if m.delay {
time.Sleep(defaultSlowThreshold + time.Millisecond)
}

View File

@@ -26,11 +26,11 @@ func NewSessionFromTx(tx *sql.Tx) Session {
return txSession{Tx: tx}
}
func (t txSession) Exec(q string, args ...interface{}) (sql.Result, error) {
func (t txSession) Exec(q string, args ...any) (sql.Result, error) {
return t.ExecCtx(context.Background(), q, args...)
}
func (t txSession) ExecCtx(ctx context.Context, q string, args ...interface{}) (result sql.Result, err error) {
func (t txSession) ExecCtx(ctx context.Context, q string, args ...any) (result sql.Result, err error) {
ctx, span := startSpan(ctx, "Exec")
defer func() {
endSpan(span, err)
@@ -62,11 +62,11 @@ func (t txSession) PrepareCtx(ctx context.Context, q string) (stmtSession StmtSe
}, nil
}
func (t txSession) QueryRow(v interface{}, q string, args ...interface{}) error {
func (t txSession) QueryRow(v any, q string, args ...any) error {
return t.QueryRowCtx(context.Background(), v, q, args...)
}
func (t txSession) QueryRowCtx(ctx context.Context, v interface{}, q string, args ...interface{}) (err error) {
func (t txSession) QueryRowCtx(ctx context.Context, v any, q string, args ...any) (err error) {
ctx, span := startSpan(ctx, "QueryRow")
defer func() {
endSpan(span, err)
@@ -77,12 +77,12 @@ func (t txSession) QueryRowCtx(ctx context.Context, v interface{}, q string, arg
}, q, args...)
}
func (t txSession) QueryRowPartial(v interface{}, q string, args ...interface{}) error {
func (t txSession) QueryRowPartial(v any, q string, args ...any) error {
return t.QueryRowPartialCtx(context.Background(), v, q, args...)
}
func (t txSession) QueryRowPartialCtx(ctx context.Context, v interface{}, q string,
args ...interface{}) (err error) {
func (t txSession) QueryRowPartialCtx(ctx context.Context, v any, q string,
args ...any) (err error) {
ctx, span := startSpan(ctx, "QueryRowPartial")
defer func() {
endSpan(span, err)
@@ -93,11 +93,11 @@ func (t txSession) QueryRowPartialCtx(ctx context.Context, v interface{}, q stri
}, q, args...)
}
func (t txSession) QueryRows(v interface{}, q string, args ...interface{}) error {
func (t txSession) QueryRows(v any, q string, args ...any) error {
return t.QueryRowsCtx(context.Background(), v, q, args...)
}
func (t txSession) QueryRowsCtx(ctx context.Context, v interface{}, q string, args ...interface{}) (err error) {
func (t txSession) QueryRowsCtx(ctx context.Context, v any, q string, args ...any) (err error) {
ctx, span := startSpan(ctx, "QueryRows")
defer func() {
endSpan(span, err)
@@ -108,12 +108,12 @@ func (t txSession) QueryRowsCtx(ctx context.Context, v interface{}, q string, ar
}, q, args...)
}
func (t txSession) QueryRowsPartial(v interface{}, q string, args ...interface{}) error {
func (t txSession) QueryRowsPartial(v any, q string, args ...any) error {
return t.QueryRowsPartialCtx(context.Background(), v, q, args...)
}
func (t txSession) QueryRowsPartialCtx(ctx context.Context, v interface{}, q string,
args ...interface{}) (err error) {
func (t txSession) QueryRowsPartialCtx(ctx context.Context, v any, q string,
args ...any) (err error) {
ctx, span := startSpan(ctx, "QueryRowsPartial")
defer func() {
endSpan(span, err)

View File

@@ -23,11 +23,11 @@ func (mt *mockTx) Commit() error {
return nil
}
func (mt *mockTx) Exec(q string, args ...interface{}) (sql.Result, error) {
func (mt *mockTx) Exec(q string, args ...any) (sql.Result, error) {
return nil, nil
}
func (mt *mockTx) ExecCtx(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
func (mt *mockTx) ExecCtx(ctx context.Context, query string, args ...any) (sql.Result, error) {
return nil, nil
}
@@ -39,35 +39,35 @@ func (mt *mockTx) PrepareCtx(ctx context.Context, query string) (StmtSession, er
return nil, nil
}
func (mt *mockTx) QueryRow(v interface{}, q string, args ...interface{}) error {
func (mt *mockTx) QueryRow(v any, q string, args ...any) error {
return nil
}
func (mt *mockTx) QueryRowCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error {
func (mt *mockTx) QueryRowCtx(ctx context.Context, v any, query string, args ...any) error {
return nil
}
func (mt *mockTx) QueryRowPartial(v interface{}, q string, args ...interface{}) error {
func (mt *mockTx) QueryRowPartial(v any, q string, args ...any) error {
return nil
}
func (mt *mockTx) QueryRowPartialCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error {
func (mt *mockTx) QueryRowPartialCtx(ctx context.Context, v any, query string, args ...any) error {
return nil
}
func (mt *mockTx) QueryRows(v interface{}, q string, args ...interface{}) error {
func (mt *mockTx) QueryRows(v any, q string, args ...any) error {
return nil
}
func (mt *mockTx) QueryRowsCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error {
func (mt *mockTx) QueryRowsCtx(ctx context.Context, v any, query string, args ...any) error {
return nil
}
func (mt *mockTx) QueryRowsPartial(v interface{}, q string, args ...interface{}) error {
func (mt *mockTx) QueryRowsPartial(v any, q string, args ...any) error {
return nil
}
func (mt *mockTx) QueryRowsPartialCtx(ctx context.Context, v interface{}, query string, args ...interface{}) error {
func (mt *mockTx) QueryRowsPartialCtx(ctx context.Context, v any, query string, args ...any) error {
return nil
}

View File

@@ -51,7 +51,7 @@ func escape(input string) string {
return b.String()
}
func format(query string, args ...interface{}) (string, error) {
func format(query string, args ...any) (string, error) {
numArgs := len(args)
if numArgs == 0 {
return query, nil
@@ -141,7 +141,7 @@ func logSqlError(ctx context.Context, stmt string, err error) {
}
}
func writeValue(buf *strings.Builder, arg interface{}) {
func writeValue(buf *strings.Builder, arg any) {
switch v := arg.(type) {
case bool:
if v {

View File

@@ -34,92 +34,92 @@ func TestFormat(t *testing.T) {
tests := []struct {
name string
query string
args []interface{}
args []any
expect string
hasErr bool
}{
{
name: "mysql normal",
query: "select name, age from users where bool=? and phone=?",
args: []interface{}{true, "133"},
args: []any{true, "133"},
expect: "select name, age from users where bool=1 and phone='133'",
},
{
name: "mysql normal",
query: "select name, age from users where bool=? and phone=?",
args: []interface{}{false, "133"},
args: []any{false, "133"},
expect: "select name, age from users where bool=0 and phone='133'",
},
{
name: "pg normal",
query: "select name, age from users where bool=$1 and phone=$2",
args: []interface{}{true, "133"},
args: []any{true, "133"},
expect: "select name, age from users where bool=1 and phone='133'",
},
{
name: "pg normal reverse",
query: "select name, age from users where bool=$2 and phone=$1",
args: []interface{}{"133", false},
args: []any{"133", false},
expect: "select name, age from users where bool=0 and phone='133'",
},
{
name: "pg error not number",
query: "select name, age from users where bool=$a and phone=$1",
args: []interface{}{"133", false},
args: []any{"133", false},
hasErr: true,
},
{
name: "pg error more args",
query: "select name, age from users where bool=$2 and phone=$1 and nickname=$3",
args: []interface{}{"133", false},
args: []any{"133", false},
hasErr: true,
},
{
name: "oracle normal",
query: "select name, age from users where bool=:1 and phone=:2",
args: []interface{}{true, "133"},
args: []any{true, "133"},
expect: "select name, age from users where bool=1 and phone='133'",
},
{
name: "oracle normal reverse",
query: "select name, age from users where bool=:2 and phone=:1",
args: []interface{}{"133", false},
args: []any{"133", false},
expect: "select name, age from users where bool=0 and phone='133'",
},
{
name: "oracle error not number",
query: "select name, age from users where bool=:a and phone=:1",
args: []interface{}{"133", false},
args: []any{"133", false},
hasErr: true,
},
{
name: "oracle error more args",
query: "select name, age from users where bool=:2 and phone=:1 and nickname=:3",
args: []interface{}{"133", false},
args: []any{"133", false},
hasErr: true,
},
{
name: "select with date",
query: "select * from user where date='2006-01-02 15:04:05' and name=:1",
args: []interface{}{"foo"},
args: []any{"foo"},
expect: "select * from user where date='2006-01-02 15:04:05' and name='foo'",
},
{
name: "select with date and escape",
query: `select * from user where date=' 2006-01-02 15:04:05 \'' and name=:1`,
args: []interface{}{"foo"},
args: []any{"foo"},
expect: `select * from user where date=' 2006-01-02 15:04:05 \'' and name='foo'`,
},
{
name: "select with date and bad arg",
query: `select * from user where date='2006-01-02 15:04:05 \'' and name=:a`,
args: []interface{}{"foo"},
args: []any{"foo"},
hasErr: true,
},
{
name: "select with date and escape error",
query: `select * from user where date='2006-01-02 15:04:05 \`,
args: []interface{}{"foo"},
args: []any{"foo"},
hasErr: true,
},
}