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:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user