Class: Sequel::SQL::OrderedExpression
- Inherits:
-
Expression
- Object
- Expression
- Sequel::SQL::OrderedExpression
- Defined in:
- lib/sequel/sql.rb,
lib/sequel/extensions/eval_inspect.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 = 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, #clone, #eql?, #hash, inherited, #inspect
Constructor Details
#initialize(expression, descending = true, opts = OPTS) ⇒ OrderedExpression
Set the expression and descending attributes to the given values. Options:
- :nulls
-
Can be :first/:last for NULLS FIRST/LAST.
1658 1659 1660 1661 1662 1663 |
# File 'lib/sequel/sql.rb', line 1658 def initialize(expression, descending = true, opts=OPTS) @expression = expression @descending = descending @nulls = opts[:nulls] freeze end |
Instance Attribute Details
#descending ⇒ Object (readonly)
Whether the expression should order the result set in a descending manner
1649 1650 1651 |
# File 'lib/sequel/sql.rb', line 1649 def descending @descending end |
#expression ⇒ Object (readonly)
The expression to order the result set by.
1646 1647 1648 |
# File 'lib/sequel/sql.rb', line 1646 def expression @expression end |
#nulls ⇒ Object (readonly)
Whether to sort NULLS FIRST/LAST
1652 1653 1654 |
# File 'lib/sequel/sql.rb', line 1652 def nulls @nulls end |
Instance Method Details
#asc ⇒ Object
Return a copy that is ordered ASC
1666 1667 1668 |
# File 'lib/sequel/sql.rb', line 1666 def asc OrderedExpression.new(@expression, false, :nulls=>@nulls) end |
#desc ⇒ Object
Return a copy that is ordered DESC
1671 1672 1673 |
# File 'lib/sequel/sql.rb', line 1671 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.
1676 1677 1678 |
# File 'lib/sequel/sql.rb', line 1676 def invert OrderedExpression.new(@expression, !@descending, :nulls=>INVERT_NULLS.fetch(@nulls, @nulls)) end |