class Sequel::SQL::OrderedExpression
Represents a column/expression to order the result set by.
Constants
- INVERT_NULLS
Attributes
Whether the expression should order the result set in a descending manner
The expression to order the result set by.
Whether to sort NULLS FIRST/LAST
Public Class Methods
Source
# File lib/sequel/sql.rb 1682 def initialize(expression, descending = true, opts=OPTS) 1683 @expression = expression 1684 @descending = descending 1685 @nulls = opts[:nulls] 1686 freeze 1687 end
Set the expression and descending attributes to the given values. Options:
- :nulls
-
Can be :first/:last for NULLS FIRST/LAST.
Public Instance Methods
Source
# File lib/sequel/sql.rb 1690 def asc 1691 OrderedExpression.new(@expression, false, :nulls=>@nulls) 1692 end
Return a copy that is ordered ASC
Source
# File lib/sequel/sql.rb 1695 def desc 1696 OrderedExpression.new(@expression, true, :nulls=>@nulls) 1697 end
Return a copy that is ordered DESC
Source
# File lib/sequel/sql.rb 1700 def invert 1701 OrderedExpression.new(@expression, !@descending, :nulls=>INVERT_NULLS.fetch(@nulls, @nulls)) 1702 end
Return an inverted expression, changing ASC to DESC and NULLS FIRST to NULLS LAST.
Private Instance Methods
Source
# File lib/sequel/extensions/eval_inspect.rb 169 def inspect_args 170 if nulls 171 [:expression, :descending, :opts_hash] 172 else 173 [:expression, :descending] 174 end 175 end
OrderedExpression’s initializer takes the :nulls information inside a hash, so if a NULL order was given, include a hash with that information.
Source
# File lib/sequel/extensions/eval_inspect.rb 178 def opts_hash 179 {:nulls=>nulls} 180 end
A hash of null information suitable for passing to the initializer.