repository

package
v0.0.84 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains added in v0.0.84

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

Contains checks if value present in array

func ContainsKey added in v0.0.84

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

ContainsKey checks if key present in map

func DoesColumnExistInTable added in v0.0.84

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

DoesColumnExistInTable returns bool if the column exist in table

func GetOrderType added in v0.0.84

func GetOrderType(order string) string

GetOrderType returns the type of order

Types

type GormRepository

type GormRepository struct {
}

GormRepository implements Repository

func (*GormRepository) Add

func (repository *GormRepository) Add(uow *UnitOfWork, entity interface{}) error

Add specified Entity

func (*GormRepository) Delete

func (repository *GormRepository) Delete(uow *UnitOfWork, entity interface{}) error

Delete specified Entity

func (*GormRepository) Get

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

Get a record for specified entity with specific id

func (*GormRepository) GetAll

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

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

func (*GormRepository) GetAllForTenant added in v0.0.6

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

GetAllForTenant returns all objects of specifeid tenantID

func (*GormRepository) Update

func (repository *GormRepository) Update(uow *UnitOfWork, entity interface{}) error

Update specified Entity

type QueryProcessor added in v0.0.23

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

QueryProcessor allows to modify the query before it is executed

func AddFiltersFromQueryParams added in v0.0.78

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 added in v0.0.82

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]". All Filters are using 'OR'

func Filter added in v0.0.23

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

Filter will filter the results

func FilterWithOR added in v0.0.81

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

FilterWithOR will filter the results based on OR

func GetOrder added in v0.0.84

func GetOrder(orderBy string, validSortingColumn []string, subsituteKeyWithValue map[string][]string) (QueryProcessor, error)

GetOrder will check for valid sorting columns, substituting column and return the Order Query. Format for orderBy : ColumnName1:1,ColumnName2:0 etc. 0 -> Asc, 1 -> Desc Format For SubsituteKeyWithValue : map[string][]string{"Key": []string{"Value1", "Value2"}}

func Order added in v0.0.76

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

Order will filter the results

func Paginate added in v0.0.23

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

Paginate will restrict the output of query

func PaginateForWeb added in v0.0.26

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 added in v0.0.23

func PreloadAssociations(preloadAssociations []string) QueryProcessor

PreloadAssociations specified associations to be preloaded

func TimeRangeForWeb added in v0.0.42

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) error
	GetAll(uow *UnitOfWork, out interface{}, queryProcessors []QueryProcessor) error
	GetAllForTenant(uow *UnitOfWork, out interface{}, tenantID uuid.UUID, queryProcessors []QueryProcessor) error
	Add(uow *UnitOfWork, out interface{}) error
	Update(uow *UnitOfWork, out interface{}) error
	Delete(uow *UnitOfWork, out interface{}) error
}

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