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 1676 def initialize(expression, descending = true, opts=OPTS) 1677 @expression = expression 1678 @descending = descending 1679 @nulls = opts[:nulls] 1680 freeze 1681 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 1684 def asc 1685 OrderedExpression.new(@expression, false, :nulls=>@nulls) 1686 end
Return a copy that is ordered ASC
Source
# File lib/sequel/sql.rb 1689 def desc 1690 OrderedExpression.new(@expression, true, :nulls=>@nulls) 1691 end
Return a copy that is ordered DESC
Source
# File lib/sequel/sql.rb 1694 def invert 1695 OrderedExpression.new(@expression, !@descending, :nulls=>INVERT_NULLS.fetch(@nulls, @nulls)) 1696 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.