Documentation ¶
Index ¶
- Variables
- func FromCursor(val []byte) uint64
- func FromInterval(val Interval) (string, error)
- func FromIntervalWithFallback(val Interval, fallback string) string
- func FromOrdering(val Ordering) (string, error)
- func FromOrderingWithFallback(val Ordering, fallback string) string
- func PaginateQuery(query string, opts []interface{}, cursor Cursor, limit uint64, ...) (string, []interface{})
- type Cursor
- type Filter
- type Interval
- type Option
- type Ordering
- type QueryOptions
- type SupportedOptions
Constants ¶
This section is empty.
Variables ¶
View Source
var AllIntervals = []Interval{ IntervalRaw, IntervalHour, IntervalDay, IntervalWeek, IntervalMonth, }
View Source
var (
ErrQueryNotSupported = errors.New("the requested query option is not supported")
)
Functions ¶
func FromCursor ¶
func FromInterval ¶
func FromOrdering ¶
func PaginateQuery ¶
func PaginateQuery(query string, opts []interface{}, cursor Cursor, limit uint64, direction Ordering) (string, []interface{})
PaginateQuery returns a paginated query string for the given input options.
The input query string is expected as follows:
"SELECT ... WHERE (...)" <- these brackets are not optional
The output query string would be as follows:
"SELECT ... WHERE (...) AND id > ? ORDER BY ? LIMIT ?" -or- "SELECT ... WHERE (...) AND id < ? ORDER BY ? LIMIT ?"
Example:
query := "SELECT * FROM table WHERE (state = $1 OR age > $2)" opts := []interface{}{ state: 123, age: 45, } cursor := 123 limit := 10 direction := Ascending PaginateQuery(query, opts, cursor, limit, direction) > "SELECT * FROM table WHERE (state = $1 OR age > $2) AND cursor > $3 ORDER BY id ASC LIMIT 10"
Types ¶
type Option ¶
type Option func(*QueryOptions) error
func WithCursor ¶
func WithDirection ¶
func WithEndTime ¶
func WithFilter ¶
func WithInterval ¶
func WithStartTime ¶
type Ordering ¶
type Ordering uint
The ordering of a returned set of records
func ToOrdering ¶
func ToOrderingWithFallback ¶
type QueryOptions ¶
type QueryOptions struct { Supported SupportedOptions Start time.Time End time.Time Interval Interval SortBy Ordering Limit uint64 Cursor Cursor FilterBy Filter }
func DefaultPaginationHandler ¶
func DefaultPaginationHandler(opts ...Option) (*QueryOptions, error)
func DefaultPaginationHandlerWithLimit ¶
func DefaultPaginationHandlerWithLimit(limit uint64, opts ...Option) (*QueryOptions, error)
func (*QueryOptions) Apply ¶
func (qo *QueryOptions) Apply(opts ...Option) error
type SupportedOptions ¶
type SupportedOptions byte
const ( CanLimitResults SupportedOptions = 0x01 CanSortBy SupportedOptions = 0x01 << 1 CanBucketBy SupportedOptions = 0x01 << 2 CanQueryByCursor SupportedOptions = 0x01 << 3 CanQueryByStartTime SupportedOptions = 0x01 << 4 CanQueryByEndTime SupportedOptions = 0x01 << 5 CanFilterBy SupportedOptions = 0x01 << 6 )
Click to show internal directories.
Click to hide internal directories.