Documentation
¶
Overview ¶
Package crdbx implements cursor pagination for crdb.
Index ¶
- Variables
- func AsOfSystemTime(ctx context.Context, value any) context.Context
- func ContextAsOfSystemTime(ctx context.Context, defaultTime any) any
- func Limit(limit int) int
- type Cursor
- type FormatValues
- func (v FormatValues) AndWhere(next int) string
- func (v FormatValues) AsOfSystemTime() string
- func (v FormatValues) LimitClause() string
- func (v FormatValues) Order(fields ...string) string
- func (v FormatValues) OrderClause(fields ...string) string
- func (v FormatValues) Values(values ...any) []any
- func (v FormatValues) Where(next int) string
- func (v FormatValues) WhereClause(next int) string
- func (v FormatValues) WithQualifier(q string) FormatValues
- type Pagination
- type Paginator
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidPaginationCursor = errors.New("invalid pagination cursor")
ErrInvalidPaginationCursor is returned when there's an error handling the cursor.
Functions ¶
func AsOfSystemTime ¶
AsOfSystemTime sets the `AS OF SYSTEM TIME` context value to be used.
func ContextAsOfSystemTime ¶
ContextAsOfSystemTime retrieves the `AS OF SYSTEM TIME` value from the context. If no value is found the default value is returned.
Types ¶
type Cursor ¶
type Cursor string
Cursor handles encoding and decoding a pagination cursor values.
func MustNewCursor ¶
MustNewCursor calls NewCursor. If an error is returned panic is called.
func NewCursorFromValues ¶
NewCursorFromValues creates a new pagination cursor from url values.
func (*Cursor) MarshalJSON ¶
MarshalJSON implements json marshaller.
type FormatValues ¶
type FormatValues struct {
// contains filtered or unexported fields
}
FormatValues contains the necessary values to extend a query for pagination.
func Paginate ¶
func Paginate(p Paginator, asOfSystemTime any) FormatValues
Paginate handles setting the pagination for the request.
func (FormatValues) AndWhere ¶
func (v FormatValues) AndWhere(next int) string
AndWhere returns the conditions prefixed by `AND` if conditions have been defined. See FormatValues.Where for more details.
func (FormatValues) AsOfSystemTime ¶
func (v FormatValues) AsOfSystemTime() string
AsOfSystemTime if set will be formatted as `AS OF SYSTEM TIME` followed by a value. This value should be included directly after a `FROM` in the query.
func (FormatValues) LimitClause ¶
func (v FormatValues) LimitClause() string
LimitClause returns the `LIMIT` clause. If no limit is setup the default limit of `10` is used.
func (FormatValues) Order ¶
func (v FormatValues) Order(fields ...string) string
Order provides the `ORDER BY` clause value. Additional fields may be included to build the final value. Fields are included in addition to configured order field are used as is.
func (FormatValues) OrderClause ¶
func (v FormatValues) OrderClause(fields ...string) string
OrderClause provides the `ORDER BY` clause. Additional fields may be included, see FormatValues.Order for more details.
func (FormatValues) Values ¶
func (v FormatValues) Values(values ...any) []any
Values returns the values to be used in a query. Additional values may be included and will be first in the combined values slice.
func (FormatValues) Where ¶
func (v FormatValues) Where(next int) string
Where returns the conditions to be added to a where clause. Next provides the offset for defining bind values. If your query includes additional values, this value should be set to the next unused number. For example if you had the query `SELECT * FROM users WHERE country=$1`. The value you should use here is `2`.
func (FormatValues) WhereClause ¶
func (v FormatValues) WhereClause(next int) string
WhereClause returns a full WHERE clause including the conditions if defined. See FormatValues.Where for more details.
func (FormatValues) WithQualifier ¶
func (v FormatValues) WithQualifier(q string) FormatValues
WithQualifier sets all field qualifiers for referenced fields.
type Pagination ¶
Pagination define pagination query parameters.
func (Pagination) GetCursor ¶
func (p Pagination) GetCursor() *Cursor
GetCursor implements Paginator returning the cursor
func (Pagination) GetLimit ¶
func (p Pagination) GetLimit() int
GetLimit implements Paginator returning the effective limit.
func (Pagination) GetOnlyFields ¶
func (p Pagination) GetOnlyFields() []string
GetOnlyFields implements Paginator returning the permitted fields.