Files
mayfly-go/server/internal/redis/infrastructure/persistence/redis_repo.go

63 lines
1.7 KiB
Go
Raw Normal View History

package persistence
import (
2022-09-09 18:26:08 +08:00
"mayfly-go/internal/redis/domain/entity"
"mayfly-go/internal/redis/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
2022-09-09 18:26:08 +08:00
type redisRepoImpl struct{}
2022-09-09 18:26:08 +08:00
func newRedisRepo() repository.Redis {
return new(redisRepoImpl)
}
// 分页获取机器信息列表
func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
qd := gormx.NewQuery(new(entity.Redis)).
Like("host", condition.Host).
In("tag_id", condition.TagIds).
RLike("tag_path", condition.TagPathLike).
OrderByAsc("tag_path")
return gormx.PageQuery(qd, pageParam, toEntity)
}
2022-10-26 20:49:29 +08:00
func (r *redisRepoImpl) Count(condition *entity.RedisQuery) int64 {
where := make(map[string]any)
2022-10-26 20:49:29 +08:00
if len(condition.TagIds) > 0 {
where["tag_id"] = condition.TagIds
}
if condition.TagId != 0 {
where["tag_id"] = condition.TagId
}
return gormx.CountByCond(new(entity.Redis), where)
2021-09-11 14:04:09 +08:00
}
// 根据id获取
2022-09-09 18:26:08 +08:00
func (r *redisRepoImpl) GetById(id uint64, cols ...string) *entity.Redis {
rd := new(entity.Redis)
if err := gormx.GetById(rd, id, cols...); err != nil {
return nil
}
return rd
}
2022-09-09 18:26:08 +08:00
func (r *redisRepoImpl) GetRedis(condition *entity.Redis, cols ...string) error {
return gormx.GetBy(condition, cols...)
}
2022-09-09 18:26:08 +08:00
func (r *redisRepoImpl) Insert(redis *entity.Redis) {
biz.ErrIsNilAppendErr(gormx.Insert(redis), "新增失败: %s")
}
2022-09-09 18:26:08 +08:00
func (r *redisRepoImpl) Update(redis *entity.Redis) {
biz.ErrIsNilAppendErr(gormx.UpdateById(redis), "更新失败: %s")
}
2022-09-09 18:26:08 +08:00
func (r *redisRepoImpl) Delete(id uint64) {
biz.ErrIsNilAppendErr(gormx.DeleteById(new(entity.Redis), id), "删除失败: %s")
}