db2

package
v0.0.0-...-b1bd2f5 Latest Latest
Warning

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

Go to latest
Published: May 7, 2019 License: Apache-2.0 Imports: 7 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"}
	// ErrNotPageable is an error that occurs when the records provided to
	// PageQuery.GetContinuations cannot be cast to Pageable
	ErrNotPageable = errors.New("Records provided are not Pageable")
)

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) 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) GetContinuations

func (p PageQuery) GetContinuations(records interface{}) (next PageQuery, prev PageQuery, err error)

GetContinuations returns two new PageQuery structs, a next and previous query.

func (PageQuery) Invert

func (p PageQuery) Invert() PageQuery

Invert returns a new PageQuery whose order is reversed

type Pageable

type Pageable interface {
	PagingToken() string
}

Pageable records have a defined order, and the place withing that order is determined by the paging token

Directories

Path Synopsis
Package core contains database record definitions useable for reading rows from a Stellar Core db
Package core contains database record definitions useable for reading rows from a Stellar Core db
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
Package sqx contains utilities and extensions for the squirrel package which is used by horizon to generate sql statements.
Package sqx contains utilities and extensions for the squirrel package which is used by horizon to generate sql statements.

Jump to

Keyboard shortcuts

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