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 ¶
- func FilterOnExperiment(tableName string, columns []string, selectCount bool, experimentID string) (sq.SelectBuilder, error)
- func FilterOnNamespace(tableName string, columns []string, selectCount bool, namespace string) (sq.SelectBuilder, error)
- func FilterOnResourceReference(tableName string, columns []string, resourceType common.ResourceType, ...) (sq.SelectBuilder, error)
- func ScanRowToTotalSize(rows *sql.Rows) (int, error)
- type Listable
- type Options
- func (o *Options) AddFilterToSelect(sqlBuilder sq.SelectBuilder) sq.SelectBuilder
- func (o *Options) AddPaginationToSelect(sqlBuilder sq.SelectBuilder) sq.SelectBuilder
- func (o *Options) AddSortingToSelect(sqlBuilder sq.SelectBuilder) sq.SelectBuilder
- func (o *Options) Matches(opts *Options) bool
- func (o *Options) NextPageToken(listable Listable) (string, error)
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 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
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 ¶
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.