Documentation ¶
Index ¶
- func CreateUserPaginator(cursor paginator.Cursor, order *paginator.Order, limit *int) *paginator.Paginator
- type BaseRepo
- func (r *BaseRepo[T]) CountAll() (int64, error)
- func (r *BaseRepo[T]) DeleteBy(condition map[string]interface{}, hardDelete bool) error
- func (r *BaseRepo[T]) DeleteById(id uint64) error
- func (r *BaseRepo[T]) Exec(sql string, values ...interface{}) (*gorm.DB, error)
- func (r *BaseRepo[T]) FindBy(condition map[string]interface{}) (*T, error)
- func (r *BaseRepo[T]) FindByID(id uint64) (*T, error)
- func (r *BaseRepo[T]) FindByLock(condition map[string]interface{}) (*T, error)
- func (r *BaseRepo[T]) GetByPage(pageNum uint32, pageSize uint32, opts ...SelOpt) (*Pagination[T], error)
- func (r *BaseRepo[T]) Insert(model *T) error
- func (r *BaseRepo[T]) InsertOrIgnore(model *T, condition map[string]interface{}) (int64, error)
- func (r *BaseRepo[T]) InsertOrUpdate(insertItem *T, condition map[string]interface{}, updateValues *T) error
- func (r *BaseRepo[T]) SelectBy(condition map[string]interface{}, results *[]*T, opts ...SelOpt) error
- func (r *BaseRepo[T]) UpdateBy(condition map[string]interface{}, updateValues map[string]interface{}) (int64, error)
- func (r *BaseRepo[T]) UpdateById(id uint64, updateValues map[string]interface{}) error
- func (r *BaseRepo[T]) Upsert(model *T, condition map[string]interface{}) error
- func (r *BaseRepo[T]) UpsertByID(model *T, updateFields []string) error
- type Cursor
- type Pagination
- type SelOpt
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseRepo ¶
func (*BaseRepo[T]) DeleteById ¶
DeleteById 按照ID删除一条
func (*BaseRepo[T]) FindByLock ¶
FindByLock 根据条件查找一条记录,并使用 SELECT FOR UPDATE 锁定 (需要配合外部事务)
func (*BaseRepo[T]) GetByPage ¶
func (r *BaseRepo[T]) GetByPage(pageNum uint32, pageSize uint32, opts ...SelOpt) (*Pagination[T], error)
GetByPage 根据分页获取记录
func (*BaseRepo[T]) InsertOrIgnore ¶
InsertOrIgnore 无显式事务 先查找,存在则忽略,否则插入 (并发性也可以由数据库相同的unique key来保证)
func (*BaseRepo[T]) InsertOrUpdate ¶
func (r *BaseRepo[T]) InsertOrUpdate(insertItem *T, condition map[string]interface{}, updateValues *T) error
InsertOrUpdate 事务版本 先查找,不存在则插入,存在则更新
func (*BaseRepo[T]) SelectBy ¶
func (r *BaseRepo[T]) SelectBy(condition map[string]interface{}, results *[]*T, opts ...SelOpt) error
SelectBy 按照条件查找多条 可使用链式方法添加order和limit等参数
func (*BaseRepo[T]) UpdateBy ¶
func (r *BaseRepo[T]) UpdateBy(condition map[string]interface{}, updateValues map[string]interface{}) (int64, error)
UpdateBy 根据条件更新记录
func (*BaseRepo[T]) UpdateById ¶
UpdateById 按照ID更新一条
func (*BaseRepo[T]) UpsertByID ¶
UpsertByID 非显式事务(onConflict和clauses),固定根据id查找记录,如果存在则更新,如果不存在则创建
type Pagination ¶
type Pagination[T any] struct { TotalRecords int64 `json:"totalRecords"` TotalPages int64 `json:"totalPages"` CurrentPage uint32 `json:"currentPage"` PageSize uint32 `json:"pageSize"` Records []*T `json:"records"` }
Pagination 定义
Click to show internal directories.
Click to hide internal directories.