Refactoring to support parameterized queries.
This commit is contained in:
parent
bc6a2bbcac
commit
fef8f0ef83
33 changed files with 1112 additions and 1206 deletions
46
sqlbuilder/order_by_clause.go
Normal file
46
sqlbuilder/order_by_clause.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package sqlbuilder
|
||||
|
||||
import "github.com/dropbox/godropbox/errors"
|
||||
|
||||
type OrderByClause interface {
|
||||
Clause
|
||||
isOrderByClauseType()
|
||||
}
|
||||
|
||||
type isOrderByClause struct {
|
||||
}
|
||||
|
||||
func (o *isOrderByClause) isOrderByClauseType() {
|
||||
}
|
||||
|
||||
type orderByClause struct {
|
||||
isOrderByClause
|
||||
expression Expression
|
||||
ascent bool
|
||||
}
|
||||
|
||||
func (o *orderByClause) Serialize(out *queryData, options ...serializeOption) error {
|
||||
if o.expression == nil {
|
||||
return errors.Newf("nil orderBy by clause.")
|
||||
}
|
||||
|
||||
if err := o.expression.Serialize(out); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if o.ascent {
|
||||
out.WriteString(" ASC")
|
||||
} else {
|
||||
out.WriteString(" DESC")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Asc(expression Expression) OrderByClause {
|
||||
return &orderByClause{expression: expression, ascent: true}
|
||||
}
|
||||
|
||||
func Desc(expression Expression) OrderByClause {
|
||||
return &orderByClause{expression: expression, ascent: false}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue