Skip to content

Commit a22f420

Browse files
authored
feat: add order by asc expr (#1034)
* feat: add order by asc expr * feat: add order by asc expr
1 parent f534623 commit a22f420

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

do_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ func TestDO_methods(t *testing.T) {
162162
Expr: u.Order(u.ID.Desc()).Order(u.Age),
163163
Result: "ORDER BY `id` DESC,`age`",
164164
},
165+
{
166+
Expr: u.Order(u.ID.Asc()),
167+
Result: "ORDER BY `id` ASC",
168+
},
169+
{
170+
Expr: u.Order(u.ID.Asc(), u.Age),
171+
Result: "ORDER BY `id` ASC,`age`",
172+
},
173+
{
174+
Expr: u.Order(u.ID.Asc()).Order(u.Age),
175+
Result: "ORDER BY `id` ASC,`age`",
176+
},
165177
{
166178
Expr: u.Clauses(hints.New("hint")).Select(),
167179
Result: "SELECT /*+ hint */ *",

field/expr.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type Expr interface {
4848
type OrderExpr interface {
4949
Expr
5050
Desc() Expr
51+
ASC() Expr
5152
}
5253

5354
type expression interface{}
@@ -274,10 +275,16 @@ func (e expr) As(alias string) Expr {
274275
return e
275276
}
276277

278+
// Desc sort by desc
277279
func (e expr) Desc() Expr {
278280
return e.setE(clause.Expr{SQL: "? DESC", Vars: []interface{}{e.RawExpr()}})
279281
}
280282

283+
// Asc sort by asc
284+
func (e expr) Asc() Expr {
285+
return e.setE(clause.Expr{SQL: "? ASC", Vars: []interface{}{e.RawExpr()}})
286+
}
287+
281288
// ======================== general experssion ========================
282289
func (e expr) value(value interface{}) AssignExpr {
283290
return e.setE(clause.Eq{Column: e.col.Name, Value: value})

0 commit comments

Comments
 (0)