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