Documentation
¶
Index ¶
- type CacheConfig
- type Dao
- type MgoDao
- func (m MgoDao[E]) All(query bson.M) ([]E, error)
- func (m MgoDao[E]) Delete(query bson.M) error
- func (m MgoDao[E]) Insert(entity *E) error
- func (m MgoDao[E]) One(query bson.M) (*E, error)
- func (m MgoDao[E]) Pager(query bson.M, sort []string, page, size int) ([]E, *models.ResultPage, error)
- func (m MgoDao[E]) Update(selector bson.M, update bson.M) error
- func (m MgoDao[E]) Updates(id primitive.ObjectID, doc E) error
- type MySQLDao
- func (receiver *MySQLDao[E]) Alias(alias string) *gorm.DB
- func (receiver *MySQLDao[E]) All(entity E, opts ...QueryOption) ([]E, error)
- func (receiver *MySQLDao[E]) Count(entity E) (int64, error)
- func (receiver *MySQLDao[E]) Create(entity *E) error
- func (receiver *MySQLDao[E]) DB() *gorm.DB
- func (m *MySQLDao[E]) Debug() *MySQLDao[E]
- func (receiver *MySQLDao[E]) Delete(entity E) error
- func (receiver *MySQLDao[E]) Exists(entity E) bool
- func (receiver *MySQLDao[E]) JOIN(alias, query string, args ...interface{}) *gorm.DB
- func (receiver *MySQLDao[E]) MultiCreate(entities []*E) error
- func (receiver *MySQLDao[E]) One(entity E) (*E, error)
- func (receiver *MySQLDao[E]) Pager(conn *gorm.DB, page, size int) ([]E, *models.ResultPage, error)
- func (receiver *MySQLDao[E]) Save(entity *E) error
- func (receiver *MySQLDao[E]) Updates(entity *E) error
- func (m *MySQLDao[E]) Where(query interface{}, args ...interface{}) *gorm.DB
- func (m *MySQLDao[E]) WithCache(config CacheConfig) *MySQLDao[E]
- func (m *MySQLDao[E]) WithContext(ctx *context.Context) *MySQLDao[E]
- type QueryOption
- type RedisCache
- func (c *RedisCache) Add(key interface{}, value interface{}, lifeSpan time.Duration)
- func (c *RedisCache) Clear() bool
- func (c *RedisCache) Close()
- func (c *RedisCache) Delete(key interface{})
- func (c *RedisCache) Get(key interface{}) (interface{}, bool)
- func (c *RedisCache) IsExist(key interface{}) bool
- func (c *RedisCache) Range(f func(key, value interface{}) bool)
- func (c *RedisCache) Set(key interface{}, value interface{}, duration time.Duration)
- func (c *RedisCache) Value(key interface{}) (interface{}, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheConfig ¶ added in v2.0.8
CacheConfig controls result caching for the DAO query methods.
type Dao ¶
type Dao[E any] interface { Insert(entity *E) error Where(query interface{}, args ...interface{}) *gorm.DB Find(query interface{}, args ...interface{}) ([]E, error) FindById(id interface{}) (E, error) Update(entity *E) error Delete(entity *E) error Count() (int64, error) }
Dao[E] 是 mgin v2 扩展后的泛型 DAO 接口。
v1 时代仅包含 Insert(*E) error 一个方法,v2 扩展为与 db/dao/mysql.go、postgres.go、 clickhouse.go、mgo.go 等具体实现对齐的最小方法集。已有具体实现(MySQLDao 等)的方法 集合已经超过这个接口,因此把它们"补齐签名"以满足本接口即可。
注意:v2 Dao 接口仍然保持小而精,避免在接口里强加大量可选方法。具体实现可以 拥有接口之外的扩展方法(如 MySQLDao.Debug()、MySQLDao.WithContext()), 业务需要时直接断言到具体类型调用。
type MgoDao ¶
MgoDao 注意使用前必须先将CollectionName赋值
func (MgoDao[E]) Pager ¶
func (m MgoDao[E]) Pager(query bson.M, sort []string, page, size int) ([]E, *models.ResultPage, error)
Pager mongo简单分页查询数据
type MySQLDao ¶
type MySQLDao[E schema.Tabler] struct { Tag func() string // contains filtered or unexported fields }
func (*MySQLDao[E]) All ¶
func (receiver *MySQLDao[E]) All(entity E, opts ...QueryOption) ([]E, error)
All mysql动态查询数据
func (*MySQLDao[E]) MultiCreate ¶
MultiCreate mysql动态插入多条数据
func (*MySQLDao[E]) WithCache ¶ added in v2.0.8
func (m *MySQLDao[E]) WithCache(config CacheConfig) *MySQLDao[E]
WithCache enables configurable result caching for this DAO.
type QueryOption ¶
type RedisCache ¶ added in v2.0.8
type RedisCache struct {
Client redis.UniversalClient
}
RedisCache adapts a go-redis client to the cache store used by MySQLDao.
func NewRedisCache ¶ added in v2.0.8
func NewRedisCache(client redis.UniversalClient) *RedisCache
func (*RedisCache) Add ¶ added in v2.0.8
func (c *RedisCache) Add(key interface{}, value interface{}, lifeSpan time.Duration)
func (*RedisCache) Clear ¶ added in v2.0.8
func (c *RedisCache) Clear() bool
func (*RedisCache) Close ¶ added in v2.0.8
func (c *RedisCache) Close()
func (*RedisCache) Delete ¶ added in v2.0.8
func (c *RedisCache) Delete(key interface{})
func (*RedisCache) Get ¶ added in v2.0.8
func (c *RedisCache) Get(key interface{}) (interface{}, bool)
func (*RedisCache) IsExist ¶ added in v2.0.8
func (c *RedisCache) IsExist(key interface{}) bool
func (*RedisCache) Range ¶ added in v2.0.8
func (c *RedisCache) Range(f func(key, value interface{}) bool)
func (*RedisCache) Set ¶ added in v2.0.8
func (c *RedisCache) Set(key interface{}, value interface{}, duration time.Duration)
func (*RedisCache) Value ¶ added in v2.0.8
func (c *RedisCache) Value(key interface{}) (interface{}, bool)
Click to show internal directories.
Click to hide internal directories.