Class: SQLTree::Node::Base
- Inherits:
-
Object
- Object
- SQLTree::Node::Base
- Defined in:
- lib/sql_tree/node.rb
Direct Known Subclasses
Expression, Field, Join, Ordering, SelectExpression, SelectQuery, Source, TableReference, Value, Variable
Class Method Summary collapse
-
.[](sql, options = {}) ⇒ Object
Parses a string, expecting it to be parsable to an instance of the current class.
-
.parse(tokens) ⇒ Object
This method should be implemented by a subclass.
Instance Method Summary collapse
-
#inspect ⇒ Object
Pretty prints this instance for inspection.
-
#quote_str(str) ⇒ Object
Quotes a string so that it can be used within an SQL query.
-
#quote_var(name) ⇒ Object
Quotes a variable name so that it can be safely used within SQL queries.
Class Method Details
.[](sql, options = {}) ⇒ Object
Parses a string, expecting it to be parsable to an instance of the current class.
32 33 34 35 |
# File 'lib/sql_tree/node.rb', line 32 def self.[](sql, = {}) parser = SQLTree::Parser.new(sql, ) self.parse(parser) end |
.parse(tokens) ⇒ Object
This method should be implemented by a subclass.
26 27 28 |
# File 'lib/sql_tree/node.rb', line 26 def self.parse(tokens) raise 'Only implemented in subclasses!' end |
Instance Method Details
#inspect ⇒ Object
Pretty prints this instance for inspection
10 11 12 |
# File 'lib/sql_tree/node.rb', line 10 def inspect "#{self.class.name}[#{self.to_sql}]" end |
#quote_str(str) ⇒ Object
Quotes a string so that it can be used within an SQL query.
21 22 23 |
# File 'lib/sql_tree/node.rb', line 21 def quote_str(str) "'#{str.gsub(/\'/, "''")}'" end |
#quote_var(name) ⇒ Object
Quotes a variable name so that it can be safely used within SQL queries.
16 17 18 |
# File 'lib/sql_tree/node.rb', line 16 def quote_var(name) "\"#{name}\"" end |