class Sequel::SQL::OrderedExpression
Represents a column/expression to order the result set by.
Constants
- INVERT_NULLS
Attributes
descending[R]
Whether the expression should order the result set in a descending manner
expression[R]
The expression to order the result set by.
nulls[R]
Whether to sort NULLS FIRST/LAST
Public Class Methods
new(expression, descending = true, opts=OPTS)
click to toggle source
Set the expression and descending attributes to the given values. Options:
- :nulls
-
Can be :first/:last for NULLS FIRST/LAST.
# File lib/sequel/sql.rb 1673 def initialize(expression, descending = true, opts=OPTS) 1674 @expression = expression 1675 @descending = descending 1676 @nulls = opts[:nulls] 1677 freeze 1678 end
Public Instance Methods
asc()
click to toggle source
Return a copy that is ordered ASC
# File lib/sequel/sql.rb 1681 def asc 1682 OrderedExpression.new(@expression, false, :nulls=>@nulls) 1683 end
desc()
click to toggle source
Return a copy that is ordered DESC
# File lib/sequel/sql.rb 1686 def desc 1687 OrderedExpression.new(@expression, true, :nulls=>@nulls) 1688 end
invert()
click to toggle source
Return an inverted expression, changing ASC to DESC and NULLS FIRST to NULLS LAST.
# File lib/sequel/sql.rb 1691 def invert 1692 OrderedExpression.new(@expression, !@descending, :nulls=>INVERT_NULLS.fetch(@nulls, @nulls)) 1693 end
Private Instance Methods
inspect_args()
click to toggle source
OrderedExpression’s initializer takes the :nulls information inside a hash, so if a NULL order was given, include a hash with that information.
# 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
opts_hash()
click to toggle source
A hash of null information suitable for passing to the initializer.
# File lib/sequel/extensions/eval_inspect.rb 178 def opts_hash 179 {:nulls=>nulls} 180 end