class Sequel::SQL::OrderedExpression

  1. lib/sequel/sql.rb
Parent: SQL

Represents a column/expression to order the result set by.

Methods

Public Class

  1. new

Public Instance

  1. asc
  2. desc
  3. descending
  4. expression
  5. invert
  6. nulls

Constants

INVERT_NULLS = {:first=>:last, :last=>:first}.freeze  

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)

Set the expression and descending attributes to the given values. Options:

:nulls

Can be :first/:last for NULLS FIRST/LAST.

[show source]
# File lib/sequel/sql.rb, line 1365
def initialize(expression, descending = true, opts=OPTS)
  @expression, @descending, @nulls = expression, descending, opts[:nulls]
end

Public Instance methods

asc ()

Return a copy that is ordered ASC

[show source]
# File lib/sequel/sql.rb, line 1370
def asc
  OrderedExpression.new(@expression, false, :nulls=>@nulls)
end
desc ()

Return a copy that is ordered DESC

[show source]
# File lib/sequel/sql.rb, line 1375
def desc
  OrderedExpression.new(@expression, true, :nulls=>@nulls)
end
invert ()

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

[show source]
# File lib/sequel/sql.rb, line 1380
def invert
  OrderedExpression.new(@expression, !@descending, :nulls=>INVERT_NULLS.fetch(@nulls, @nulls))
end