Class: Sequel::SQL::OrderedExpression

Inherits:
Expression show all
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

Instance Method Summary collapse

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.



865
866
867
# File 'lib/sequel/sql.rb', line 865

def initialize(expression, descending = true, opts={})
  @expression, @descending, @nulls = expression, descending, opts[:nulls]
end

Instance Attribute Details

#descendingObject (readonly)

Whether the expression should order the result set in a descending manner



856
857
858
# File 'lib/sequel/sql.rb', line 856

def descending
  @descending
end

#expressionObject (readonly)

The expression to order the result set by.



853
854
855
# File 'lib/sequel/sql.rb', line 853

def expression
  @expression
end

#nullsObject (readonly)

Whether to sort NULLS FIRST/LAST



859
860
861
# File 'lib/sequel/sql.rb', line 859

def nulls
  @nulls
end

Instance Method Details

#ascObject

Return a copy that is ordered ASC



870
871
872
# File 'lib/sequel/sql.rb', line 870

def asc
  OrderedExpression.new(@expression, false, :nulls=>@nulls)
end

#descObject

Return a copy that is ordered DESC



875
876
877
# File 'lib/sequel/sql.rb', line 875

def desc
  OrderedExpression.new(@expression, true, :nulls=>@nulls)
end

#invertObject

Return an inverted expression, changing ASC to DESC and NULLS FIRST to NULLS LAST.



880
881
882
# File 'lib/sequel/sql.rb', line 880

def invert
  OrderedExpression.new(@expression, !@descending, :nulls=>INVERT_NULLS.fetch(@nulls, @nulls))
end