Class: Sequel::SQL::OrderedExpression
- Inherits:
-
Expression
- Object
- Expression
- Sequel::SQL::OrderedExpression
- Defined in:
- lib/sequel/sql.rb
Overview
Represents a column/expression to order the result set by.
Constant Summary collapse
- INVERT_NULLS =
{:first=>:last, :last=>:first}.freeze
Instance Attribute Summary collapse
-
#descending ⇒ Object
readonly
Whether the expression should order the result set in a descending manner.
-
#expression ⇒ Object
readonly
The expression to order the result set by.
-
#nulls ⇒ Object
readonly
Whether to sort NULLS FIRST/LAST.
Instance Method Summary collapse
-
#asc ⇒ Object
Return a copy that is ordered ASC.
-
#desc ⇒ Object
Return a copy that is ordered DESC.
-
#initialize(expression, descending = true, opts = {}) ⇒ OrderedExpression
constructor
Set the expression and descending attributes to the given values.
-
#invert ⇒ Object
Return an inverted expression, changing ASC to DESC and NULLS FIRST to NULLS LAST.
Methods inherited from Expression
#==, attr_reader, comparison_attrs, #eql?, #hash, #inspect, #lit, #sql_literal
Constructor Details
#initialize(expression, descending = true, opts = {}) ⇒ OrderedExpression
Set the expression and descending attributes to the given values. Options:
- :nulls
-
Can be :first/:last for NULLS FIRST/LAST.
910 911 912 |
# File 'lib/sequel/sql.rb', line 910 def initialize(expression, descending = true, opts={}) @expression, @descending, @nulls = expression, descending, opts[:nulls] end |
Instance Attribute Details
#descending ⇒ Object (readonly)
Whether the expression should order the result set in a descending manner
901 902 903 |
# File 'lib/sequel/sql.rb', line 901 def descending @descending end |
#expression ⇒ Object (readonly)
The expression to order the result set by.
898 899 900 |
# File 'lib/sequel/sql.rb', line 898 def expression @expression end |
#nulls ⇒ Object (readonly)
Whether to sort NULLS FIRST/LAST
904 905 906 |
# File 'lib/sequel/sql.rb', line 904 def nulls @nulls end |
Instance Method Details
#asc ⇒ Object
Return a copy that is ordered ASC
915 916 917 |
# File 'lib/sequel/sql.rb', line 915 def asc OrderedExpression.new(@expression, false, :nulls=>@nulls) end |
#desc ⇒ Object
Return a copy that is ordered DESC
920 921 922 |
# File 'lib/sequel/sql.rb', line 920 def desc OrderedExpression.new(@expression, true, :nulls=>@nulls) end |
#invert ⇒ Object
Return an inverted expression, changing ASC to DESC and NULLS FIRST to NULLS LAST.
925 926 927 |
# File 'lib/sequel/sql.rb', line 925 def invert OrderedExpression.new(@expression, !@descending, :nulls=>INVERT_NULLS.fetch(@nulls, @nulls)) end |