persistence

package
v0.0.0-...-d389d3b Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DSN

func DSN(config *config.DatabaseConfig) string

func FindUsingTemplate

func FindUsingTemplate[T any, C any](
	ctx context.Context,
	gorm *gorm.DB,
	queryTemplateEngine sqlTemplate.QueryTemplateEngine,
	namespace string,
	name string,
	criteriaAndPagination *models.CriteriaAndPagination[C],
) (*T, error)

FindUsingTemplate cannot be part of the repository until https://github.com/golang/go/issues/49085 is fixed.

func FindUsingTemplatePageable

func FindUsingTemplatePageable[T any, C any](
	ctx context.Context,
	gorm *gorm.DB,
	queryTemplateEngine sqlTemplate.QueryTemplateEngine,
	namespace string,
	name string,
	criteriaAndPagination *models.CriteriaAndPagination[C],
) (*models.Page[*T], error)

FindUsingTemplatePageable cannot be part of the repository until https://github.com/golang/go/issues/49085 is fixed.

Types

type Database

type Database struct {
	*gorm.DB
}

Database modal.

func NewDatabase

func NewDatabase(config *config.AppConfig, logger logger.Logger) (Database, error)

NewDatabase creates a new database instance.

type EntityRepository

type EntityRepository[T common.EntityConstraint] interface {
	WithTx(tx *gorm.DB) EntityRepository[T]
	TransactWithDefaultRetry(operation func(tx *gorm.DB) error) error
	FindOneByID(ctx context.Context, id uint) (entity *T, err error)
	FindOneByIDForUpdate(ctx context.Context, id uint) (entity *T, err error)
	FindAll(ctx context.Context, pagination *models.Pagination) (page *models.Page[*T], err error)
	FindAllByCriteria(
		ctx context.Context, criteriaAndPagination any, pagination *models.Pagination) (page *models.Page[*T], err error)
	Create(ctx context.Context, entity *T) (*T, error)
	Save(ctx context.Context, entity *T) (*T, error)
	DeleteByID(ctx context.Context, id uint) error
	Count(ctx context.Context) (int64, error)
	Gorm() *gorm.DB
	WrapError(err error) error
}

func NewEntityRepository

func NewEntityRepository[T common.EntityConstraint](
	database Database,
	entity T,
	logger logger.Logger,
	config *config.AppConfig,
) EntityRepository[T]

type Repository

type Repository interface {
	WithTx(tx *gorm.DB) Repository
	RawSQL(ctx context.Context, sql string, values ...any) error
	Gorm() *gorm.DB
	WrapError(err error) error
}

func NewRepository

func NewRepository(
	database Database,
	logger logger.Logger,
	config *config.AppConfig,
	queryTemplateEngine sqlTemplate.QueryTemplateEngine,
) Repository

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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