Documentation ¶
Index ¶
- Variables
- type ColumnCreateModifyDeleteTime
- type Model
- type Pager
- type Repository
- func (r *Repository[M]) Create(model *M) error
- func (r *Repository[M]) CreateBatch(models []*M) error
- func (r *Repository[M]) Delete(condition *M, deleteUser ...string) error
- func (r *Repository[M]) DeleteById(id int64, deleteUser ...string) error
- func (r *Repository[M]) DeleteByIds(ids []int64, deleteUser ...string) error
- func (r *Repository[M]) Exist(condition *M) (bool, error)
- func (r *Repository[M]) ExistExcludeId(condition *M, id int64) (bool, error)
- func (r *Repository[M]) ExistExcludeIds(condition *M, ids []int64) (bool, error)
- func (r *Repository[M]) FirstOrCreate(condition *M) (*M, error)
- func (r *Repository[M]) Get(condition *M, fields ...string) (*M, error)
- func (r *Repository[M]) GetById(id int64, fields ...string) (*M, error)
- func (r *Repository[M]) List(condition *M, fields ...string) ([]*M, error)
- func (r *Repository[M]) ListAll(condition *M, fields ...string) ([]*M, error)
- func (r *Repository[M]) Page(condition *M, pager *Pager, fields ...string) ([]*M, error)
- func (r *Repository[M]) PageOrder(condition *M, pager *Pager, order string, fields ...string) ([]*M, error)
- func (r *Repository[M]) Update(model *M, condition *M, selectFields ...string) error
- func (r *Repository[M]) UpdateById(model *M, id int64, selectFields ...string) error
- func (r *Repository[M]) Upsert(models []*M, fields ...string) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrModelNotBeNil = errors.New("model not be nil") ErrIdLessThanZero = errors.New("id not less than zero") ErrModelsNotBeEmptySlice = errors.New("models not be empty slice") ErrConditionNotBeNil = errors.New("condition not be nil") ErrIdsNotBeEmpty = errors.New("ids not be empty array") )
Functions ¶
This section is empty.
Types ¶
type ColumnCreateModifyDeleteTime ¶
type ColumnCreateModifyDeleteTime struct { ID int64 `gorm:"primary_key;AUTO_INCREMENT" json:"id" db:"id"` CreateTime int64 `json:"create_time" db:"create_time" gorm:"autoCreateTime"` ModifyTime int64 `json:"modify_time" db:"modify_time" gorm:"autoUpdateTime"` DeletedTime int64 `json:"deleted_time" db:"deleted_time"` IsDel soft_delete.DeletedAt `json:"is_del" db:"is_del" gorm:"softDelete:flag,DeletedAtField:DeletedTime"` }
type Repository ¶
type Repository[M Model] struct { // contains filtered or unexported fields }
func NewRepository ¶
func NewRepository(model Model, db *gorm.DB) Repository[Model]
newCommonRepo 创建一个通用的 repo
func (*Repository[M]) Delete ¶
func (r *Repository[M]) Delete(condition *M, deleteUser ...string) error
通过条件删除记录
func (*Repository[M]) DeleteById ¶
func (r *Repository[M]) DeleteById(id int64, deleteUser ...string) error
通过 ID 删除记录
func (*Repository[M]) DeleteByIds ¶
func (r *Repository[M]) DeleteByIds(ids []int64, deleteUser ...string) error
通过 IDs 删除记录
func (*Repository[M]) Exist ¶
func (r *Repository[M]) Exist(condition *M) (bool, error)
通过条件查询是否存在记录
func (*Repository[M]) ExistExcludeId ¶
func (r *Repository[M]) ExistExcludeId(condition *M, id int64) (bool, error)
通过条件查询是否存在记录,排除指定 ID
func (*Repository[M]) ExistExcludeIds ¶
func (r *Repository[M]) ExistExcludeIds(condition *M, ids []int64) (bool, error)
通过条件查询是否存在记录,排除指定 IDs
func (*Repository[M]) FirstOrCreate ¶
func (r *Repository[M]) FirstOrCreate(condition *M) (*M, error)
func (*Repository[M]) Get ¶
func (r *Repository[M]) Get(condition *M, fields ...string) (*M, error)
通过条件查询记录
func (*Repository[M]) GetById ¶
func (r *Repository[M]) GetById(id int64, fields ...string) (*M, error)
通过 ID 查询记录
func (*Repository[M]) List ¶
func (r *Repository[M]) List(condition *M, fields ...string) ([]*M, error)
通过条件查询记录列表
func (*Repository[M]) ListAll ¶
func (r *Repository[M]) ListAll(condition *M, fields ...string) ([]*M, error)
通过条件查询记录列表(包含删除的记录)
func (*Repository[M]) Page ¶
func (r *Repository[M]) Page(condition *M, pager *Pager, fields ...string) ([]*M, error)
通过条件分页查询记录列表
func (*Repository[M]) PageOrder ¶
func (r *Repository[M]) PageOrder(condition *M, pager *Pager, order string, fields ...string) ([]*M, error)
通过条件分页查询记录列表(指定排序)
func (*Repository[M]) Update ¶
func (r *Repository[M]) Update(model *M, condition *M, selectFields ...string) error
通过条件更新记录
func (*Repository[M]) UpdateById ¶
func (r *Repository[M]) UpdateById(model *M, id int64, selectFields ...string) error
通过 ID 更新记录 使用 struct 进行更新时,GORM 只会更新非零值的字段。selectFields 用于指定更新的字段,避免无法更新零值。 more see: https://gorm.io/zh_CN/docs/update.html#%E6%9B%B4%E6%96%B0%E9%80%89%E5%AE%9A%E5%AD%97%E6%AE%B5
func (*Repository[M]) Upsert ¶
func (r *Repository[M]) Upsert(models []*M, fields ...string) error
创建及更新记录。根据数据的唯一键,不存在即创建记录,存在则更新记录 more see: https://gorm.io/zh_CN/docs/create.html#Upsert-%E5%8F%8A%E5%86%B2%E7%AA%81
Click to show internal directories.
Click to hide internal directories.