repository

package
v2.3.38 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repo

type Repo[C model.Model] struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository[C model.Model](db *gorm.DB, fieldSearchable clause.FieldSearchable, fieldOrderBy clause.FieldOrderBy) Repo[C]

func (Repo[C]) Count

func (r Repo[C]) Count(ctx context.Context, query string, args ...any) (int64, error)

func (Repo[C]) Create

func (r Repo[C]) Create(ctx context.Context, u *C, returning ...string) (*C, error)

func (Repo[C]) Create2 added in v2.0.4

func (r Repo[C]) Create2(ctx context.Context, u *[]C, returning ...string) (*[]C, error)

func (Repo[C]) CreateOrUpdate

func (r Repo[C]) CreateOrUpdate(ctx context.Context, u *C, onConflict []interface{}, doUpdates []interface{}, doCreates []interface{}, returning ...string) (*C, error)

func (Repo[C]) DB

func (r Repo[C]) DB() *gorm.DB

func (Repo[C]) Delete

func (r Repo[C]) Delete(ctx context.Context, query string, args ...any) error

func (Repo[C]) Error

func (r Repo[C]) Error(ctx context.Context, err error) error

func (Repo[C]) Exists

func (r Repo[C]) Exists(ctx context.Context, field string, value interface{}, excludeField string, excludeValue interface{}) error

func (Repo[C]) FieldOrderBy added in v2.3.0

func (r Repo[C]) FieldOrderBy() clause.FieldOrderBy

func (Repo[C]) FieldSearchable

func (r Repo[C]) FieldSearchable() clause.FieldSearchable

func (Repo[C]) Find

func (r Repo[C]) Find(ctx context.Context, query string, args ...any) (*C, error)

func (Repo[C]) FindById

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

func (Repo[C]) FirstOrCreate

func (r Repo[C]) FirstOrCreate(ctx context.Context, u *C, returning string, query string, args ...any) (*C, error)

func (Repo[C]) Joins

func (r Repo[C]) Joins(models ...string) Repo[C]

func (Repo[C]) List

func (r Repo[C]) List(ctx context.Context, f *model.Filter, query string, args ...any) ([]C, error)

func (Repo[C]) Model

func (r Repo[C]) Model() C

func (Repo[C]) Omit

func (r Repo[C]) Omit(columns ...string) Repo[C]

func (Repo[C]) OrderBy

func (r Repo[C]) OrderBy(orderBy []clause.ExpressionOrderBy) (Repo[C], error)

func (Repo[C]) Paginate

func (r Repo[C]) Paginate(ctx context.Context, p *model.Meta[C], query string, args ...any) error

func (Repo[C]) PluckIDs added in v2.3.0

func (r Repo[C]) PluckIDs(ctx context.Context, query string, args ...any) ([]int, error)

func (Repo[C]) QuoteTo added in v2.0.24

func (r Repo[C]) QuoteTo(str string) string

func (Repo[C]) SetDB

func (r Repo[C]) SetDB(db *gorm.DB) Repo[C]

func (Repo[C]) Trx

func (r Repo[C]) Trx(db *gorm.DB) Repo[C]

func (Repo[C]) Update

func (r Repo[C]) Update(ctx context.Context, u *C, selects []interface{}, query string, args ...any) error

func (Repo[C]) Update2 added in v2.0.4

func (r Repo[C]) Update2(ctx context.Context, u *[]C, selects []interface{}, query string, args ...any) error

func (Repo[C]) UpdateMap added in v2.0.4

func (r Repo[C]) UpdateMap(ctx context.Context, u map[string]interface{}, query string, args ...any) error

func (Repo[C]) Where

func (r Repo[C]) Where(where *clause.ExpressionWhere) (Repo[C], error)

func (Repo[C]) With

func (r Repo[C]) With(models ...string) Repo[C]

type Repository

type Repository[T any, C model.Model] interface {
	Trx(db *gorm.DB) T
	With(models ...string) T
	Joins(models ...string) T
	Omit(columns ...string) T
	Find(ctx context.Context, query string, args ...any) (*C, error)
	FindById(ctx context.Context, id int) (*C, error)
	Delete(ctx context.Context, query string, args ...any) error
	Create(ctx context.Context, u *C, returning ...string) (*C, error)
	Create2(ctx context.Context, u *[]C, returning ...string) (*[]C, error)
	CreateOrUpdate(ctx context.Context, u *C, onConflict []interface{}, doUpdates []interface{}, doCreates []interface{}, returning ...string) (*C, error)
	FirstOrCreate(ctx context.Context, u *C, returning string, query string, args ...any) (*C, error)
	Update(ctx context.Context, u *C, selects []interface{}, query string, args ...any) error
	Update2(ctx context.Context, u *[]C, selects []interface{}, query string, args ...any) error
	UpdateMap(ctx context.Context, u map[string]interface{}, query string, args ...any) error
	Count(ctx context.Context, query string, args ...any) (int64, error)
	List(ctx context.Context, f *model.Filter, query string, args ...any) ([]C, error)
	Paginate(ctx context.Context, p *model.Meta[C], query string, args ...any) error
	PluckIDs(ctx context.Context, query string, args ...any) ([]int, error)
	DB() *gorm.DB
}

Jump to

Keyboard shortcuts

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