db2

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: Apache-2.0, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package db2 is the replacement for db. It provides low level db connection and query capabilities.

Index

Constants

View Source
const (
	// DefaultPageSize is the default page size for db queries
	DefaultPageSize = 10
	// MaxPageSize is the max page size for db queries
	MaxPageSize = 200

	// OrderAscending is used to indicate an ascending order in request params
	OrderAscending = "asc"

	// OrderDescending is used to indicate an descending order in request params
	OrderDescending = "desc"

	// DefaultPairSep is the default separator used to separate two numbers for CursorInt64Pair
	DefaultPairSep = "-"
)

Variables

View Source
var (
	// ErrInvalidOrder is an error that occurs when a user-provided order string
	// is invalid
	ErrInvalidOrder = &InvalidFieldError{"order"}
	// ErrInvalidLimit is an error that occurs when a user-provided limit num
	// is invalid
	ErrInvalidLimit = &InvalidFieldError{"limit"}
	// ErrInvalidCursor is an error that occurs when a user-provided cursor string
	// is invalid
	ErrInvalidCursor = &InvalidFieldError{"cursor"}
)

Functions

This section is empty.

Types

type InvalidFieldError

type InvalidFieldError struct {
	Name string
}

func (*InvalidFieldError) Error

func (e *InvalidFieldError) Error() string

type PageQuery

type PageQuery struct {
	Cursor string
	Order  string
	Limit  uint64
}

PageQuery represents a portion of a Query struct concerned with paging through a large dataset.

func MustPageQuery

func MustPageQuery(cursor string, validateCursor bool, order string, limit uint64) PageQuery

MustPageQuery behaves as NewPageQuery, but panics upon error

func NewPageQuery

func NewPageQuery(
	cursor string,
	validateCursor bool,
	order string,
	limit uint64,
) (result PageQuery, err error)

NewPageQuery creates a new PageQuery struct, ensuring the order, limit, and cursor are set to the appropriate defaults and are valid.

func (PageQuery) ApplyRawTo

func (p PageQuery) ApplyRawTo(
	sql sq.SelectBuilder,
	col string,
) (sq.SelectBuilder, error)

ApplyRawTo applies the raw PageQuery.Cursor cursor to the builder

func (PageQuery) ApplyTo

func (p PageQuery) ApplyTo(
	sql sq.SelectBuilder,
	col string,
) (sq.SelectBuilder, error)

ApplyTo returns a new SelectBuilder after applying the paging effects of `p` to `sql`. This method provides the default case for paging: int64 cursor-based paging by an id column.

func (PageQuery) ApplyToUsingCursor

func (p PageQuery) ApplyToUsingCursor(
	sql sq.SelectBuilder,
	col string,
	cursor interface{},
) (sq.SelectBuilder, error)

ApplyToUsingCursor returns a new SelectBuilder after applying the paging effects of `p` to `sql`. This method allows any type of cursor by a single column

func (PageQuery) CursorInt64

func (p PageQuery) CursorInt64() (int64, error)

CursorInt64 parses this query's Cursor string as an int64

func (PageQuery) CursorInt64Pair

func (p PageQuery) CursorInt64Pair(sep string) (l int64, r int64, err error)

CursorInt64Pair parses this query's Cursor string as two int64s, separated by the provided separator

func (PageQuery) Invert

func (p PageQuery) Invert() PageQuery

Invert returns a new PageQuery whose order is reversed

Directories

Path Synopsis
Package history contains database record definitions useable for reading rows from a the history portion of horizon's database
Package history contains database record definitions useable for reading rows from a the history portion of horizon's database

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL