repository

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(arr []string, str string) bool

Contains checks if value present in array

func ContainsKey

func ContainsKey(keyValuePair map[string][]string, keyToCheck string) bool

ContainsKey checks if key present in map

func DoesColumnExistInTable

func DoesColumnExistInTable(uow *UnitOfWork, tableName string, ColumnName string) bool

DoesColumnExistInTable returns bool if the column exist in table

Types

type GormRepository

type GormRepository struct {
}

GormRepository implements Repository

func (*GormRepository) Add

func (repository *GormRepository) Add(uow *UnitOfWork, entity interface{}) microappError.DatabaseError

Add specified Entity

func (*GormRepository) AddAssociations

func (repository *GormRepository) AddAssociations(uow *UnitOfWork, out interface{}, associationName string, associations ...interface{}) microappError.DatabaseError

AddAssociations adds associations to the given out entity

func (*GormRepository) CheckVersionAndUpdate added in v1.13.2

func (repository *GormRepository) CheckVersionAndUpdate(uow *UnitOfWork, entity interface{}, queryProcessors []QueryProcessor) microappError.DatabaseError

CheckVersionAndUpdate specified Entity after checking for version change

func (*GormRepository) Delete

func (repository *GormRepository) Delete(uow *UnitOfWork, entity interface{}, where ...interface{}) microappError.DatabaseError

Delete specified Entity

func (*GormRepository) DeleteForTenant

func (repository *GormRepository) DeleteForTenant(uow *UnitOfWork, entity interface{}, tenantID uuid.UUID) microappError.DatabaseError

DeleteForTenant all recrod(s) of specified entity / entity type for given tenant

func (*GormRepository) DeletePermanent

func (repository *GormRepository) DeletePermanent(uow *UnitOfWork, entity interface{}, where ...interface{}) microappError.DatabaseError

DeletePermanent deletes record permanently specified Entity

func (*GormRepository) Get

func (repository *GormRepository) Get(uow *UnitOfWork, out interface{}, id uuid.UUID, preloadAssociations []string) microappError.DatabaseError

Get a record for specified entity with specific id

func (*GormRepository) GetAll

func (repository *GormRepository) GetAll(uow *UnitOfWork, out interface{}, queryProcessors []QueryProcessor) microappError.DatabaseError

GetAll retrieves all the records for a specified entity and returns it

func (*GormRepository) GetAllForTenant

func (repository *GormRepository) GetAllForTenant(uow *UnitOfWork, out interface{}, tenantID uuid.UUID, queryProcessors []QueryProcessor) microappError.DatabaseError

GetAllForTenant returns all objects of specifeid tenantID

func (*GormRepository) GetAllUnscoped

func (repository *GormRepository) GetAllUnscoped(uow *UnitOfWork, out interface{}, queryProcessors []QueryProcessor) microappError.DatabaseError

GetAllUnscoped retrieves all the records (including deleted) for a specified entity and returns it

func (*GormRepository) GetAllUnscopedForTenant

func (repository *GormRepository) GetAllUnscopedForTenant(uow *UnitOfWork, out interface{}, tenantID uuid.UUID, queryProcessors []QueryProcessor) microappError.DatabaseError

GetAllUnscopedForTenant returns all objects (including deleted) of specifeid tenantID

func (*GormRepository) GetCount

func (repository *GormRepository) GetCount(uow *UnitOfWork, count *int64, entity interface{}, queryProcessors []QueryProcessor) microappError.DatabaseError

GetCount gets count of the given entity type

func (*GormRepository) GetCountForTenant

func (repository *GormRepository) GetCountForTenant(uow *UnitOfWork, count *int64, tenantID uuid.UUID, entity interface{}, queryProcessors []QueryProcessor) microappError.DatabaseError

GetCountForTenant gets count of the given entity type for specified tenant

func (*GormRepository) GetFirst

func (repository *GormRepository) GetFirst(uow *UnitOfWork, out interface{}, queryProcessors []QueryProcessor) microappError.DatabaseError

GetFirst gets first record matching the given criteria

func (*GormRepository) GetForTenant

func (repository *GormRepository) GetForTenant(uow *UnitOfWork, out interface{}, id string, tenantID uuid.UUID, preloadAssociations []string) microappError.DatabaseError

GetForTenant a record for specified entity with specific id and for specified tenant

func (*GormRepository) RemoveAssociations

func (repository *GormRepository) RemoveAssociations(uow *UnitOfWork, out interface{}, associationName string, associations ...interface{}) microappError.DatabaseError

RemoveAssociations removes associations from the given out entity

func (*GormRepository) ReplaceAssociations

func (repository *GormRepository) ReplaceAssociations(uow *UnitOfWork, out interface{}, associationName string, associations ...interface{}) microappError.DatabaseError

ReplaceAssociations removes associations from the given out entity

func (*GormRepository) Update

func (repository *GormRepository) Update(uow *UnitOfWork, entity interface{}) microappError.DatabaseError

Update specified Entity

type QueryProcessor

type QueryProcessor func(db *gorm.DB, out interface{}) (*gorm.DB, microappError.DatabaseError)

QueryProcessor allows to modify the query before it is executed

func AddFiltersFromQueryParams

