dao

package
v2.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClickhouseDao

type ClickhouseDao[E schema.Tabler] struct {
	Tag func() string
	// contains filtered or unexported fields
}

func (*ClickhouseDao[E]) All

func (receiver *ClickhouseDao[E]) All(entity E, opts ...QueryOption) ([]E, error)

All clickhouse动态查询数据

func (*ClickhouseDao[E]) Count

func (receiver *ClickhouseDao[E]) Count(entity E) (int64, error)

Count clickhouse统计记录数

func (*ClickhouseDao[E]) Create

func (receiver *ClickhouseDao[E]) Create(entity *E) error

Create clickhouse动态插入数据

func (*ClickhouseDao[E]) Debug

func (m *ClickhouseDao[E]) Debug() *ClickhouseDao[E]

func (*ClickhouseDao[E]) Delete

func (receiver *ClickhouseDao[E]) Delete(entity E) error

Delete clickhouse动态删除数据

func (*ClickhouseDao[E]) Exists

func (receiver *ClickhouseDao[E]) Exists(entity E) bool

Exists clickhouse动态查询是否存在数据

func (*ClickhouseDao[E]) MultiCreate

func (receiver *ClickhouseDao[E]) MultiCreate(entities []*E) error

MultiCreate clickhouse动态插入多条数据

func (*ClickhouseDao[E]) One

func (receiver *ClickhouseDao[E]) One(entity E) (*E, error)

One clickhouse动态查询一条数据

func (*ClickhouseDao[E]) Pager

func (receiver *ClickhouseDao[E]) Pager(conn *gorm.DB, page, size int) ([]E, *models.ResultPage, error)

Pager clickhouse简单分页查询数据

func (*ClickhouseDao[E]) Save

func (receiver *ClickhouseDao[E]) Save(entity *E) error

Save clickhouse动态保存数据

func (*ClickhouseDao[E]) Updates

func (receiver *ClickhouseDao[E]) Updates(entity *E) error

Updates clickhouse动态更新数据

func (*ClickhouseDao[E]) Where

func (m *ClickhouseDao[E]) Where(query interface{}, args ...interface{}) *gorm.DB

Where clickhouse动态查询数据

func (*ClickhouseDao[E]) WithContext

func (m *ClickhouseDao[E]) WithContext(ctx *context.Context) *ClickhouseDao[E]

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

type MgoDao[E any] struct {
	CollectionName string
	Tag            func() string
}

MgoDao 注意使用前必须先将CollectionName赋值

func (MgoDao[E]) All

func (m MgoDao[E]) All(query bson.M) ([]E, error)

All mongo动态查询数据

func (MgoDao[E]) Delete

func (m MgoDao[E]) Delete(query bson.M) error

Delete mongo动态删除数据

func (MgoDao[E]) Insert

func (m MgoDao[E]) Insert(entity *E) error

Insert mongo动态插入数据

func (MgoDao[E]) One

func (m MgoDao[E]) One(query bson.M) (*E, error)

One mongo动态查询一条数据

func (MgoDao[E]) Pager

func (m MgoDao[E]) Pager(query bson.M, sort []string, page, size int) ([]E, *models.ResultPage, error)

Pager mongo简单分页查询数据

func (MgoDao[E]) Updates

func (m MgoDao[E]) Updates(id primitive.ObjectID, doc E) error

Updates 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]) Count

func (receiver *MySQLDao[E]) Count(entity E) (int64, error)

Count mysql统计记录数

func (*MySQLDao[E]) Create

func (receiver *MySQLDao[E]) Create(entity *E) error

Create mysql动态插入数据

func (*MySQLDao[E]) Debug

func (m *MySQLDao[E]) Debug() *MySQLDao[E]

func (*MySQLDao[E]) Delete

func (receiver *MySQLDao[E]) Delete(entity E) error

Delete mysql动态删除数据

func (*MySQLDao[E]) Exists

func (receiver *MySQLDao[E]) Exists(entity E) bool

Exists mysql动态查询是否存在数据

func (*MySQLDao[E]) MultiCreate

func (receiver *MySQLDao[E]) MultiCreate(entities []*E) error

MultiCreate mysql动态插入多条数据

func (*MySQLDao[E]) One

func (receiver *MySQLDao[E]) One(entity E) (*E, error)

One mysql动态查询一条数据

func (*MySQLDao[E]) Pager

func (receiver *MySQLDao[E]) Pager(conn *gorm.DB, page, size int) ([]E, *models.ResultPage, error)

Pager mysql简单分页查询数据

func (*MySQLDao[E]) Save

func (receiver *MySQLDao[E]) Save(entity *E) error

Save mysql动态保存数据

func (*MySQLDao[E]) Updates

func (receiver *MySQLDao[E]) Updates(entity *E) error

Updates mysql动态更新数据

func (*MySQLDao[E]) Where

func (m *MySQLDao[E]) Where(query interface{}, args ...interface{}) *gorm.DB

Where mysql动态查询数据

func (*MySQLDao[E]) WithContext

func (m *MySQLDao[E]) WithContext(ctx *context.Context) *MySQLDao[E]

type PostgresDao

type PostgresDao[E schema.Tabler] struct {
	Tag func() string
	// contains filtered or unexported fields
}

func (*PostgresDao[E]) All

func (receiver *PostgresDao[E]) All(entity E, opts ...QueryOption) ([]E, error)

func (*PostgresDao[E]) Count

func (receiver *PostgresDao[E]) Count(entity E) (int64, error)

func (*PostgresDao[E]) Create

func (receiver *PostgresDao[E]) Create(entity *E) error

func (*PostgresDao[E]) Debug

func (m *PostgresDao[E]) Debug() *PostgresDao[E]

func (*PostgresDao[E]) Delete

func (receiver *PostgresDao[E]) Delete(entity E) error

func (*PostgresDao[E]) Exists

func (receiver *PostgresDao[E]) Exists(entity E) bool

func (*PostgresDao[E]) MultiCreate

func (receiver *PostgresDao[E]) MultiCreate(entities []*E) error

func (*PostgresDao[E]) One

func (receiver *PostgresDao[E]) One(entity E) (*E, error)

func (*PostgresDao[E]) Pager

func (receiver *PostgresDao[E]) Pager(conn *gorm.DB, page, size int) ([]E, *models.ResultPage, error)

func (*PostgresDao[E]) Save

func (receiver *PostgresDao[E]) Save(entity *E) error

func (*PostgresDao[E]) Updates

func (receiver *PostgresDao[E]) Updates(entity *E) error

func (*PostgresDao[E]) Where

func (m *PostgresDao[E]) Where(query interface{}, args ...interface{}) *gorm.DB

func (*PostgresDao[E]) WithContext

func (m *PostgresDao[E]) WithContext(ctx *context.Context) *PostgresDao[E]

type QueryOption

type QueryOption struct {
	Preloads []string
	OrderBy  []string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL