query

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultPageSize defines the default number of results to select per page.
	DefaultPageSize = 30

	SortOrderAsc  = "asc"
	SortOrderDesc = "desc"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute struct {
	Name string
	// contains filtered or unexported fields
}

Attribute defines a transaction event attribute.

func NewAttribute

func NewAttribute(name string, value []byte) Attribute

NewAttribute creates a new transaction event attribute.

func (Attribute) Value

func (a Attribute) Value() (v any, err error)

Value returns the attribute value. Event attribute values are originally encoded as JSON. This method decodes the event value into its Go representation.

type Cursor

type Cursor interface {
	// Err returns the last error seen by the Cursor, or nil if no error has occurred.
	Err() error

	// Next prepares the next result to be read with the Scan method.
	// It returns true on success, or false if there is no next result row or an error
	// happened while preparing it. Err should be consulted to distinguish between the
	// two cases.
	//
	// Every call to Scan, even the first one, must be preceded by a call to Next.
	Next() bool

	// Scan copies the query row into the pointed values.
	Scan(values ...any) error

	// Close closes the cursor preventing further iterations.
	// If Next is called and returns false and there are no further result sets,
	// the cursor is closed automatically and it will suffice to check the result of Err.
	// This method is idempotent meaning that after the first call, any subsequent calls
	// will not change the state.
	Close() error
}

Cursor defines a cursor to iterate query results.

type Event

type Event struct {
	ID         int64
	TXHash     string
	Index      uint64
	Type       string
	Attributes []Attribute
	CreatedAt  time.Time
}

Event defines a transaction event.

type EventQuery

type EventQuery interface {
	Pager
	Filterer
}

EventQuery describes how to select event values from a data backend.

func NewEventQuery

func NewEventQuery(options ...Option) EventQuery

NewEventQuery creates a new query that selects events.

type Filter

type Filter interface {
	fmt.Stringer

	// Field returns the name of the filtered field.
	Field() string

	// Value returns the value to use for filtering.
	Value() any
}

Filter describes a filter to apply to a query.

type Filterer

type Filterer interface {
	// Filters returns the list of filters to apply to the query.
	Filters() []Filter
}

Filterer describes support for filtering query results.

type Option

type Option func(*Query)

Option configures queries.

func AtPage

func AtPage(page uint32) Option

AtPage assigns a page to select. Pages start from page one, so assigning page zero selects the first page.

func Fields

func Fields(fields ...string) Option

Fields assigns the field names to query. The default is to select all fields.

func SortByFields

func SortByFields(order string, fields ...string) Option

SortByFields orders the query by one or more fields. Use `WithSortBy` option when multiple order by directions are needed.

func WithArgs

func WithArgs(args ...any) Option

WithArgs adds one or more arguments to the query.

func WithFilters

func WithFilters(f ...Filter) Option

WithFilters adds one or more filters to apply to the query.

func WithPageSize

func WithPageSize(size uint32) Option

WithPageSize assigns the number of results to select per page. The default page size is used when size zero is assigned.

func WithSortBy

func WithSortBy(o ...SortBy) Option

WithSortBy orders the query by one or more fields.

func WithoutPaging

func WithoutPaging() Option

WithoutPaging disables the paging of results. All results are selected when paging is disabled.

type Pager

type Pager interface {
	// PageSize returns the size for each query result set.
	PageSize() uint32

	// AtPage returns the result set page to query.
	AtPage() uint32

	// IsPagingEnabled checks if the query results should be paginated.
	IsPagingEnabled() bool
}

Pager describes support for paging query results.

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query describes how to select values from a data backend.

func New

func New(name string, options ...Option) Query

New creates a new query that selects results from an entity. The name is the name of an entity which depending on the data backend have different meanings. In a relational database the name should be a table, function or view, while in a NoSQL database it should be a collection.

func (Query) Args

func (q Query) Args() []any

Args returns the arguments for query. Arguments are used when the query calls a function in the data backend.

func (Query) AtPage

func (q Query) AtPage() uint32

AtPage returns the result set page to query.

func (Query) Fields

func (q Query) Fields() []string

Fields returns list of field names to select.

func (Query) Filters

func (q Query) Filters() []Filter

Filters returns the list of filters to apply to the query.

func (Query) IsPagingEnabled

func (q Query) IsPagingEnabled() bool

IsPagingEnabled checks if the query results should be paginated.

func (Query) Name

func (q Query) Name() string

Name returns the name of the database table, collection, view or function to select.

func (Query) PageSize

func (q Query) PageSize() uint32

PageSize returns the size for each query result set.

func (Query) SortBy

func (q Query) SortBy() []SortBy

SortBy returns the sort info for the query.

type SortBy

type SortBy struct {
	Field string
	Order string
}

SortBy contains info on how to sort query results.

Jump to

Keyboard shortcuts

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