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, #eql?, #hash, inherited, #inspect, #lit, #sql_literal
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.
1365 1366 1367 |
# File 'lib/sequel/sql.rb', line 1365 def initialize(expression, descending = true, opts=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
1356 1357 1358 |
# File 'lib/sequel/sql.rb', line 1356 def descending @descending end |
#expression ⇒ Object (readonly)
The expression to order the result set by.
1353 1354 1355 |
# File 'lib/sequel/sql.rb', line 1353 def expression @expression end |
#nulls ⇒ Object (readonly)
Whether to sort NULLS FIRST/LAST
1359 1360 1361 |
# File 'lib/sequel/sql.rb', line 1359 def nulls @nulls end |
Instance Method Details
#asc ⇒ Object
Return a copy that is ordered ASC
1370 1371 1372 |
# File 'lib/sequel/sql.rb', line 1370 def asc OrderedExpression.new(@expression, false, :nulls=>@nulls) end |
#desc ⇒ Object
Return a copy that is ordered DESC
1375 1376 1377 |
# File 'lib/sequel/sql.rb', line 1375 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.
1380 1381 1382 |
# File 'lib/sequel/sql.rb', line 1380 def invert OrderedExpression.new(@expression, !@descending, :nulls=>INVERT_NULLS.fetch(@nulls, @nulls)) end |