Documentation
¶
Overview ¶
Package queryparts provides struct defitintions that abstract the necessary parts of a SQL query such as joins, column aliases, order by clauses, etc.
Index ¶
- Constants
- type FieldDescriptor
- type Join
- type OrderByRequest
- type Table
- func (t *Table) AddColumns(cols []string)
- func (t *Table) AddMultitenancyWhere(column string, val interface{})
- func (t *Table) AddWhere(column string, val interface{})
- func (t *Table) AddWhereGroup(group sql.Sqlizer)
- func (t *Table) AppendJoin(tbl, joinField, parentField, jType string, counter *int) *Table
- func (t *Table) AppendJoinTable(tbl *Table, joinField, parentField, jType string) *Table
- func (t *Table) BuildSQL() sql.SelectBuilder
- func (t *Table) Columns() []string
- func (t *Table) DeleteSQL() sql.DeleteBuilder
- func (t *Table) FieldAliases() map[string]FieldDescriptor
- func (t *Table) ToSQL() (string, []interface{}, error)
Constants ¶
const (
AliasedField string = "%[1]v.%[2]v"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FieldDescriptor ¶
FieldDescriptor holds the table/field info for an aliased field
type Join ¶
Join holds a very simple join definition, including a pointer to the parent table and the joined table and type of join
type OrderByRequest ¶
OrderByRequest holds information about a request to order by a field
Picard will read the column name from the struct field's tag and add that to the ORDER BY clause in the SQL query.
Example:
results, err := p.FilterModel(picard.FilterRequest{ FilterModel: tableA{}, OrderBy: []qp.OrderByRequest{ { Field: "FieldA", Descending: true, }, }, })
// SELECT ... ORDER BY t0.field_a DESC
type Table ¶
type Table struct { Alias string RefPath string Name string Joins []Join Wheres sql.And MultiTenancy sql.Eq // contains filtered or unexported fields }
Table represents a select, and is the root of the structure. Start here to build a query by calling
tbl := New("my_table")
func NewAliased ¶
NewAliased returns a new table with the given alias
func (*Table) AddColumns ¶
AddColumns adds an array of columns to the current table, adding the aliases
func (*Table) AddMultitenancyWhere ¶
AddMultitenancyWhere creates a multitenancy WHERE condition
func (*Table) AddWhereGroup ¶
AddWhereGroup adds a grouping of ORS or ANDs to the where clause
func (*Table) AppendJoin ¶
AppendJoin adds a join with the proper aliasing, including any columns requested from that table
func (*Table) AppendJoinTable ¶
AppendJoinTable adds a join with the proper aliasing, including any columns requested from that table
func (*Table) BuildSQL ¶
func (t *Table) BuildSQL() sql.SelectBuilder
BuildSQL returns a squirrel SelectBuilder, which can be used to execute the query or to just add more to the query
func (*Table) DeleteSQL ¶
func (t *Table) DeleteSQL() sql.DeleteBuilder
DeleteSQL returns a squirrel SelectBuilder, which can be used to execute the query or to just add more to the query
func (*Table) FieldAliases ¶
func (t *Table) FieldAliases() map[string]FieldDescriptor
FieldAliases returns a map of all columns on a table and that table's joins.