jet/order_by_clause.go

35 lines
711 B
Go
Raw Normal View History

2019-06-21 13:56:57 +02:00
package jet
2019-06-05 17:15:20 +02:00
import "errors"
2019-06-04 12:10:23 +02:00
type OrderByClause interface {
2019-07-08 10:48:03 +02:00
serializeForOrderBy(statement statementType, out *sqlBuilder) error
}
2019-05-07 19:06:21 +02:00
type orderByClauseImpl struct {
2019-06-04 12:10:23 +02:00
expression Expression
ascent bool
}
2019-07-08 10:48:03 +02:00
func (o *orderByClauseImpl) serializeForOrderBy(statement statementType, out *sqlBuilder) error {
if o.expression == nil {
2019-06-05 17:15:20 +02:00
return errors.New("nil orderBy by clause.")
}
2019-06-11 12:47:35 +02:00
if err := o.expression.serializeForOrderBy(statement, out); err != nil {
return err
}
if o.ascent {
2019-06-17 12:05:52 +02:00
out.writeString("ASC")
} else {
2019-06-17 12:05:52 +02:00
out.writeString("DESC")
}
return nil
}
2019-06-21 13:56:57 +02:00
func newOrderByClause(expression Expression, ascent bool) OrderByClause {
return &orderByClauseImpl{expression: expression, ascent: ascent}
}