Documentation
¶
Index ¶
- 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]) 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]) WithContext(ctx *context.Context) *MySQLDao[E]
- type QueryOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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赋值
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动态插入多条数据
type QueryOption ¶
Click to show internal directories.
Click to hide internal directories.