Documentation
¶
Overview ¶
Package query holds the query builders used in an entity schema.
Index ¶
- type Aggregate
- type CreateOperations
- type Func
- type ListAllOperations
- type ListByOperations
- type OrderColumn
- type Query
- func (q Query) Contracts(contracts ...entlite.Layer) QueryOperations
- func (q Query) GetAggregates() []Aggregate
- func (q Query) GetContracts() []entlite.Layer
- func (q Query) GetDistinct() []string
- func (q Query) GetFields() []string
- func (q Query) GetFilters() []filter.Filter
- func (q Query) GetGroupBy() []string
- func (q Query) GetLimit() int
- func (q Query) GetName() string
- func (q Query) GetOrderBy() []OrderColumn
- func (q Query) GetType() Type
- func (q Query) GetUpsertFields() []string
- func (q Query) HasCount() bool
- func (q Query) HasLimit() bool
- func (q Query) HasOffset() bool
- func (q Query) HasUpsert() bool
- func (q Query) HasUpsertIgnore() bool
- func (q Query) Name(name string) QueryOperations
- func (Query) Query()
- type QueryBuilder
- type QueryOperations
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aggregate ¶ added in v0.0.6
type Aggregate struct {
// contains filtered or unexported fields
}
Aggregate is one aggregate function over one column.
type CreateOperations ¶ added in v0.0.5
type CreateOperations interface {
QueryBuilder
// Upsert updates the existing row when the given fields collide. The fields must be
// a primary key or a unique constraint, no fields means the primary key.
Upsert(fields ...string) CreateOperations
// Ignore keeps the existing row instead of updating it. Needs an Upsert.
Ignore() CreateOperations
// Name overrides the auto-generated query/method name
Name(name string) CreateOperations
// Contracts limits the query to the given layers, sqlc or proto.
Contracts(contracts ...entlite.Layer) CreateOperations
}
CreateOperations exposes the modifiers available on a Create or CreateBulk query.
type ListAllOperations ¶ added in v0.0.5
type ListAllOperations interface {
QueryBuilder
// Count also returns how many rows match, counted before Limit. An empty page reports 0.
Count() ListAllOperations
// Distinct returns the deduplicated values of the given columns instead of whole
// rows. Every column is part of the key, so sorting is limited to them.
Distinct(fields ...string) ListAllOperations
// GroupBy returns one row per distinct combination of the given columns, an
// aggregate folds each group. Sort by a grouped column or by an aggregate
// column, which is named like sum_duration_ms.
GroupBy(fields ...string) ListAllOperations
// Sum adds up the given column, per group or over the whole table without a GroupBy.
Sum(field string) ListAllOperations
// Avg averages the given column, per group or over the whole table without a GroupBy.
Avg(field string) ListAllOperations
// Min takes the smallest value of the given column, per group or over the whole table.
Min(field string) ListAllOperations
// Max takes the largest value of the given column, per group or over the whole table.
Max(field string) ListAllOperations
// Asc appends a sort column, ascending.
Asc(field string) ListAllOperations
// Desc appends a sort column, descending.
Desc(field string) ListAllOperations
// Limit takes the row count from the caller, Limit(rows) sets it in the query.
Limit(rows ...int) ListAllOperations
// Offset asks the caller how many rows to skip. Needs a Limit.
Offset() ListAllOperations
// Name overrides the auto-generated query/method name
Name(name string) ListAllOperations
// Contracts limits the query to the given layers, sqlc or proto.
Contracts(contracts ...entlite.Layer) ListAllOperations
}
ListAllOperations exposes the modifiers available on a ListAll query.
type ListByOperations ¶
type ListByOperations interface {
QueryBuilder
// Count also returns how many rows match, counted before Limit. An empty page reports 0.
Count() ListByOperations
// Distinct returns the deduplicated values of the given columns instead of whole
// rows. Every column is part of the key, so sorting is limited to them.
Distinct(fields ...string) ListByOperations
// GroupBy returns one row per distinct combination of the given columns, an
// aggregate folds each group. Sort by a grouped column or by an aggregate
// column, which is named like sum_duration_ms.
GroupBy(fields ...string) ListByOperations
// Sum adds up the given column, per group or over the whole table without a GroupBy.
Sum(field string) ListByOperations
// Avg averages the given column, per group or over the whole table without a GroupBy.
Avg(field string) ListByOperations
// Min takes the smallest value of the given column, per group or over the whole table.
Min(field string) ListByOperations
// Max takes the largest value of the given column, per group or over the whole table.
Max(field string) ListByOperations
// Asc appends a sort column, ascending.
Asc(field string) ListByOperations
// Desc appends a sort column, descending.
Desc(field string) ListByOperations
// Limit takes the row count from the caller, Limit(rows) sets it in the query.
Limit(rows ...int) ListByOperations
// Offset asks the caller how many rows to skip. Needs a Limit.
Offset() ListByOperations
// Name overrides the auto-generated query/method name
Name(name string) ListByOperations
// Contracts limits the query to the given layers, sqlc or proto.
Contracts(contracts ...entlite.Layer) ListByOperations
}
ListByOperations exposes the modifiers available on a ListBy query.
func ListBy ¶
func ListBy(args ...interface{}) ListByOperations
ListBy lists records with filters. Takes field names, which default to Eq, or Filter values, e.g. ListBy("org_id") or ListBy(filter.Range("age"), filter.Search("name"))
type OrderColumn ¶ added in v0.0.5
type OrderColumn struct {
// contains filtered or unexported fields
}
OrderColumn is a single sort column together with its direction.
func (OrderColumn) GetName ¶ added in v0.0.5
func (c OrderColumn) GetName() string
GetName returns the column name.
func (OrderColumn) IsDesc ¶ added in v0.0.5
func (c OrderColumn) IsDesc() bool
IsDesc reports if the column is sorted descending.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query holds the state of one query.
func (Query) Contracts ¶ added in v0.0.3
func (q Query) Contracts(contracts ...entlite.Layer) QueryOperations
Contracts limits the query to the given layers, sqlc or proto.
func (Query) GetAggregates ¶ added in v0.0.6
GetAggregates returns the aggregates in chain order, or nil when there is none.
func (Query) GetContracts ¶ added in v0.0.3
GetContracts returns the layers the query belongs to.
func (Query) GetDistinct ¶ added in v0.0.6
GetDistinct returns the deduplicated columns, or nil when the query returns rows.
func (Query) GetFilters ¶
GetFilters returns the filters of a ListBy query.
func (Query) GetGroupBy ¶ added in v0.0.6
GetGroupBy returns the grouped columns, or nil when the query returns rows.
func (Query) GetLimit ¶ added in v0.0.5
GetLimit returns the fixed limit, or 0 when the caller sets it.
func (Query) GetOrderBy ¶
func (q Query) GetOrderBy() []OrderColumn
GetOrderBy returns the sort columns in order, or nil when there is none.
func (Query) GetUpsertFields ¶ added in v0.0.5
GetUpsertFields returns the conflict target, or nil for the primary key.
func (Query) HasUpsert ¶ added in v0.0.5
HasUpsert reports if a create query updates the row it collides with.
func (Query) HasUpsertIgnore ¶ added in v0.0.5
HasUpsertIgnore reports if an upsert keeps the existing row instead of updating it.
func (Query) Name ¶
func (q Query) Name(name string) QueryOperations
Name overrides the auto-generated query/method name
type QueryBuilder ¶
type QueryBuilder interface {
Query()
}
QueryBuilder is implemented by every query.
func DefaultCRUD ¶
func DefaultCRUD() QueryBuilder
DefaultCRUD expands to several queries, so it cannot be named
type QueryOperations ¶
type QueryOperations interface {
QueryBuilder
// Name overrides the auto-generated query/method name
Name(name string) QueryOperations
// Contracts limits the query to the given layers, sqlc or proto.
Contracts(contracts ...entlite.Layer) QueryOperations
}
QueryOperations exposes the modifiers available on a plain query.
func GetBy ¶
func GetBy(fields ...string) QueryOperations
GetBy gets a record by one or more fields, e.g. GetBy("id") or GetBy("org_id", "email")
type Type ¶
type Type string
Type tells which kind of query is described.
const ( // TypeDefaultCRUD expands to the common create, read, update and delete queries. TypeDefaultCRUD Type = "default_crud" // TypeCreate inserts one row. TypeCreate Type = "create" // TypeCreateBulk inserts many rows in one call. TypeCreateBulk Type = "create_bulk" // TypeGet reads one row by primary key. TypeGet Type = "get" // TypeUpdate updates one row by primary key. TypeUpdate Type = "update" // TypeDelete deletes one row by primary key. TypeDelete Type = "delete" // TypeDeleteAll deletes every row of the table. TypeDeleteAll Type = "delete_all" // TypeListAll reads every row of the table. TypeListAll Type = "list_all" // TypeGetBy reads one row by the given fields. TypeGetBy Type = "get_by" // TypeListBy reads many rows by the given filters. TypeListBy Type = "list_by" )