MCPcopy Create free account
hub / github.com/go-pg/pg / Order

Method Order

orm/query.go:708–729  ·  view source on GitHub ↗

Order adds sort order to the Query quoting column name. Does not expand params like ?TableAlias etc. OrderExpr can be used to bypass quoting restriction or for params expansion.

(orders ...string)

Source from the content-addressed store, hash-verified

706// Order adds sort order to the Query quoting column name. Does not expand params like ?TableAlias etc.
707// OrderExpr can be used to bypass quoting restriction or for params expansion.
708func (q *Query) Order(orders ...string) *Query {
709loop:
710 for _, order := range orders {
711 if order == "" {
712 continue
713 }
714 ind := strings.Index(order, " ")
715 if ind != -1 {
716 field := order[:ind]
717 sort := order[ind+1:]
718 switch internal.UpperString(sort) {
719 case "ASC", "DESC", "ASC NULLS FIRST", "DESC NULLS FIRST",
720 "ASC NULLS LAST", "DESC NULLS LAST":
721 q = q.OrderExpr("? ?", types.Ident(field), types.Safe(sort))
722 continue loop
723 }
724 }
725
726 q.order = append(q.order, fieldAppender{order})
727 }
728 return q
729}
730
731// Order adds sort order to the Query.
732func (q *Query) OrderExpr(order string, params ...interface{}) *Query {

Callers 4

db_test.goFile · 0.80
select_test.goFile · 0.80

Calls 5

OrderExprMethod · 0.95
UpperStringFunction · 0.92
IdentTypeAlias · 0.92
SafeTypeAlias · 0.92
IndexMethod · 0.65

Tested by 2