diff --git a/do_test.go b/do_test.go index 75f1e8a0..d1bd6812 100644 --- a/do_test.go +++ b/do_test.go @@ -162,6 +162,18 @@ func TestDO_methods(t *testing.T) { Expr: u.Order(u.ID.Desc()).Order(u.Age), Result: "ORDER BY `id` DESC,`age`", }, + { + Expr: u.Order(u.ID.Asc()), + Result: "ORDER BY `id` ASC", + }, + { + Expr: u.Order(u.ID.Asc(), u.Age), + Result: "ORDER BY `id` ASC,`age`", + }, + { + Expr: u.Order(u.ID.Asc()).Order(u.Age), + Result: "ORDER BY `id` ASC,`age`", + }, { Expr: u.Clauses(hints.New("hint")).Select(), Result: "SELECT /*+ hint */ *", diff --git a/field/expr.go b/field/expr.go index a0722bdb..a8ff1ce2 100644 --- a/field/expr.go +++ b/field/expr.go @@ -48,6 +48,7 @@ type Expr interface { type OrderExpr interface { Expr Desc() Expr + ASC() Expr } type expression interface{} @@ -274,10 +275,16 @@ func (e expr) As(alias string) Expr { return e } +// Desc sort by desc func (e expr) Desc() Expr { return e.setE(clause.Expr{SQL: "? DESC", Vars: []interface{}{e.RawExpr()}}) } +// Asc sort by asc +func (e expr) Asc() Expr { + return e.setE(clause.Expr{SQL: "? ASC", Vars: []interface{}{e.RawExpr()}}) +} + // ======================== general experssion ======================== func (e expr) value(value interface{}) AssignExpr { return e.setE(clause.Eq{Column: e.col.Name, Value: value})