repo

package
v1.1.20 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: LGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseRepo

type BaseRepo[T any] struct{ Orm *gorm.DB }

func NewBaseRepo

func NewBaseRepo[T any]() *BaseRepo[T]

func (*BaseRepo[T]) CountAll

func (r *BaseRepo[T]) CountAll() (int64, error)

CountAll 指定表无条件统计全部数量

func (*BaseRepo[T]) DeleteBy

func (r *BaseRepo[T]) DeleteBy(condition map[string]interface{}, hardDelete bool) error

DeleteBy 根据给定条件删除记录,可选是否硬删除(仅对于有软删除的表)

func (*BaseRepo[T]) DeleteById

func (r *BaseRepo[T]) DeleteById(id uint64) error

DeleteById 按照ID删除一条

func (*BaseRepo[T]) Exec

func (r *BaseRepo[T]) Exec(sql string, values ...interface{}) (*gorm.DB, error)

Exec 执行原生sql语句

func (*BaseRepo[T]) FindBy

func (r *BaseRepo[T]) FindBy(condition map[string]interface{}, results *[]*T, opts ...FindOption) error

FindBy 按照条件查找多条 _order_by 为自定义快捷键 可以添加到条件中无需每次调用都额外写空参数

func (*BaseRepo[T]) FindByID

func (r *BaseRepo[T]) FindByID(id uint64) (*T, error)

FindByID 按照ID读取一条记录

func (*BaseRepo[T]) GetByPage

func (r *BaseRepo[T]) GetByPage(model interface{}, page int, pageSize int) (interface{}, error)

func (*BaseRepo[T]) Insert

func (r *BaseRepo[T]) Insert(model *T) error

Insert 插入一条记录

func (*BaseRepo[T]) InsertOrIgnore

func (r *BaseRepo[T]) InsertOrIgnore(model *T, condition map[string]interface{}) (int64, error)

InsertOrIgnore 事务版本 先查找,存在则忽略,否则插入

func (*BaseRepo[T]) InsertOrUpdate

func (r *BaseRepo[T]) InsertOrUpdate(model *T, condition map[string]interface{}, updateValues map[string]interface{}) error

InsertOrUpdate 事务版本 先查找,不存在则插入,插入则更新

func (*BaseRepo[T]) UpdateById

func (r *BaseRepo[T]) UpdateById(model *T, id uint64) error

UpdateById 按照ID更新一条

func (*BaseRepo[T]) Upsert

func (r *BaseRepo[T]) Upsert(model *T, condition map[string]interface{}) error

Upsert 同上方法,无事务,根据条件查找记录,如果存在则更新,如果不存在则创建

type FindOption added in v1.1.20

type FindOption func(*gorm.DB) *gorm.DB

FindOption FindBy 条件配置

func WithLimit

func WithLimit(limit int) FindOption

func WithOrderBy

func WithOrderBy(orderBy string) FindOption

type IBaseRepo added in v1.1.20

type IBaseRepo interface {
	Insert(model interface{}) error
	InsertOrUpdate(model interface{}, condition map[string]interface{}, forUpdateValues interface{}) error
	UpdateById(model interface{}, id uint64) error
	DeleteById(model interface{}, id uint64) error
	DeleteBy(condition map[string]interface{}, model interface{}, hardDelete bool) error
	SelectById(model interface{}, id uint64) error
	SelectBy(condition map[string]interface{}) ([]interface{}, error)
	SelectOne(condition map[string]interface{}, model interface{}) error
}

Jump to

Keyboard shortcuts

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