Documentation
¶
Index ¶
- Constants
- Variables
- func ForFiltersFromParams(ctx context.Context, model interface{}, params buffalo.ParamValues) (pop.ScopeFunc, error)
- func ForFirst() pop.ScopeFunc
- func ForID(id string) pop.ScopeFunc
- func ForIDForModel(id string, model interface{}) pop.ScopeFunc
- func ForIDSet(idSet IDSet) pop.ScopeFunc
- func ForIDWithTableName(id string, tablename string) pop.ScopeFunc
- func ForIDs(ids []uuid.UUID) pop.ScopeFunc
- func ForLast() pop.ScopeFunc
- func ForLimit(limit int) pop.ScopeFunc
- func ForNotNull(field string) pop.ScopeFunc
- func ForNotNullDeletedAt() pop.ScopeFunc
- func ForNotNullDeletedAtForModel(model interface{}) pop.ScopeFunc
- func ForNotUuidID(uid uuid.UUID) pop.ScopeFunc
- func ForNull(field string) pop.ScopeFunc
- func ForNullDeletedAt() pop.ScopeFunc
- func ForNullDeletedAtForModel(model interface{}) pop.ScopeFunc
- func ForNullsUuidID(uid nulls.UUID) pop.ScopeFunc
- func ForOne() pop.ScopeFunc
- func ForOrder(orderClauses ...string) pop.ScopeFunc
- func ForPaginateFromParams(params buffalo.ParamValues) pop.ScopeFunc
- func ForSortFromParams(ctx context.Context, model interface{}, params buffalo.ParamValues) (pop.ScopeFunc, error)
- func ForUuidID(uid uuid.UUID) pop.ScopeFunc
- func GetAggregations(ctx context.Context, tx *pop.Connection, modelsPtr interface{}, ...) (interface{}, error)
- func GetAggregationsFromParams(ctx context.Context, tx *pop.Connection, modelsPtr interface{}, ...) (interface{}, error)
- func GetAllFilterColumnNames(ctx context.Context, modelPtr interface{}) ([]string, error)
- func GetAllSortColumnNames(ctx context.Context, modelPtr interface{}) ([]string, error)
- func GetFilterOptions(ctx context.Context, tx *pop.Connection, modelsPtr interface{}, ...) ([]interface{}, error)
- func GetGroupedAggregations(ctx context.Context, tx *pop.Connection, modelsPtr interface{}, ...) ([]interface{}, error)
- func GetGroupedAggregationsFromParams(ctx context.Context, tx *pop.Connection, modelsPtr interface{}, ...) ([]interface{}, error)
- type Aggregation
- type Aggregations
- type Collection
- type CustomColumn
- type CustomColumns
- type CustomFilterable
- type CustomSortable
- type IDSet
- type StandardAggregationsType
Constants ¶
const FailQuery = "1=0"
Variables ¶
var StandardAggregations = map[StandardAggregationsType]Aggregation{ StandardAggregationsTypeCount: { Name: string(StandardAggregationsTypeCount), Statement: string(StandardAggregationsTypeCount), ResultType: reflect.TypeOf(0), }, StandardAggregationsTypeSum: { Name: string(StandardAggregationsTypeSum), Statement: string(StandardAggregationsTypeSum), ResultType: nil, }, StandardAggregationsTypeAvg: { Name: string(StandardAggregationsTypeAvg), Statement: string(StandardAggregationsTypeAvg), ResultType: nil, }, StandardAggregationsTypeMax: { Name: string(StandardAggregationsTypeMax), Statement: string(StandardAggregationsTypeMax), ResultType: nil, }, StandardAggregationsTypeMin: { Name: string(StandardAggregationsTypeMin), Statement: string(StandardAggregationsTypeMin), ResultType: nil, }, }
Functions ¶
func ForFiltersFromParams ¶
func ForFiltersFromParams(ctx context.Context, model interface{}, params buffalo.ParamValues) (pop.ScopeFunc, error)
ForFiltersFromParams filters a model based on the provided filter params.
func ForFirst ¶
func ForFirst() pop.ScopeFunc
ForFirst scopes a query for the first record in a table based on the `created_at` timestamp.
The first record is the oldest record.
func ForIDForModel ¶
func ForIDForModel(id string, model interface{}) pop.ScopeFunc
func ForIDWithTableName ¶
func ForLast ¶
func ForLast() pop.ScopeFunc
ForLast scopes a query for the last record in a table based on the `created_at` timestamp.
The last record is the newest record.
func ForNotNull ¶
func ForNotNull(field string) pop.ScopeFunc
ForNotNull scopes for a supplied field being not null.
func ForNotNullDeletedAt ¶
func ForNotNullDeletedAt() pop.ScopeFunc
func ForNotNullDeletedAtForModel ¶
func ForNotNullDeletedAtForModel(model interface{}) pop.ScopeFunc
func ForNotUuidID ¶
func ForNull ¶
func ForNull(field string) pop.ScopeFunc
ForNull scopes for a supplied field being null.
func ForNullDeletedAt ¶
func ForNullDeletedAt() pop.ScopeFunc
func ForNullDeletedAtForModel ¶
func ForNullDeletedAtForModel(model interface{}) pop.ScopeFunc
func ForNullsUuidID ¶
func ForOrder ¶
func ForOrder(orderClauses ...string) pop.ScopeFunc
ForOrder is a generic scope function for ordering.
func ForPaginateFromParams ¶
func ForPaginateFromParams(params buffalo.ParamValues) pop.ScopeFunc
ForPaginateFromParams paginates a query based on a list of parameters, generally c.Params()
func ForSortFromParams ¶
func ForSortFromParams(ctx context.Context, model interface{}, params buffalo.ParamValues) (pop.ScopeFunc, error)
ForSortFromParams orders a query based on the provided query params.
func GetAggregations ¶
func GetAggregations(ctx context.Context, tx *pop.Connection, modelsPtr interface{}, columnNames []string, scopes *Collection, aggregations Aggregations) (interface{}, error)
GetAggregations returns the aggregated value for column `columnName` of modelsPtr, restricting by the scope collection `scopes`.
`columnName` is either a CustomColumn returned by the CustomFilterable interface, or a field specified by the json tag. This is the same as the acceptable values for `filter_columns` in ForFiltersFromParams.
func GetAggregationsFromParams ¶
func GetAggregationsFromParams(ctx context.Context, tx *pop.Connection, modelsPtr interface{}, params buffalo.ParamValues, scopes *Collection) (interface{}, error)
GetAggregationsFromParams aggregates a modelsPtr based on params, restricting by the scope collection scopes.
func GetAllFilterColumnNames ¶
GetAllFilterColumnNames is a utility in order to automatically get a list of all tags that can be filtered on for the referenced model.
func GetAllSortColumnNames ¶
GetAllSortColumnNames is a utility in order to automatically get a list of all tags that can be sorted on for the referenced model.
func GetFilterOptions ¶
func GetFilterOptions(ctx context.Context, tx *pop.Connection, modelsPtr interface{}, columnName string, scopes *Collection) ([]interface{}, error)
GetFilterOptions returns all of unique values for column 'columnName' of modelsPtr, restricting by the scope collection scopes.
'columnName' is either a CustomColumn returned by the CustomFilterable interface, or a field specified by the json tag. This is the same as the acceptable values for 'filter_columns' in ForFiltersFromParams.
func GetGroupedAggregations ¶
func GetGroupedAggregations(ctx context.Context, tx *pop.Connection, modelsPtr interface{}, columnNames []string, grouperName string, scopes *Collection, aggregations Aggregations) ([]interface{}, error)
GetGroupedAggregations returns the aggregated value for column `columnName` of modelsPtr, grouped by `grouperName` of modelsPtr, restricting by the scope collection `scopes`.
`columnName` is either a CustomColumn returned by the CustomFilterable interface, or a field specified by the json tag. This is the same as the acceptable values for `filter_columns` in ForFiltersFromParams.
func GetGroupedAggregationsFromParams ¶
func GetGroupedAggregationsFromParams(ctx context.Context, tx *pop.Connection, modelsPtr interface{}, params buffalo.ParamValues, scopes *Collection) ([]interface{}, error)
GetGroupedAggregationsFromParams groups and aggregates a modelsPtr based on params, restricting by the scope collection scopes.
Types ¶
type Aggregations ¶
type Aggregations []Aggregation
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
func NewCollection ¶
func NewCollection(tx ...*pop.Connection) *Collection
func (*Collection) Dedupe ¶
func (sc *Collection) Dedupe() *Collection
func (*Collection) Flatten ¶
func (sc *Collection) Flatten() pop.ScopeFunc
func (*Collection) Get ¶
func (sc *Collection) Get() []pop.ScopeFunc
func (*Collection) Push ¶
func (sc *Collection) Push(scopes ...pop.ScopeFunc) *Collection
type CustomColumn ¶
CustomColumn represents a SQL statement that can be used like a column in a SQL query. CustomColumns are used in order to create filter and sort options that are more complex than simply sorting on a single field. For example:
Given an object with a db column 'test_int', in order to sort on the TEXT converted value of 'test_int' you would implement 'CustomSortable' and provide the CustomColumn:
{ Name: "test_int_text_value", Statement: "test_int::TEXT", ResultType: reflect.TypeOf(""), }
Statement can be any valid sql Statement that returns a single value. ResultType is the type of the value returned by statement, and is used to scan the value from the DB.
func GetAllFilterColumns ¶
func GetAllFilterColumns(ctx context.Context, modelPtr interface{}) ([]CustomColumn, error)
GetAllFilterColumns is a utility in order to automatically get a list of all columns that can be filtered on for the referenced model.
func GetAllSortColumns ¶
func GetAllSortColumns(ctx context.Context, modelPtr interface{}) ([]CustomColumn, error)
GetAllSortColumns is a utility in order to automatically get a list of all columns that can be sorted on for the referenced model.
type CustomColumns ¶
type CustomColumns []CustomColumn
func GenerateCustomColumnsForSubobject ¶
func GenerateCustomColumnsForSubobject(subobjectPtr interface{}, subobjectJsonTag, joinClause string, optionalTablename ...string) (CustomColumns, error)
GenerateCustomColumnsForSubobject is a utility in order to automatically create custom filter columns for a model related to the model you are filtering.
For example, assume you have a table Houses, and each house has an address_id field pointing to an Addresses table. In order to make houses sortable by the columns of the Address table, you will need to implement 'CustomSortable' and return the following:
GenerateCustomColumnsForSubobject(&Address{}, "address", "addresses.id = houses.address_id")
Which will return a list of CustomColumns derived from the fields of the `&Address{}` model.
CustomColumns{ { Name: "address.id", Statement: "(select id from addresses where addresses.id = houses.address_id)", ResultType: reflect.TypeOf(""), }, { Name: "address.city", Statement: "(select city from addresses where addresses.id = houses.address_id)", ResultType: reflect.TypeOf(""), }, ... }
type CustomFilterable ¶
type CustomFilterable interface {
GetCustomFilters(ctx context.Context) CustomColumns
}
type CustomSortable ¶
type CustomSortable interface {
GetCustomSorts(ctx context.Context) CustomColumns
}
type StandardAggregationsType ¶
type StandardAggregationsType string
const ( StandardAggregationsTypeCount StandardAggregationsType = "COUNT" StandardAggregationsTypeSum StandardAggregationsType = "SUM" StandardAggregationsTypeAvg StandardAggregationsType = "AVG" StandardAggregationsTypeMax StandardAggregationsType = "MAX" StandardAggregationsTypeMin StandardAggregationsType = "MIN" )