Documentation
¶
Index ¶
- Constants
- Variables
- type DB
- type Filter
- type Grouper
- type Joiner
- type MockDB
- type MockFilter
- type MockGrouper
- type MockJoiner
- type MockWhereTyper
- type MockWherer
- type MultiFilter
- type PaginatedResponse
- type Paginator
- func (p *Paginator) Counts(dest *int64) error
- func (p *Paginator) First() (string, error)
- func (p *Paginator) ParseRequest(req *http.Request, sortColumns ...string) error
- func (p *Paginator) Pivot() (string, error)
- func (p *Paginator) Retrieve(pivot string, dest any) error
- func (p *Paginator) SetDetails(paginatorDetails *PaginatorDetails, sortColumns ...string) error
- type PaginatorDetails
- type WhereType
- type WhereTyper
- type Wherer
Constants ¶
const ( // Equal is the equal comparison operator Equal = "eq" // LessThan is the less than comparison operator LessThan = "lt" // GreaterThan is the greater than comparison operator GreaterThan = "gt" // Like is the partial match operator Like = "like" // DefaultSortBy is the default sort by key DefaultSortBy = "id" QueryLastVal = "last_val" QueryLastID = "last_id" QuerySortBy = "sort_by" QuerySortDir = "sort_dir" QueryLimit = "limit" )
Variables ¶
var (
ErrInvalidPaginatorDetails = errors.New("invalid paginator details")
)
var ( // ErrNoDestination is returned when the destination is nil ErrNoDestination = errors.New("destination is nil") )
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB interface { Get(dest any, query string, args ...any) error Select(dest any, query string, args ...any) error }
DB is the common interface for database operations
This should work with database/sql.DB and database/sql.Tx.
type Grouper ¶
type Grouper interface {
Group() []string
}
Grouper represents something which can provide a group by to filter a sql query. Grouper support should only ever be used with a filter that adds the table/column refs that it needs to function, otherwise you will likely have a bad time.
type MockDB ¶
MockDB is an autogenerated mock type for the DB type
func NewMockDB ¶
NewMockDB creates a new instance of MockDB. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
type MockFilter ¶
MockFilter is an autogenerated mock type for the Filter type
func NewMockFilter ¶
func NewMockFilter(t interface { mock.TestingT Cleanup(func()) }) *MockFilter
NewMockFilter creates a new instance of MockFilter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockFilter) Join ¶
func (_m *MockFilter) Join() (string, []interface{})
Join provides a mock function with no fields
func (*MockFilter) Where ¶
func (_m *MockFilter) Where() (string, []interface{})
Where provides a mock function with no fields
type MockGrouper ¶
MockGrouper is an autogenerated mock type for the Grouper type
func NewMockGrouper ¶
func NewMockGrouper(t interface { mock.TestingT Cleanup(func()) }) *MockGrouper
NewMockGrouper creates a new instance of MockGrouper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockGrouper) Group ¶
func (_m *MockGrouper) Group() []string
Group provides a mock function with no fields
type MockJoiner ¶
MockJoiner is an autogenerated mock type for the Joiner type
func NewMockJoiner ¶
func NewMockJoiner(t interface { mock.TestingT Cleanup(func()) }) *MockJoiner
NewMockJoiner creates a new instance of MockJoiner. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockJoiner) Join ¶
func (_m *MockJoiner) Join() (string, []interface{})
Join provides a mock function with no fields
type MockWhereTyper ¶
MockWhereTyper is an autogenerated mock type for the WhereTyper type
func NewMockWhereTyper ¶
func NewMockWhereTyper(t interface { mock.TestingT Cleanup(func()) }) *MockWhereTyper
NewMockWhereTyper creates a new instance of MockWhereTyper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockWhereTyper) Where ¶
func (_m *MockWhereTyper) Where() (string, []interface{})
Where provides a mock function with no fields
func (*MockWhereTyper) WhereType ¶
func (_m *MockWhereTyper) WhereType() WhereType
WhereType provides a mock function with no fields
type MockWherer ¶
MockWherer is an autogenerated mock type for the Wherer type
func NewMockWherer ¶
func NewMockWherer(t interface { mock.TestingT Cleanup(func()) }) *MockWherer
NewMockWherer creates a new instance of MockWherer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockWherer) Where ¶
func (_m *MockWherer) Where() (string, []interface{})
Where provides a mock function with no fields
type MultiFilter ¶
type MultiFilter struct {
// contains filtered or unexported fields
}
func NewMultiFilter ¶
func NewMultiFilter() *MultiFilter
func (*MultiFilter) Add ¶
func (m *MultiFilter) Add(f any)
func (*MultiFilter) Group ¶
func (m *MultiFilter) Group() []string
func (*MultiFilter) Join ¶
func (m *MultiFilter) Join() (sqlStr string, args []any)
func (*MultiFilter) Where ¶
func (m *MultiFilter) Where() (sqlStr string, args []any)
type PaginatedResponse ¶
type PaginatedResponse[T comparable] struct { // Items is the list of items that are returned. Items []*T `json:"items"` // Total is the total number of items that have been found in the source. Total int64 `json:"total"` }
PaginatedResponse is a response that contains a list of items and the total number of items. This is useful for when you want to return a paginated list of items.
type Paginator ¶
type Paginator struct {
// contains filtered or unexported fields
}
Paginator is the struct that provides the paging.
func NewPaginator ¶
NewPaginator creates a new paginator
func (*Paginator) Counts ¶
Counts returns the total number of records in the table given the provided filters. This does not take into account of the current pivot or limit.
func (*Paginator) First ¶
First is used when no details are provided which could give us the pivot point It will pick a start depending on the provided sort and filters.
func (*Paginator) ParseRequest ¶
ParseRequest parses the request to handle retrieving all the pagination and sorting parameters
func (*Paginator) Retrieve ¶
Retrieve pulls the next page given the pivot point and requires a destination *[]struct to load the data into.
func (*Paginator) SetDetails ¶
func (p *Paginator) SetDetails(paginatorDetails *PaginatorDetails, sortColumns ...string) error
SetDetails sets paginator details from the passed in arguments.
type PaginatorDetails ¶
type PaginatorDetails struct { Limit int LastVal string LastID string SortBy string SortDir string // contains filtered or unexported fields }
PaginatorDetails contains pagination details
func DetailsFromRequest ¶
func DetailsFromRequest(req *http.Request) (*PaginatorDetails, error)
DetailsFromRequest retrieves the paginator details from the request.
func GetPaginatorDetails ¶
func GetPaginatorDetails( limit *common.LimitParam, lastVal *common.LastValue, lastID *common.LastId, sortBy *common.SortBy, sortDir *common.SortDirection, ) *PaginatorDetails
GetPaginatorDetails loads paginator details from a request. Requests have each pagination detail determined separately by codegen.
func (*PaginatorDetails) RemoveLimit ¶
func (p *PaginatorDetails) RemoveLimit()
RemoveLimit removes the limit from the paginator details.
type WhereTyper ¶
WhereTyper is an interface that can be used to specify the type of WHERE clause to use. By using this interface, you can specify whether to use an "AND" or "OR" WHERE clause.