Sha256: c9adf45862bc5046cceb3ac8ea768540646252b8f10fb8aa3d05c2576f56ac4f

Contents?: true

Size: 574 Bytes

Versions: 2

Compression:

Stored size: 574 Bytes

Contents

module SQLTree::Node

  class Ordering < Base

    attr_accessor :expression, :direction

    def initialize(expression, direction = nil)
      @expression, @direction = expression, direction
    end

    def to_sql
      sql = expression.to_sql
      sql << " #{direction.to_s.upcase}" if direction
      sql
    end

    def self.parse(tokens)
      ordering = self.new(SQLTree::Node::Expression.parse(tokens))
      if tokens.peek && tokens.peek.direction?
        ordering.direction = tokens.next.literal.downcase.to_sym
      end
      return ordering
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sql_tree-0.1.0 lib/sql_tree/node/ordering.rb
sql_tree-0.0.3 lib/sql_tree/node/ordering.rb