Documentation
¶
Index ¶
- Constants
- Variables
- type DatabaseError
- type EntityCRUD
- type EntityCreator
- type EntityDeleter
- type EntityReader
- type EntityTable
- type EntityUpdater
- type Pagination
- func (p *Pagination) Count() uint
- func (p *Pagination) HasNext() bool
- func (p *Pagination) HasOtherPages() bool
- func (p *Pagination) HasPrev() bool
- func (p *Pagination) NextPage() uint
- func (p *Pagination) NumPages() uint
- func (p *Pagination) Offset() uint
- func (p *Pagination) PrevPage() uint
- func (p *Pagination) SetTotal(total uint)
- type SortDirection
- type SortParameters
Constants ¶
const ( // DefaultPerPage defines the default value for pagination DefaultPerPage uint = 20 )
Variables ¶
var ( // ErrNotImplemented is the error raised when the method is not implemented ErrNotImplemented = errors.New("Method not implemented !") // ErrNoResult is the error raised when the query result no results ErrNoResult = errors.New("No result found !") )
Functions ¶
This section is empty.
Types ¶
type DatabaseError ¶
type DatabaseError struct {
// contains filtered or unexported fields
}
DatabaseError is the wrapper for RethinkDB errors that allows passing more data with the message
func NewDatabaseError ¶
func NewDatabaseError(t EntityTable, err error, message string) *DatabaseError
NewDatabaseError creates a new DatabaseError, wraps err and adds a message
func (*DatabaseError) Error ¶
func (d *DatabaseError) Error() string
type EntityCRUD ¶
type EntityCRUD interface {
EntityCreator
EntityReader
EntityUpdater
EntityDeleter
EntityTable
}
EntityCRUD is the interface that every table should implement
type EntityCreator ¶
type EntityCreator interface {
Insert(data interface{}) error
InsertOrUpdate(id interface{}, data interface{}) error
}
EntityCreator contains a function to create new instances in the table
type EntityDeleter ¶
EntityDeleter allows deleting resources from the database
type EntityReader ¶
type EntityReader interface {
Find(id interface{}, result interface{}) error
FindOneBy(key string, value interface{}, result interface{}) error
FindBy(key string, value interface{}, results interface{}) error
FindByAndCount(key string, value interface{}) (int, error)
Where(filter interface{}, results interface{}) error
WhereCount(filter interface{}) (int, error)
WhereAndFetchOne(filter interface{}, result interface{}) error
WhereAndFetchLimit(filter interface{}, paginator *Pagination, results interface{}) error
List(results interface{}, sortParams *SortParameters, pagination *Pagination) error
Search(results interface{}, filter interface{}, sortParams *SortParameters, pagination *Pagination) error
}
EntityReader allows fetching resources from the database
type EntityTable ¶
type EntityTable interface {
GetTableName() string
GetDBName() string
GetTable() interface{}
GetSession() interface{}
}
EntityTable contains the most basic table functions
type EntityUpdater ¶
type EntityUpdater interface {
Update(selector interface{}, data interface{}) error
UpdateID(id interface{}, data interface{}) error
}
EntityUpdater allows updating existing resources in the database
type Pagination ¶
Pagination is a pagination calcul handler for database request.
func NewPaginator ¶
func NewPaginator(page, perPage uint) *Pagination
NewPaginator returns a pagination holder
func NewPaginatorFromRequest ¶
func NewPaginatorFromRequest(r *http.Request) *Pagination
NewPaginatorFromRequest returns a paginator builded from an http request
func (*Pagination) Count ¶
func (p *Pagination) Count() uint
Count returns the total number of items
func (*Pagination) HasNext ¶
func (p *Pagination) HasNext() bool
HasNext returns the status if current page has a next one
func (*Pagination) HasOtherPages ¶
func (p *Pagination) HasOtherPages() bool
HasOtherPages returns the status of having previous or next pages
func (*Pagination) HasPrev ¶
func (p *Pagination) HasPrev() bool
HasPrev returns the status if current page has a previous one
func (*Pagination) NextPage ¶
func (p *Pagination) NextPage() uint
NextPage returns the page number for the next page. won't go past the end
func (*Pagination) NumPages ¶
func (p *Pagination) NumPages() uint
NumPages returns the total number of pages
func (*Pagination) Offset ¶
func (p *Pagination) Offset() uint
Offset returns the offset of first element
func (*Pagination) PrevPage ¶
func (p *Pagination) PrevPage() uint
PrevPage returns the page number for the page before this bottoms out at the first page
func (*Pagination) SetTotal ¶
func (p *Pagination) SetTotal(total uint)
SetTotal is used to defines the total count of paginated values.
type SortDirection ¶
type SortDirection int
SortDirection is the enumeration for sort
const ( // Ascending sort from bottom to up Ascending SortDirection = iota + 1 // Descending sort from up to bottom Descending )
func (SortDirection) String ¶
func (m SortDirection) String() string
type SortParameters ¶
type SortParameters map[string]SortDirection
SortParameters contains a hashmap of field name with sort direction
func SortConverter ¶
func SortConverter(sorts []string) *SortParameters
SortConverter convert a list of string to a SortParameters instance