Refactoring to support parameterized queries.

This commit is contained in:
zer0sub 2019-04-29 14:39:48 +02:00
parent bc6a2bbcac
commit fef8f0ef83
33 changed files with 1112 additions and 1206 deletions

View 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}
}