Documentation ¶
Index ¶
- Constants
- func Build(adverb string, wh Expression, q ...dialect.Quoter) (string, []interface{})
- func BuildQueryConstraint(qc QueryConstraint, quoter ...dialect.Quoter) string
- func Having(wh Expression, q ...dialect.Quoter) (string, []interface{})
- func Limit(n int) *queryConstraint
- func Offset(n int) *queryConstraint
- func OrderBy(column ...string) *queryConstraint
- func Where(wh Expression, q ...dialect.Quoter) (string, []interface{})
- type Clause
- type Condition
- func Between(column string, a, b interface{}) Condition
- func Eq(column string, value interface{}) Condition
- func Gt(column string, value interface{}) Condition
- func GtEq(column string, value interface{}) Condition
- func In(column string, values ...interface{}) Condition
- func Like(column string, pattern string) Condition
- func Lt(column string, value interface{}) Condition
- func LtEq(column string, value interface{}) Condition
- func NotEq(column string, value interface{}) Condition
- func NotNull(column string) Condition
- func Null(column string) Condition
- type Expression
- type QueryConstraint
Constants ¶
const ( WhereAdverb = "WHERE " HavingVerb = "HAVING " )
Variables ¶
This section is empty.
Functions ¶
func Build ¶ added in v0.17.0
func Build(adverb string, wh Expression, q ...dialect.Quoter) (string, []interface{})
Build constructs the sql clause beginning with some verb/adverb. It will contain '?' style placeholders; these need to be passed through the relevant dialect ReplacePlaceholders processing.
func BuildQueryConstraint ¶
func BuildQueryConstraint(qc QueryConstraint, quoter ...dialect.Quoter) string
func Having ¶ added in v0.17.0
func Having(wh Expression, q ...dialect.Quoter) (string, []interface{})
Having constructs the sql clause beginning "HAVING ...". It will contain '?' style placeholders; these need to be passed through the relevant dialect ReplacePlaceholders processing. A quoter may optionally be supplied, otherwise the Default Quoter is used.
func Limit ¶
func Limit(n int) *queryConstraint
Limit sets the upper limit on the number of records to be returned.
func Offset ¶
func Offset(n int) *queryConstraint
Offset sets the offset into the result set; previous items will be discarded.
func OrderBy ¶
func OrderBy(column ...string) *queryConstraint
OrderBy lists the column(s) by which the database will be asked to sort its results. The columns passed in here will be quoted according to the needs of the current dialect.
func Where ¶ added in v0.17.0
func Where(wh Expression, q ...dialect.Quoter) (string, []interface{})
Where constructs the sql clause beginning "WHERE ...". It will contain '?' style placeholders; these need to be passed through the relevant dialect ReplacePlaceholders processing. A quoter may optionally be supplied, otherwise the Default Quoter is used.
Types ¶
type Clause ¶
type Clause struct {
// contains filtered or unexported fields
}
Clause is a compound expression.
func And ¶
func And(exp ...Expression) Clause
And combines some expressions into a clause that requires they are all true.
func Or ¶
func Or(exp ...Expression) Clause
Or combines some expressions into a clause that requires that any is true.
func (Clause) And ¶
func (wh Clause) And(exp Expression) Clause
And combines two clauses into a clause that requires they are both true. SQL implementation note: AND has higher precedence than OR.
func (Clause) Or ¶
func (wh Clause) Or(exp Expression) Clause
Or combines two clauses into a clause that requires either is true. SQL implementation note: AND has higher precedence than OR.
type Condition ¶
type Condition struct {
Column, Predicate string
Args []interface{}
}
Condition is a simple condition such as an equality test.
func Like ¶
Like returns a pattern-matching condition on a column. Be careful: this can hurt performance.
func NotNull ¶
NotNull returns an 'IS NOT NULL' condition on a column. It's also possible to use Not(Null(...)).
func (Condition) And ¶
func (cl Condition) And(c2 Expression) Clause
And combines two conditions into a clause that requires they are both true.
func (Condition) Or ¶
func (cl Condition) Or(c2 Expression) Clause
Or combines two conditions into a clause that requires either is true.
type Expression ¶
type Expression interface { fmt.Stringer And(Expression) Clause Or(Expression) Clause Build(q dialect.Quoter) (string, []interface{}) }
Expression is an element in a WHERE clause. Expressions may be nested in various ways.
func NoOp ¶
func NoOp() Expression
NoOp creates an empty expression. This is useful for conditionally chaining expressions based contextual decisions. It can also be passed to any method that need an expression but for which none is required in that case.
type QueryConstraint ¶
QueryConstraint is a value that is appended to a SELECT statement.
func Literal ¶
func Literal(sqlPart string) QueryConstraint
Literal returns the literal string supplied, converting it to a QueryConstraint.