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)
| 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. |
| 708 | func (q *Query) Order(orders ...string) *Query { |
| 709 | loop: |
| 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. |
| 732 | func (q *Query) OrderExpr(order string, params ...interface{}) *Query { |