func AddFiltersFromQueryParams(r *http.Request, filterDetails ...string) ([]QueryProcessor, error)

AddFiltersFromQueryParams will check for given filter(s) in the query params, if value found creates the db filter. filterDetail format - "filterName[:type]".

func AddFiltersFromQueryParamsWithOR

func AddFiltersFromQueryParamsWithOR(r *http.Request, filterDetails ...string) ([]QueryProcessor, error)

AddFiltersFromQueryParamsWithOR will check for given filter(s) in the query params, if value found adds it in array and creates the db filter. filterDetail format - "filterName[:type]". Same field Filters are using 'OR' , 'AND' would be done between different fields

func Filter

func Filter(condition string, args ...interface{}) QueryProcessor

Filter will filter the results

func FilterWithOR

func FilterWithOR(columnName []string, condition []string, filterValues []interface{}) QueryProcessor

FilterWithOR will filter the results with an 'OR'

func GetOrderBy

func GetOrderBy(orderByAttrs []string, validOrderByAttrs []string, orderByAttrAndDBCloum map[string][]string, reorder bool) (QueryProcessor, error)

GetOrderBy creates order by query processor orderByAttrs - ["column1:0", "column2:1"], validOrderByAttrs - ["column1", "column2", "column3"], orderByAttrAndDBCloum - {"cloumn3": ["dbColunm4", "dbColumn5"]}

func Order

func Order(value interface{}, reorder bool) QueryProcessor

Order will order the results

func Paginate

func Paginate(limit int, offset int, count *int64) QueryProcessor

Paginate will restrict the output of query

func PaginateForWeb

func PaginateForWeb(w http.ResponseWriter, r *http.Request) QueryProcessor

PaginateForWeb will take limit and offset parameters from URL and will set X-Total-Count header in response

func PreloadAssociations

func PreloadAssociations(preloadAssociations []string) QueryProcessor

PreloadAssociations specified associations to be preloaded

func TimeRangeForWeb

func TimeRangeForWeb(r *http.Request, fieldName string) QueryProcessor

TimeRangeForWeb will take limit and offset parameters from URL and will set X-Total-Count header in response

type Repository

type Repository interface {
	Get(uow *UnitOfWork, out interface{}, id uuid.UUID, preloadAssociations []string) microappError.DatabaseError
	GetFirst(uow *UnitOfWork, out interface{}, queryProcessors []QueryProcessor) microappError.DatabaseError
	GetForTenant(uow *UnitOfWork, out interface{}, id string, tenantID uuid.UUID, preloadAssociations []string) microappError.DatabaseError
	GetAll(uow *UnitOfWork, out interface{}, queryProcessors []QueryProcessor) microappError.DatabaseError
	GetAllForTenant(uow *UnitOfWork, out interface{}, tenantID uuid.UUID, queryProcessors []QueryProcessor) microappError.DatabaseError
	GetAllUnscoped(uow *UnitOfWork, out interface{}, queryProcessors []QueryProcessor) microappError.DatabaseError
	GetAllUnscopedForTenant(uow *UnitOfWork, out interface{}, tenantID uuid.UUID, queryProcessors []QueryProcessor) microappError.DatabaseError
	GetCount(uow *UnitOfWork, out *int64, entity interface{}, queryProcessors []QueryProcessor) microappError.DatabaseError
	GetCountForTenant(uow *UnitOfWork, out *int64, tenantID uuid.UUID, entity interface{}, queryProcessors []QueryProcessor) microappError.DatabaseError
	CheckVersionAndUpdate(uow *UnitOfWork, entity interface{}, queryProcessors []QueryProcessor) microappError.DatabaseError

	Add(uow *UnitOfWork, out interface{}) microappError.DatabaseError
	Update(uow *UnitOfWork, out interface{}) microappError.DatabaseError
	Delete(uow *UnitOfWork, out interface{}, where ...interface{}) microappError.DatabaseError
	DeleteForTenant(uow *UnitOfWork, out interface{}, tenantID uuid.UUID) microappError.DatabaseError
	DeletePermanent(uow *UnitOfWork, out interface{}, where ...interface{}) microappError.DatabaseError

	AddAssociations(uow *UnitOfWork, out interface{}, associationName string, associations ...interface{}) microappError.DatabaseError
	RemoveAssociations(uow *UnitOfWork, out interface{}, associationName string, associations ...interface{}) microappError.DatabaseError
	ReplaceAssociations(uow *UnitOfWork, out interface{}, associationName string, associations ...interface{}) microappError.DatabaseError
}

Repository represents generic interface for interacting with DB

func NewRepository

func NewRepository() Repository

NewRepository returns a new repository object

type UnitOfWork

type UnitOfWork struct {
	DB *gorm.DB
	// contains filtered or unexported fields
}

UnitOfWork represents a connection

func NewUnitOfWork

func NewUnitOfWork(db *gorm.DB, readOnly bool) *UnitOfWork

NewUnitOfWork creates new UnitOfWork

func (*UnitOfWork) Commit

func (uow *UnitOfWork) Commit()

Commit the transaction

func (*UnitOfWork) Complete

func (uow *UnitOfWork) Complete()

Complete marks end of unit of work

Jump to

Keyboard shortcuts

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