Documentation ¶
Index ¶
- func IsNullID[I IDType](id I) bool
- func Stringify(value interface{}, null string) string
- func StringifyAtom(value interface{}) string
- func UniqueStrings(strs []string) []string
- type Cache
- type CacheBase
- func (s *CacheBase[T, I]) Close() error
- func (s *CacheBase[T, I]) GetCacheKeyPrefix() string
- func (s *CacheBase[T, I]) GetCtx() context.Context
- func (s *CacheBase[T, I]) GetIdField() string
- func (s *CacheBase[T, I]) GetTableName() string
- func (s *CacheBase[T, I]) MakeCacheKey(index Index) string
- func (s *CacheBase[T, I]) SetCacheKeyPrefix(prefix string)
- func (s *CacheBase[T, I]) SetCtx(ctx context.Context)
- func (s *CacheBase[T, I]) SetIdField(idField string)
- func (s *CacheBase[T, I]) SetTableName(table string)
- type DBCRUD
- type FullCache
- type FullDBCache
- type FullRedisCache
- func (s *FullRedisCache[T, I]) CacheKey() string
- func (s *FullRedisCache[T, I]) ClearCache(objs ...T) error
- func (s *FullRedisCache[T, I]) Create(r *T) error
- func (s *FullRedisCache[T, I]) Delete(ids ...I) (int64, error)
- func (s *FullRedisCache[T, I]) Get(id I) (T, bool, error)
- func (s *FullRedisCache[T, I]) GetBy(index Index) (T, bool, error)
- func (s *FullRedisCache[T, I]) List(id ...I) ([]T, error)
- func (s *FullRedisCache[T, I]) ListAll() ([]T, error)
- func (s *FullRedisCache[T, I]) ListBy(index Index, orderBys OrderBys) ([]T, error)
- func (s *FullRedisCache[T, I]) Load() error
- func (s *FullRedisCache[T, I]) Save(r *T) error
- func (s *FullRedisCache[T, I]) Update(id I, values interface{}) (int64, error)
- type IDInt
- type IDType
- type Index
- type Indexes
- type JsonSerializer
- type OrderBy
- type OrderBys
- type RedisCache
- func (s *RedisCache[T, I]) ClearCache(objs ...T) error
- func (s *RedisCache[T, I]) Close() error
- func (s *RedisCache[T, I]) Create(obj *T) error
- func (s *RedisCache[T, I]) Delete(ids ...I) (int64, error)
- func (s *RedisCache[T, I]) Get(id I) (T, bool, error)
- func (s *RedisCache[T, I]) GetBy(index Index) (T, bool, error)
- func (s *RedisCache[T, I]) GetDB() DBCRUD[T, I]
- func (s *RedisCache[T, I]) List(ids ...I) ([]T, error)
- func (s *RedisCache[T, I]) ListBy(index Index, orderBys OrderBys) ([]T, error)
- func (s *RedisCache[T, I]) Save(obj *T) error
- func (s *RedisCache[T, I]) Update(id I, values interface{}) (int64, error)
- type RedisHashJson
- func (s *RedisHashJson[T, I]) HDelJson(key string, ids ...I) error
- func (s *RedisHashJson[T, I]) HGetAllJson(key string) ([]T, error)
- func (s *RedisHashJson[T, I]) HGetJson(key string, id I) (T, bool, error)
- func (s *RedisHashJson[T, I]) HMGetJson(key string, ids ...I) ([]T, error)
- func (s *RedisHashJson[T, I]) HSetJson(key string, objs ...T) error
- type RedisJson
- func (s *RedisJson[T]) Expires(keys ...string) error
- func (s *RedisJson[T]) GetJson(key string) (T, bool, error)
- func (s *RedisJson[T]) MGetJson(keys []string) ([]T, []int, error)
- func (s *RedisJson[T]) MSetJson(objMap map[string]interface{}) error
- func (s *RedisJson[T]) MSetNull(keys []string) error
- func (s *RedisJson[T]) SetJson(key string, obj T) error
- func (s *RedisJson[T]) SetNull(key string) error
- type Serializer
- type Table
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StringifyAtom ¶
func StringifyAtom(value interface{}) string
func UniqueStrings ¶
Types ¶
type Cache ¶
type Cache[T Table[I], I IDType] interface { DBCRUD[T, I] //clear cache for objs ClearCache(objs ...T) error //for extending SetCtx(ctx context.Context) GetCtx() context.Context SetCacheKeyPrefix(prefix string) GetCacheKeyPrefix() string MakeCacheKey(index Index) string SetTableName(table string) GetTableName() string SetIdField(idField string) GetIdField() string }
Cache 1. Primary key cache: eg. {table}/id/{id} -> record 2.1 Index cache: eg1. {table}/uid/{uid}-> [id1,id2] 2.2 Index cache: eg2. {table}/uid/{uid}/type/{type} -> [id1] 3. Index cache clear cache process, on index change 1. given indexes, 2. find related index cache keys,3. delete
type CacheBase ¶
func NewCacheBase ¶
func (*CacheBase[T, I]) GetCacheKeyPrefix ¶
func (*CacheBase[T, I]) GetIdField ¶
func (*CacheBase[T, I]) GetTableName ¶
func (*CacheBase[T, I]) MakeCacheKey ¶
func (*CacheBase[T, I]) SetCacheKeyPrefix ¶
func (s *CacheBase[T, I]) SetSerializer(serializer Serializer) { s.serializer = serializer }
func (s *CacheBase[T, I]) GetSerializer() Serializer { return s.serializer }
func (*CacheBase[T, I]) SetCtx ¶
func (s *CacheBase[T, I]) AddIndexFields(index []string) { sort.Strings(index) s.indexFields = append(s.indexFields, index) }
func (s *CacheBase[T, I]) ListIndexFields() [][]string { return s.indexFields }
func (*CacheBase[T, I]) SetIdField ¶
func (*CacheBase[T, I]) SetTableName ¶
type DBCRUD ¶
type DBCRUD[T Table[I], I IDType] interface { //Creat create new record into dababase Create(obj *T) error //Save update if id exists or create new record Save(obj *T) error //Delete return (effectedrows,error) Delete(ids ...I) (int64, error) // values can be struct or map[string]interface{}, return (effectedrows,error) Update(id I, values interface{}) (int64, error) //get obj by id Get(id I) (T, bool, error) //list objs by ids List(ids ...I) ([]T, error) //get obj by index GetBy(index Index) (T, bool, error) //list objs by indexes ListBy(index Index, orderBys OrderBys) ([]T, error) //close lower clients Close() error }
type FullCache ¶
type FullCache[T Table[I], I IDType] interface { ClearCache(objs ...T) error //Creat create new record into dababase Create(obj *T) error //Save update if id exists or create new record Save(obj *T) error //Delete return (effectedrows,error) Delete(ids ...I) (int64, error) // values can be struct or map[string]interface{}, return (effectedrows,error) Update(id I, values interface{}) (int64, error) //get obj by id Get(id I) (T, bool, error) //list objs by ids List(ids ...I) ([]T, error) //get obj by index GetBy(index Index) (T, bool, error) //list objs by indexes ListBy(index Index, orderBys OrderBys) ([]T, error) //list all objs from db ListAll() ([]T, error) //close lower clients Close() error //for extending SetCtx(ctx context.Context) GetCtx() context.Context SetCacheKeyPrefix(prefix string) GetCacheKeyPrefix() string MakeCacheKey(index Index) string SetTableName(table string) GetTableName() string SetIdField(idField string) GetIdField() string }
type FullDBCache ¶
type FullRedisCache ¶
type FullRedisCache[T Table[I], I IDType] struct { *CacheBase[T, I] // contains filtered or unexported fields }
func NewFullRedisCache ¶
func NewFullRedisCache[T Table[I], I IDType](prefix, table, idField string, db FullDBCache[T, I], red *redis.Client, ttl time.Duration) *FullRedisCache[T, I]
func (*FullRedisCache[T, I]) CacheKey ¶
func (s *FullRedisCache[T, I]) CacheKey() string
func (*FullRedisCache[T, I]) ClearCache ¶
func (s *FullRedisCache[T, I]) ClearCache(objs ...T) error
func (*FullRedisCache[T, I]) Create ¶
func (s *FullRedisCache[T, I]) Create(r *T) error
func (*FullRedisCache[T, I]) Delete ¶
func (s *FullRedisCache[T, I]) Delete(ids ...I) (int64, error)
func (*FullRedisCache[T, I]) Get ¶
func (s *FullRedisCache[T, I]) Get(id I) (T, bool, error)
func (*FullRedisCache[T, I]) GetBy ¶ added in v0.0.5
func (s *FullRedisCache[T, I]) GetBy(index Index) (T, bool, error)
func (*FullRedisCache[T, I]) List ¶
func (s *FullRedisCache[T, I]) List(id ...I) ([]T, error)
func (*FullRedisCache[T, I]) ListAll ¶
func (s *FullRedisCache[T, I]) ListAll() ([]T, error)
func (*FullRedisCache[T, I]) ListBy ¶ added in v0.0.5
func (s *FullRedisCache[T, I]) ListBy(index Index, orderBys OrderBys) ([]T, error)
func (*FullRedisCache[T, I]) Load ¶ added in v0.0.3
func (s *FullRedisCache[T, I]) Load() error
func (*FullRedisCache[T, I]) Save ¶
func (s *FullRedisCache[T, I]) Save(r *T) error
func (*FullRedisCache[T, I]) Update ¶
func (s *FullRedisCache[T, I]) Update(id I, values interface{}) (int64, error)
type JsonSerializer ¶
type JsonSerializer struct { }
func (*JsonSerializer) Marshal ¶
func (s *JsonSerializer) Marshal(obj interface{}) (string, error)
func (*JsonSerializer) Unmarshal ¶
func (s *JsonSerializer) Unmarshal(data string, objRef interface{}) error
type RedisCache ¶
type RedisCache[T Table[I], I IDType] struct { *CacheBase[T, I] // contains filtered or unexported fields }
func NewRedisCache ¶
func (*RedisCache[T, I]) ClearCache ¶
func (s *RedisCache[T, I]) ClearCache(objs ...T) error
func (*RedisCache[T, I]) Close ¶
func (s *RedisCache[T, I]) Close() error
func (*RedisCache[T, I]) Create ¶
func (s *RedisCache[T, I]) Create(obj *T) error
func (*RedisCache[T, I]) Delete ¶
func (s *RedisCache[T, I]) Delete(ids ...I) (int64, error)
func (*RedisCache[T, I]) Get ¶
func (s *RedisCache[T, I]) Get(id I) (T, bool, error)
func (*RedisCache[T, I]) GetDB ¶
func (s *RedisCache[T, I]) GetDB() DBCRUD[T, I]
func (*RedisCache[T, I]) List ¶
func (s *RedisCache[T, I]) List(ids ...I) ([]T, error)
List list records by ids, order & empty records keeped
func (*RedisCache[T, I]) ListBy ¶
func (s *RedisCache[T, I]) ListBy(index Index, orderBys OrderBys) ([]T, error)
func (*RedisCache[T, I]) Save ¶
func (s *RedisCache[T, I]) Save(obj *T) error
func (*RedisCache[T, I]) Update ¶
func (s *RedisCache[T, I]) Update(id I, values interface{}) (int64, error)
Update values can be struct or map[string]interface{}
type RedisHashJson ¶
type RedisHashJson[T Table[I], I IDType] struct { *RedisJson[T] *redis.Client // contains filtered or unexported fields }
func NewRedisHashJson ¶
func NewRedisHashJson[T Table[I], I IDType](client *redis.Client, ttl time.Duration) *RedisHashJson[T, I]
func (*RedisHashJson[T, I]) HDelJson ¶
func (s *RedisHashJson[T, I]) HDelJson(key string, ids ...I) error
func (*RedisHashJson[T, I]) HGetAllJson ¶
func (s *RedisHashJson[T, I]) HGetAllJson(key string) ([]T, error)
func (*RedisHashJson[T, I]) HGetJson ¶
func (s *RedisHashJson[T, I]) HGetJson(key string, id I) (T, bool, error)
func (*RedisHashJson[T, I]) HMGetJson ¶
func (s *RedisHashJson[T, I]) HMGetJson(key string, ids ...I) ([]T, error)
func (*RedisHashJson[T, I]) HSetJson ¶
func (s *RedisHashJson[T, I]) HSetJson(key string, objs ...T) error
type RedisJson ¶
type RedisJson[T any] struct { *redis.Client // contains filtered or unexported fields }
type Serializer ¶
Click to show internal directories.
Click to hide internal directories.