Class: SQLTree::Node::TableReference
- Defined in:
- lib/sql_tree/node/table_reference.rb
Instance Attribute Summary collapse
-
#table ⇒ Object
Returns the value of attribute table.
-
#table_alias ⇒ Object
Returns the value of attribute table_alias.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(table, table_alias = nil) ⇒ TableReference
constructor
A new instance of TableReference.
- #to_sql ⇒ Object
Methods inherited from Base
[], #inspect, #quote_str, #quote_var
Constructor Details
#initialize(table, table_alias = nil) ⇒ TableReference
Returns a new instance of TableReference.
7 8 9 |
# File 'lib/sql_tree/node/table_reference.rb', line 7 def initialize(table, table_alias = nil) @table, @table_alias = table, table_alias end |
Instance Attribute Details
#table ⇒ Object
Returns the value of attribute table.
5 6 7 |
# File 'lib/sql_tree/node/table_reference.rb', line 5 def table @table end |
#table_alias ⇒ Object
Returns the value of attribute table_alias.
5 6 7 |
# File 'lib/sql_tree/node/table_reference.rb', line 5 def table_alias @table_alias end |
Class Method Details
.parse(tokens) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sql_tree/node/table_reference.rb', line 21 def self.parse(tokens) if SQLTree::Token::Variable === tokens.next table_reference = self.new(tokens.current.literal) if tokens.peek == SQLTree::Token::AS || SQLTree::Token::Variable === tokens.peek tokens.consume(SQLTree::Token::AS) if tokens.peek == SQLTree::Token::AS table_reference.table_alias = SQLTree::Node::Variable.parse(tokens).name end return table_reference else raise SQLTree::Parser::UnexpectedToken.new(tokens.current) end end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 |
# File 'lib/sql_tree/node/table_reference.rb', line 17 def ==(other) other.table = self.table && other.table_alias == self.table_alias end |
#to_sql ⇒ Object
11 12 13 14 15 |
# File 'lib/sql_tree/node/table_reference.rb', line 11 def to_sql sql = quote_var(table) sql << " AS " << quote_var(table_alias) if table_alias return sql end |