gormrepo

package
v0.0.0-...-1cbb08c Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CustomPagination

func CustomPagination(pagination *Pagination) string

func Paginate

func Paginate(pagination *Pagination) func(db *gorm.DB) *gorm.DB

Types

type ITable

type ITable interface {
	TableName() string
}

type Pagination

type Pagination struct {
	Page     int
	PageSize int
}

func (*Pagination) GetLimit

func (p *Pagination) GetLimit() int

func (*Pagination) GetOffset

func (p *Pagination) GetOffset() int

func (*Pagination) GetPage

func (p *Pagination) GetPage() int

func (*Pagination) SetPage

func (p *Pagination) SetPage(page int)

func (*Pagination) SetPageSize

func (p *Pagination) SetPageSize(pageSize int)

type Repo

type Repo[T ITable] struct {
	Db *gorm.DB
	// contains filtered or unexported fields
}

func NewRepo

func NewRepo[T ITable](db *gorm.DB) Repo[T]

func (*Repo[T]) BaseModel

func (r *Repo[T]) BaseModel(ctx context.Context, arg ...func(*gorm.DB)) *gorm.DB

func (*Repo[T]) BatchCreate

func (r *Repo[T]) BatchCreate(ctx context.Context, data []*T) error

func (*Repo[T]) Create

func (r *Repo[T]) Create(ctx context.Context, data *T) error

func (*Repo[T]) DeleteById

func (r *Repo[T]) DeleteById(ctx context.Context, id int64) error

func (*Repo[T]) DeleteWhere

func (r *Repo[T]) DeleteWhere(ctx context.Context, where string, args ...interface{}) error

func (*Repo[T]) FindAll

func (r *Repo[T]) FindAll(ctx context.Context, arg ...func(*gorm.DB)) ([]*T, error)

func (*Repo[T]) FindById

func (r *Repo[T]) FindById(ctx context.Context, id int64) (*T, error)

func (*Repo[T]) FindByIds

func (r *Repo[T]) FindByIds(ctx context.Context, ids []int64) ([]*T, error)

func (*Repo[T]) FindByWhere

func (r *Repo[T]) FindByWhere(ctx context.Context, where string, args ...any) (*T, error)

func (*Repo[T]) FindCustom

func (r *Repo[T]) FindCustom(ctx context.Context, arg ...func(*gorm.DB)) (*T, error)

func (*Repo[T]) Model

func (r *Repo[T]) Model(ctx context.Context) *gorm.DB

func (*Repo[T]) QueryCount

func (r *Repo[T]) QueryCount(ctx context.Context, where string, args ...any) (int64, error)

func (*Repo[T]) QueryExist

func (r *Repo[T]) QueryExist(ctx context.Context, where string, args ...any) (bool, error)

func (*Repo[T]) SelectFindById

func (r *Repo[T]) SelectFindById(ctx context.Context, where string, id int64) (*T, error)

func (*Repo[T]) SelectFindByWhere

func (r *Repo[T]) SelectFindByWhere(ctx context.Context, sel string, where string, args ...interface{}) (*T, error)

func (*Repo[T]) Txx

func (r *Repo[T]) Txx(ctx context.Context, fc func(tx *gorm.DB) error) error

func (*Repo[T]) UpdateById

func (r *Repo[T]) UpdateById(ctx context.Context, id any, data map[string]any) (int64, error)

func (*Repo[T]) UpdateWhere

func (r *Repo[T]) UpdateWhere(ctx context.Context, data map[string]any, where string, args ...any) (int64, error)

Jump to

Keyboard shortcuts

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