Documentation ¶
Index ¶
- func DatabaseError(message string, golangError error) httperrors.HTTPError
- type CRUDRepository
- type CRUDRepositoryImpl
- func (repository *CRUDRepositoryImpl[T, ID]) Count(filters squirrel.Sqlizer) (uint, httperrors.HTTPError)
- func (repository *CRUDRepositoryImpl[T, ID]) Create(entity *T) httperrors.HTTPError
- func (repository *CRUDRepositoryImpl[T, ID]) Delete(entity *T) httperrors.HTTPError
- func (repository *CRUDRepositoryImpl[T, ID]) Find(filters squirrel.Sqlizer, page pagination.Paginator, sortOption SortOption) (*pagination.Page[T], httperrors.HTTPError)
- func (repository *CRUDRepositoryImpl[T, ID]) GetAll(sortOption SortOption) ([]*T, httperrors.HTTPError)
- func (repository *CRUDRepositoryImpl[T, ID]) GetByID(id ID) (*T, httperrors.HTTPError)
- func (repository *CRUDRepositoryImpl[T, ID]) Save(entity *T) httperrors.HTTPError
- func (repository *CRUDRepositoryImpl[T, ID]) Transaction(transactionFunction func(CRUDRepository[T, ID]) (any, error)) (any, httperrors.HTTPError)
- type SortOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DatabaseError ¶
func DatabaseError(message string, golangError error) httperrors.HTTPError
Return a database error
Types ¶
type CRUDRepository ¶
type CRUDRepository[T models.Tabler, ID any] interface { Create(*T) httperrors.HTTPError Delete(*T) httperrors.HTTPError Save(*T) httperrors.HTTPError GetByID(ID) (*T, httperrors.HTTPError) GetAll(SortOption) ([]*T, httperrors.HTTPError) Count(squirrel.Sqlizer) (uint, httperrors.HTTPError) Find(squirrel.Sqlizer, pagination.Paginator, SortOption) (*pagination.Page[T], httperrors.HTTPError) Transaction(fn func(CRUDRepository[T, ID]) (any, error)) (any, httperrors.HTTPError) }
Generic CRUD Repository
func NewCRUDRepository ¶
func NewCRUDRepository[T models.Tabler, ID any]( database *gorm.DB, logger *zap.Logger, paginationConfiguration configuration.PaginationConfiguration, ) CRUDRepository[T, ID]
Contructor of the Generic CRUD Repository
type CRUDRepositoryImpl ¶
type CRUDRepositoryImpl[T models.Tabler, ID any] struct { CRUDRepository[T, ID] // contains filtered or unexported fields }
Implementation of the Generic CRUD Repository
func (*CRUDRepositoryImpl[T, ID]) Count ¶
func (repository *CRUDRepositoryImpl[T, ID]) Count(filters squirrel.Sqlizer) (uint, httperrors.HTTPError)
Count entities of a models
func (*CRUDRepositoryImpl[T, ID]) Create ¶
func (repository *CRUDRepositoryImpl[T, ID]) Create(entity *T) httperrors.HTTPError
Create an entity of a Model
func (*CRUDRepositoryImpl[T, ID]) Delete ¶
func (repository *CRUDRepositoryImpl[T, ID]) Delete(entity *T) httperrors.HTTPError
Delete an entity of a Model
func (*CRUDRepositoryImpl[T, ID]) Find ¶
func (repository *CRUDRepositoryImpl[T, ID]) Find( filters squirrel.Sqlizer, page pagination.Paginator, sortOption SortOption, ) (*pagination.Page[T], httperrors.HTTPError)
Find entities of a Model
func (*CRUDRepositoryImpl[T, ID]) GetAll ¶
func (repository *CRUDRepositoryImpl[T, ID]) GetAll(sortOption SortOption) ([]*T, httperrors.HTTPError)
Get all entities of a Model
func (*CRUDRepositoryImpl[T, ID]) GetByID ¶
func (repository *CRUDRepositoryImpl[T, ID]) GetByID(id ID) (*T, httperrors.HTTPError)
Get an entity of a Model By ID
func (*CRUDRepositoryImpl[T, ID]) Save ¶
func (repository *CRUDRepositoryImpl[T, ID]) Save(entity *T) httperrors.HTTPError
Save an entity of a Model
func (*CRUDRepositoryImpl[T, ID]) Transaction ¶
func (repository *CRUDRepositoryImpl[T, ID]) Transaction(transactionFunction func(CRUDRepository[T, ID]) (any, error)) (any, httperrors.HTTPError)
Run the function passed as parameter, if it returns the error and rollback the transaction. If no error is returned, it commits the transaction and return the interface{} value.
type SortOption ¶
Click to show internal directories.
Click to hide internal directories.