Sha256: d12e6c500ad03319d3a2c51416e68efafb4c68b2f0d3dba6ffc37b119fc6888c

Contents?: true

Size: 743 Bytes

Versions: 2

Compression:

Stored size: 743 Bytes

Contents

module SQLTree::Node

  class Source < Base

    child :table_reference
    child :joins

    def initialize(table_reference, joins = [])
      @table_reference, @joins = table_reference, joins
    end

    def table
      table_reference.table
    end

    def table_alias
      table_reference.table_alias
    end

    def to_sql(options = {})
      sql = table_reference.to_sql(options)
      sql << ' ' << joins.map { |j| j.to_sql(options) }.join(' ') if joins.any?
      return sql
    end

    def self.parse(tokens)
      source = self.new(SQLTree::Node::TableReference.parse(tokens))
      while tokens.peek && tokens.peek.join?
        source.joins << SQLTree::Node::Join.parse(tokens)
      end
      return source
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sql_tree-0.2.0 lib/sql_tree/node/source.rb
sql_tree-0.1.1 lib/sql_tree/node/source.rb