Documentation ¶
Index ¶
- Constants
- func Bitwise(left TableField, operator BitwiseOperator, right interface{}) *binaryExpression
- func NewMissingTablesError(tables []string) errors.TracerError
- func NewValidationFromNotSetError() errors.TracerError
- type BitwiseOperator
- type Comparison
- type ConditionExpression
- func (exp *ConditionExpression) And(expression *ConditionExpression) *ConditionExpression
- func (exp *ConditionExpression) Or(expression *ConditionExpression) *ConditionExpression
- func (exp *ConditionExpression) SQL() (string, []interface{})
- func (exp *ConditionExpression) Tables() []string
- func (exp *ConditionExpression) XOr(expression *ConditionExpression) *ConditionExpression
- type CountExpression
- type DeleteQuery
- func (q *DeleteQuery) From(table Table) *DeleteQuery
- func (q *DeleteQuery) GetAlias(tableName string) string
- func (q *DeleteQuery) InnerJoin(table Table) *Join
- func (q *DeleteQuery) OuterJoin(direction JoinDirection, table Table) *Join
- func (q *DeleteQuery) SQL() (string, []interface{}, error)
- func (q *DeleteQuery) Validate() bool
- func (q *DeleteQuery) Where(condition *ConditionExpression) *DeleteQuery
- type FieldValue
- type InsertQuery
- func (q *InsertQuery) GetAlias(tableName string) string
- func (q *InsertQuery) OnDuplicate(fields []TableField, values ...interface{}) *InsertQuery
- func (q *InsertQuery) ParameterizedSQL() (string, error)
- func (q *InsertQuery) SQL() (string, []interface{}, error)
- func (q *InsertQuery) Values(values ...interface{}) *InsertQuery
- type Join
- type JoinDirection
- type JoinError
- type JoinType
- type MissingTablesError
- type OrderDirection
- type RowCount
- type SelectExpression
- func Alias(tableField TableField, aliasName string) SelectExpression
- func Coalesce(column TableField, defaultValue string, alias string) SelectExpression
- func Count(tableField TableField, aliasName string) SelectExpression
- func NewCountExpression(table string) SelectExpression
- func NotNull(tableField TableField, alias string) SelectExpression
- type SelectQuery
- func (q *SelectQuery) From(table Table) *SelectQuery
- func (q *SelectQuery) GetAlias(tableName string) string
- func (q *SelectQuery) GroupBy(expressions ...SelectExpression) *SelectQuery
- func (q *SelectQuery) InnerJoin(table Table) *Join
- func (q *SelectQuery) OrderBy(field TableField, direction OrderDirection) *SelectQuery
- func (q *SelectQuery) OuterJoin(direction JoinDirection, table Table) *Join
- func (q *SelectQuery) SQL(limit, offset uint) (string, []interface{}, error)
- func (q *SelectQuery) SelectFrom(selectExpressions ...SelectExpression) *SelectQuery
- func (q *SelectQuery) Validate() bool
- func (q *SelectQuery) Where(condition *ConditionExpression) *SelectQuery
- type Table
- type TableField
- func (tf TableField) Equal(obj interface{}) *ConditionExpression
- func (tf TableField) GetName() string
- func (tf TableField) GetTables() []string
- func (tf TableField) GreaterThan(obj interface{}) *ConditionExpression
- func (tf TableField) GreaterThanEqual(obj interface{}) *ConditionExpression
- func (tf TableField) In(objs ...interface{}) *ConditionExpression
- func (tf TableField) IsNotNull() *ConditionExpression
- func (tf TableField) IsNull() *ConditionExpression
- func (tf TableField) LessThan(obj interface{}) *ConditionExpression
- func (tf TableField) LessThanEqual(obj interface{}) *ConditionExpression
- func (tf TableField) Like(obj interface{}) *ConditionExpression
- func (tf TableField) NotEqual(obj interface{}) *ConditionExpression
- func (tf TableField) NullSafeEqual(obj interface{}) *ConditionExpression
- func (tf TableField) SQL() string
- type UpdateQuery
- func (q *UpdateQuery) GetAlias(tableName string) string
- func (q *UpdateQuery) OrderBy(field TableField, direction OrderDirection) *UpdateQuery
- func (q *UpdateQuery) ParameterizedSQL(limit int) (string, error)
- func (q *UpdateQuery) SQL(limit int) (string, []interface{}, error)
- func (q *UpdateQuery) Set(field TableField, value interface{}) *UpdateQuery
- func (q *UpdateQuery) SetParam(field TableField) *UpdateQuery
- func (q *UpdateQuery) Where(condition *ConditionExpression) *UpdateQuery
- type ValidationFromNotSetError
Constants ¶
const ( // SQLNow is the SQL NOW() function for use as a value in expressions. SQLNow = "NOW()" // SQLNull is the SQL representation of NULL SQLNull = "NULL" )
const ( // Equal Comparison Operator Equal Comparison = "=" // NotEqual Comparison Operator NotEqual Comparison = "!=" // LessThan Comparison Operator LessThan Comparison = "<" // LessThanEqual Comparison Operator LessThanEqual Comparison = "<=" // GreaterThan Comparison Operator GreaterThan Comparison = ">" // GreaterThanEqual Comparison Operator GreaterThanEqual Comparison = ">=" // NullSafeEqual Comparison Operator NullSafeEqual Comparison = "<=>" // Is Comparison Operator Is Comparison = "IS" // IsNot Comparison Operator IsNot Comparison = "IS NOT" // In Comparison Operator In Comparison = "IN" // LIKE Comparison Operator Like Comparison = "LIKE" // Inner JoinType Inner JoinType = "INNER" // Outer JoinType Outer JoinType = "OUTER" // Cross JoinType Cross JoinType = "CROSS" // Left JoinDirection Left JoinDirection = "LEFT" // Right JoinDirection Right JoinDirection = "RIGHT" // Ascending OrderDirection Ascending OrderDirection = "ASC" // Descending OrderDirection Descending OrderDirection = "DESC" // And expression conjunction And = "AND" // Or expression conjunction Or = "OR" // XOr expression conjunction XOr = "XOR" // NoLimit is the value that represents not applying a limit on the query // we are not using ^uint(0) because that is easy to guess and would make // this value not comparable to int NoLimit = 1<<16 - 1337 // 4@><0R5 yea yea )
Variables ¶
This section is empty.
Functions ¶
func Bitwise ¶ added in v2.9.0
func Bitwise(left TableField, operator BitwiseOperator, right interface{}) *binaryExpression
func NewMissingTablesError ¶
func NewMissingTablesError(tables []string) errors.TracerError
NewMissingTablesError is returned when column's are being used from a table that is not part of the query.
func NewValidationFromNotSetError ¶
func NewValidationFromNotSetError() errors.TracerError
NewValidationFromNotSetError instantiates a ValidationFromNotSetError with a stack trace
Types ¶
type BitwiseOperator ¶ added in v2.9.0
type BitwiseOperator string
const ( // Binary and expression conjunction BitwiseAnd BitwiseOperator = "&" // Bitwise or expression conjunction BitwiseOr BitwiseOperator = "|" // Bitwise xor expression conjunction BitwiseXor BitwiseOperator = "^" // Bitwise negation expression conjunction BitwiseNegation BitwiseOperator = "~" // Bitwise and negation expression conjunction BitwiseAndNegation BitwiseOperator = "&~" // Bitwise or negation expression conjunction BitwiseOrNegation BitwiseOperator = "|~" // Bitwise xor negation expression conjunction BitwiseXorNegation BitwiseOperator = "^~" )
type ConditionExpression ¶
type ConditionExpression struct {
// contains filtered or unexported fields
}
ConditionExpression represents an expression that can be used as a condition in a where or join on.
func FieldComparison ¶
func FieldComparison(left TableField, comparison Comparison, right interface{}) *ConditionExpression
FieldComparison to another field or a discrete value.
func FieldIn ¶
func FieldIn(left TableField, in ...interface{}) *ConditionExpression
FieldIn a series of TableFields and/or values
func (*ConditionExpression) And ¶
func (exp *ConditionExpression) And(expression *ConditionExpression) *ConditionExpression
And creates an expression with this and the passed expression with an AND conjunction.
func (*ConditionExpression) Or ¶
func (exp *ConditionExpression) Or(expression *ConditionExpression) *ConditionExpression
Or creates an expression with this and the passed expression with an OR conjunction.
func (*ConditionExpression) SQL ¶
func (exp *ConditionExpression) SQL() (string, []interface{})
SQL returns this condition expression as a SQL expression.
func (*ConditionExpression) Tables ¶
func (exp *ConditionExpression) Tables() []string
Tables that are used in this expression or it's sub expressions.
func (*ConditionExpression) XOr ¶
func (exp *ConditionExpression) XOr(expression *ConditionExpression) *ConditionExpression
XOr creates an expression with this and the passed expression with an XOr conjunction.
type CountExpression ¶ added in v2.10.0
type CountExpression struct {
// contains filtered or unexported fields
}
CountExpression can be used as the expression in count query's. Requires a table name that exists in the query to bind to for validation.
func (*CountExpression) GetName ¶ added in v2.10.0
func (ce *CountExpression) GetName() string
GetName of this count expression
func (*CountExpression) GetTables ¶ added in v2.10.0
func (ce *CountExpression) GetTables() []string
GetTables used by this count expression
func (*CountExpression) SQL ¶ added in v2.10.0
func (ce *CountExpression) SQL() string
SQL fragment this count expressions represents
type DeleteQuery ¶
type DeleteQuery struct {
// contains filtered or unexported fields
}
DeleteQuery for removing rows from a database
func Delete ¶
func Delete(rowsIn ...Table) *DeleteQuery
Delete from from the specified tables that match the criteria specified in where.
func (*DeleteQuery) From ¶
func (q *DeleteQuery) From(table Table) *DeleteQuery
From sets the primary table the query will find rows in.
func (*DeleteQuery) GetAlias ¶
func (q *DeleteQuery) GetAlias(tableName string) string
GetAlias of the passed table name in this query
func (*DeleteQuery) InnerJoin ¶
func (q *DeleteQuery) InnerJoin(table Table) *Join
InnerJoin with another table in the database.
func (*DeleteQuery) OuterJoin ¶
func (q *DeleteQuery) OuterJoin(direction JoinDirection, table Table) *Join
OuterJoin with another table in the database.
func (*DeleteQuery) SQL ¶
func (q *DeleteQuery) SQL() (string, []interface{}, error)
SQL representation of this delete query.
func (*DeleteQuery) Validate ¶
func (q *DeleteQuery) Validate() bool
Validate that this query is executable
func (*DeleteQuery) Where ¶
func (q *DeleteQuery) Where(condition *ConditionExpression) *DeleteQuery
Where determines what rows to delete from.
type FieldValue ¶ added in v2.8.0
type FieldValue struct { Field TableField Value interface{} }
FieldValue represents a single field value on a table.
type InsertQuery ¶
type InsertQuery struct {
// contains filtered or unexported fields
}
InsertQuery for inserting a row into the database.
func (*InsertQuery) GetAlias ¶
func (q *InsertQuery) GetAlias(tableName string) string
GetAlias of the passed table name in this query.
func (*InsertQuery) OnDuplicate ¶
func (q *InsertQuery) OnDuplicate(fields []TableField, values ...interface{}) *InsertQuery
OnDuplicate update these fields / values
func (*InsertQuery) ParameterizedSQL ¶
func (q *InsertQuery) ParameterizedSQL() (string, error)
ParameterizedSQL that represents this insert query.
func (*InsertQuery) SQL ¶
func (q *InsertQuery) SQL() (string, []interface{}, error)
SQL that represents this insert query.
func (*InsertQuery) Values ¶
func (q *InsertQuery) Values(values ...interface{}) *InsertQuery
Values to be inserted. Call multiple times to insert multiple rows.
type Join ¶
type Join struct {
// contains filtered or unexported fields
}
Join on the tables inside the query.
func NewJoin ¶
func NewJoin(joinType JoinType, joinDirection JoinDirection, table Table) *Join
NewJoin of the specified type and direction.
func (*Join) On ¶
func (join *Join) On(left TableField, comparison Comparison, right interface{}) *ConditionExpression
On specifies the the conditions of a join based upon two fields or a field and a discrete value
type JoinError ¶
type JoinError struct {
// contains filtered or unexported fields
}
JoinError signifying a problem with the created join.
type MissingTablesError ¶
type MissingTablesError struct { Tables []string // contains filtered or unexported fields }
MissingTablesError is returned when column's are being used from a table that is not part of the query.
func (*MissingTablesError) Error ¶
func (err *MissingTablesError) Error() string
func (*MissingTablesError) Trace ¶
func (err *MissingTablesError) Trace() []string
Trace returns the stack trace for the error
type OrderDirection ¶
type OrderDirection string
OrderDirection for use in an order by Ascending or Descending
type RowCount ¶ added in v2.10.0
type RowCount struct {
Count int `db:"count"`
}
RowCount serves as a target for queries returning only a count of rows
type SelectExpression ¶
type SelectExpression interface { // GetName that can be used to reference this expression GetName() string // GetTables that are used in this expression GetTables() []string // SQL that represents this SelectExpression SQL() string }
SelectExpression for use in identifying the fields desired in a select query.
func Alias ¶
func Alias(tableField TableField, aliasName string) SelectExpression
Alias the passed table field for use in or as a SelectExpression
func Coalesce ¶
func Coalesce(column TableField, defaultValue string, alias string) SelectExpression
Coalesce creates a SQL coalesce that can be used as a SelectExpression
func Count ¶ added in v2.10.1
func Count(tableField TableField, aliasName string) SelectExpression
Count the passed table field for use in or as a SelectExpression
func NewCountExpression ¶ added in v2.10.0
func NewCountExpression(table string) SelectExpression
NewCountExpression for the passed table. Table must be a part of the query.
func NotNull ¶
func NotNull(tableField TableField, alias string) SelectExpression
NotNull field for use as a select expression
type SelectQuery ¶
type SelectQuery struct { Seperator string // contains filtered or unexported fields }
SelectQuery for retrieving data from a database table.
func Select ¶
func Select(selectExpressions ...SelectExpression) *SelectQuery
Select creates a new select query based on the passed expressions for the select clause.
func SelectDistinct ¶
func SelectDistinct(selectExpressions ...SelectExpression) *SelectQuery
SelectDistinct creates a new select query based on the passed expressions for the select clause with a distinct modifier.
func (*SelectQuery) From ¶
func (q *SelectQuery) From(table Table) *SelectQuery
From sets the primary table the query will get values from.
func (*SelectQuery) GetAlias ¶
func (q *SelectQuery) GetAlias(tableName string) string
GetAlias of the passed table name in this query.
func (*SelectQuery) GroupBy ¶
func (q *SelectQuery) GroupBy(expressions ...SelectExpression) *SelectQuery
GroupBy the passed table field.
func (*SelectQuery) InnerJoin ¶
func (q *SelectQuery) InnerJoin(table Table) *Join
InnerJoin with another table in the database.
func (*SelectQuery) OrderBy ¶
func (q *SelectQuery) OrderBy(field TableField, direction OrderDirection) *SelectQuery
OrderBy the passed field and direction.
func (*SelectQuery) OuterJoin ¶
func (q *SelectQuery) OuterJoin(direction JoinDirection, table Table) *Join
OuterJoin with another table in the database.
func (*SelectQuery) SQL ¶
func (q *SelectQuery) SQL(limit, offset uint) (string, []interface{}, error)
SQL statement corresponding to this query.
func (*SelectQuery) SelectFrom ¶
func (q *SelectQuery) SelectFrom(selectExpressions ...SelectExpression) *SelectQuery
SelectFrom this query but with different select expressions, not a deep copy
func (*SelectQuery) Validate ¶
func (q *SelectQuery) Validate() bool
Validate that this query can be executed.
func (*SelectQuery) Where ¶
func (q *SelectQuery) Where(condition *ConditionExpression) *SelectQuery
Where the comparison between the two tablefields evaluates to true.
type Table ¶
type Table interface { // GetName returns the name of the database table GetName() string // GetAlias returns the alias of the database table to be used in the query GetAlias() string // PrimaryKey returns the primary key TableField PrimaryKey() TableField // AllColumns returns the AllColumns TableField for this Table AllColumns() TableField // ReadColumns returns the default set of columns for a read operation ReadColumns() []TableField // WriteColumns returns the default set of columns for a write operation WriteColumns() []TableField // SortBy returns the name of the default sort by field SortBy() (TableField, OrderDirection) }
Table represents a db table
type TableField ¶
type TableField struct { // Name of the column in the database table Name string // Table that the column is on Table string }
TableField represents a single column on a table.
func (TableField) Equal ¶
func (tf TableField) Equal(obj interface{}) *ConditionExpression
Equal returns a condition expression for this table field Equal to the passed obj.
func (TableField) GetName ¶
func (tf TableField) GetName() string
GetName that can be used to reference this expression
func (TableField) GetTables ¶
func (tf TableField) GetTables() []string
GetTables that are used in this expression
func (TableField) GreaterThan ¶
func (tf TableField) GreaterThan(obj interface{}) *ConditionExpression
GreaterThan returns a condition expression for this table field GreaterThan to the passed obj.
func (TableField) GreaterThanEqual ¶
func (tf TableField) GreaterThanEqual(obj interface{}) *ConditionExpression
GreaterThanEqual returns a condition expression for this table field GreaterThanEqual to the passed obj.
func (TableField) In ¶
func (tf TableField) In(objs ...interface{}) *ConditionExpression
In returns a condition expression for this table field in to the passed objs.
func (TableField) IsNotNull ¶
func (tf TableField) IsNotNull() *ConditionExpression
IsNotNull returns a condition expression for this table field where it is not NULL
func (TableField) IsNull ¶
func (tf TableField) IsNull() *ConditionExpression
IsNull returns a condition expression for this table field when it is NULL
func (TableField) LessThan ¶
func (tf TableField) LessThan(obj interface{}) *ConditionExpression
LessThan returns a condition expression for this table field LessThan to the passed obj.
func (TableField) LessThanEqual ¶
func (tf TableField) LessThanEqual(obj interface{}) *ConditionExpression
LessThanEqual returns a condition expression for this table field LessThanEqual to the passed obj.
func (TableField) Like ¶
func (tf TableField) Like(obj interface{}) *ConditionExpression
Like returns a condition expression for this table field Like to the passed obj.
func (TableField) NotEqual ¶
func (tf TableField) NotEqual(obj interface{}) *ConditionExpression
NotEqual returns a condition expression for this table field NotEqual to the passed obj.
func (TableField) NullSafeEqual ¶
func (tf TableField) NullSafeEqual(obj interface{}) *ConditionExpression
NullSafeEqual returns a condition expression for this table field NullSafeEqual to the passed obj.
type UpdateQuery ¶
type UpdateQuery struct {
// contains filtered or unexported fields
}
UpdateQuery represents a query to update rows in a database Currently only supports single table, to change this the tableReference would have to be built out more.
func Update ¶
func Update(table Table) *UpdateQuery
Update returns a query that can be used for updating rows in the passed table.
func (*UpdateQuery) GetAlias ¶
func (q *UpdateQuery) GetAlias(tableName string) string
GetAlias returns the alias for the passed tablename used in this query.
func (*UpdateQuery) OrderBy ¶
func (q *UpdateQuery) OrderBy(field TableField, direction OrderDirection) *UpdateQuery
OrderBy the passed field and direction.
func (*UpdateQuery) ParameterizedSQL ¶
func (q *UpdateQuery) ParameterizedSQL(limit int) (string, error)
ParameterizedSQL representation of this query.
func (*UpdateQuery) SQL ¶
func (q *UpdateQuery) SQL(limit int) (string, []interface{}, error)
SQL representation of this query.
func (*UpdateQuery) Set ¶
func (q *UpdateQuery) Set(field TableField, value interface{}) *UpdateQuery
Set adds a assignment to this update query.
func (*UpdateQuery) SetParam ¶
func (q *UpdateQuery) SetParam(field TableField) *UpdateQuery
SetParam adds a parameterized assignment to this update query.
func (*UpdateQuery) Where ¶
func (q *UpdateQuery) Where(condition *ConditionExpression) *UpdateQuery
Where determines the conditions by which the assignments in this query apply
type ValidationFromNotSetError ¶
type ValidationFromNotSetError struct {
// contains filtered or unexported fields
}
ValidationFromNotSetError is set on the query when From has not been called on this query.
func (*ValidationFromNotSetError) Error ¶
func (err *ValidationFromNotSetError) Error() string
func (*ValidationFromNotSetError) Trace ¶
func (err *ValidationFromNotSetError) Trace() []string
Trace returns the stack trace for the error