list

package
v1.7.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: Apache-2.0 Imports: 11 Imported by: 3

Documentation

Overview

Package list contains types and methods for performing ListXXX operations. In particular, the package exports the Options struct, which can be used for applying listing, filtering and pagination logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterOnExperiment

func FilterOnExperiment(
	tableName string,
	columns []string,
	selectCount bool,
	experimentID string,
) (sq.SelectBuilder, error)

FilterOnExperiment filters the given table by rows based on provided experiment ID, and returns the rebuilt SelectBuilder

func FilterOnNamespace

func FilterOnNamespace(
	tableName string,
	columns []string,
	selectCount bool,
	namespace string,
) (sq.SelectBuilder, error)

func FilterOnResourceReference

func FilterOnResourceReference(tableName string, columns []string, resourceType common.ResourceType,
	selectCount bool, filterContext *common.FilterContext) (sq.SelectBuilder, error)

FilterOnResourceReference filters the given resource's table by rows from the ResourceReferences table that match an optional given filter, and returns the rebuilt SelectBuilder

func ScanRowToTotalSize

func ScanRowToTotalSize(rows *sql.Rows) (int, error)

Scans the one given row into a number, and returns the number

Types

type Listable

type Listable interface {
	// PrimaryKeyColumnName returns the primary key for model.
	PrimaryKeyColumnName() string
	// DefaultSortField returns the default field name to be used when sorting list
	// query results.
	DefaultSortField() string
	// APIToModelFieldMap returns a map from field names in the API representation
	// of the model to its corresponding field name in the model itself.
	APIToModelFieldMap() map[string]string
	// GetModelName returns table name used as sort field prefix.
	GetModelName() string
	// Get the prefix of sorting field.
	GetSortByFieldPrefix(string) string
	// Get the prefix of key field.
	GetKeyFieldPrefix() string
	// Get a valid field for sorting/filtering in a listable model from the given string.
	GetField(name string) (string, bool)
	// Find the value of a given field in a listable object.
	GetFieldValue(name string) interface{}
}

Listable is an interface that should be implemented by any resource/model that wants to support listing queries.

type Options

type Options struct {
	PageSize int
	// contains filtered or unexported fields
}

Options represents options used when making a ListXXX query. In particular, it contains information on how to sort and filter results. It also encapsulates all the logic required for making the query for an initial set of results as well as subsequent pages of results.

func NewOptions

func NewOptions(listable Listable, pageSize int, sortBy string, filterProto *api.Filter) (*Options, error)

NewOptions creates a new Options struct for the given listable. It uses sorting and filtering criteria parsed from sortBy and filterProto respectively.

func NewOptionsFromToken

func NewOptionsFromToken(nextPageToken string, pageSize int) (*Options, error)

NewOptionsFromToken creates a new Options struct from the passed in token which represents the next page of results. An empty nextPageToken will result in an error.

func (*Options) AddFilterToSelect

func (o *Options) AddFilterToSelect(sqlBuilder sq.SelectBuilder) sq.SelectBuilder

AddFilterToSelect adds WHERE clauses with the filtering criteria in the Options o to the supplied SelectBuilder, and returns the new SelectBuilder containing these.

func (*Options) AddPaginationToSelect

func (o *Options) AddPaginationToSelect(sqlBuilder sq.SelectBuilder) sq.SelectBuilder

AddPaginationToSelect adds WHERE clauses with the sorting and pagination criteria in the Options o to the supplied SelectBuilder, and returns the new SelectBuilder containing these.

func (*Options) AddSortingToSelect

func (o *Options) AddSortingToSelect(sqlBuilder sq.SelectBuilder) sq.SelectBuilder

AddSortingToSelect adds Order By clause.

func (*Options) Matches

func (o *Options) Matches(opts *Options) bool

Matches returns trues if the sorting and filtering criteria in o matches that of the one supplied in opts.

func (*Options) NextPageToken

func (o *Options) NextPageToken(listable Listable) (string, error)

NextPageToken returns a string that can be used to fetch the subsequent set of results using the same listing options in o, starting with listable as the first record.

Jump to

Keyboard shortcuts

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