repository

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GormRepository

type GormRepository struct {
	// contains filtered or unexported fields
}

func (GormRepository) AutoMigrateOrWarn

func (r GormRepository) AutoMigrateOrWarn(models ...interface{})

AutoMigrateOrWarn create tables for the given models or print a warning message if there's an error

func (GormRepository) Count

func (r GormRepository) Count(model, query interface{}, args ...interface{}) (count int64, err error)

Count count total number of records for the given query

func (*GormRepository) Create

func (r *GormRepository) Create(target interface{}) error

func (*GormRepository) CreateTx

func (r *GormRepository) CreateTx(target interface{}, tx *gorm.DB) error

func (*GormRepository) DB

func (r *GormRepository) DB() *gorm.DB

func (*GormRepository) DBWithPreloads

func (r *GormRepository) DBWithPreloads(preloads []string) *gorm.DB

func (*GormRepository) Delete

func (r *GormRepository) Delete(target interface{}) error

func (*GormRepository) DeleteTx

func (r *GormRepository) DeleteTx(target interface{}, tx *gorm.DB) error

func (GormRepository) FindPage

func (r GormRepository) FindPage(page, perPage uint, query *gorm.DB, out interface{}) (Page, error)

FindPage page finding records

func (*GormRepository) GetAll

func (r *GormRepository) GetAll(target interface{}, preloads ...string) error

func (*GormRepository) GetByField

func (r *GormRepository) GetByField(target interface{}, field string, value interface{}, preloads ...string) error

func (*GormRepository) GetByFields

func (r *GormRepository) GetByFields(target interface{}, filters map[string]interface{}, preloads ...string) error

func (*GormRepository) GetOneByField

func (r *GormRepository) GetOneByField(target interface{}, field string, value interface{}, preloads ...string) error

func (*GormRepository) GetOneByFields

func (r *GormRepository) GetOneByFields(target interface{}, filters map[string]interface{}, preloads ...string) error

func (*GormRepository) GetOneByID

func (r *GormRepository) GetOneByID(target interface{}, id string, preloads ...string) error

func (*GormRepository) GetWhere

func (r *GormRepository) GetWhere(target interface{}, condition string, preloads ...string) error

func (*GormRepository) HandleError

func (r *GormRepository) HandleError(res *gorm.DB) error

func (*GormRepository) HandleOneError

func (r *GormRepository) HandleOneError(res *gorm.DB) error

func (*GormRepository) Save

func (r *GormRepository) Save(target interface{}) error

func (*GormRepository) SaveTx

func (r *GormRepository) SaveTx(target interface{}, tx *gorm.DB) error

type Page

type Page struct {
	Total   uint
	Page    uint
	PerPage uint
	Pages   uint
}

Holds information about result page

type Repository

type Repository interface {
	GetAll(target interface{}, preloads ...string) error
	GetWhere(target interface{}, condition string, preloads ...string) error
	GetByField(target interface{}, field string, value interface{}, preloads ...string) error
	GetByFields(target interface{}, filters map[string]interface{}, preloads ...string) error

	GetOneByField(target interface{}, field string, value interface{}, preloads ...string) error
	GetOneByFields(target interface{}, filters map[string]interface{}, preloads ...string) error
	GetOneByID(target interface{}, id string, preloads ...string) error

	Create(target interface{}) error
	Save(target interface{}) error
	Delete(target interface{}) error

	FindPage(page, perPage uint, query *gorm.DB, out interface{}) (Page, error)
	Count(model, query interface{}, args ...interface{}) (count int64, err error)

	DB() *gorm.DB
	DBWithPreloads(preloads []string) *gorm.DB
	HandleError(res *gorm.DB) error
	HandleOneError(res *gorm.DB) error

	AutoMigrateOrWarn(models ...interface{})
}

Repository is a generic DB handler that cares about default error handling

type TransactionRepository

type TransactionRepository interface {
	Repository
	CreateTx(target interface{}, tx *gorm.DB) error
	SaveTx(target interface{}, tx *gorm.DB) error
	DeleteTx(target interface{}, tx *gorm.DB) error
}

TransactionRepository extends Repository with modifier functions that accept a transaction

func NewGormRepository

func NewGormRepository(db *gorm.DB, logger *glog.Logger, defaultJoins ...string) TransactionRepository

NewGormRepository returns a new base repository that implements TransactionRepository

Jump to

Keyboard shortcuts

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