AddOrderBy returns a Rule that appends an ORDER BY expression to a SELECT statement. Multiple calls append additional sort keys in the order they are applied. Parameters: - column: Name of the column (or expression alias) to sort by - desc: When true the sort direction is DESC; when false it is ASC
(column string, desc bool)
| 27 | // |
| 28 | // Returns ErrUnsupportedStatement for non-SELECT statements. |
| 29 | func AddOrderBy(column string, desc bool) Rule { |
| 30 | return RuleFunc(func(stmt ast.Statement) error { |
| 31 | sel, err := getSelect(stmt, "AddOrderBy") |
| 32 | if err != nil { |
| 33 | return err |
| 34 | } |
| 35 | sel.OrderBy = append(sel.OrderBy, ast.OrderByExpression{ |
| 36 | Expression: &ast.Identifier{Name: column}, |
| 37 | Ascending: !desc, |
| 38 | }) |
| 39 | return nil |
| 40 | }) |
| 41 | } |
| 42 | |
| 43 | // RemoveOrderBy returns a Rule that removes the ORDER BY clause entirely from a |
| 44 | // SELECT statement, leaving the result set in an unspecified (engine-dependent) |