Class: Axiom::SQL::Generator::Relation
- Extended by:
- Identifier
- Includes:
- Attribute
- Defined in:
- lib/axiom/sql/generator/relation.rb,
lib/axiom/sql/generator/relation/set.rb,
lib/axiom/sql/generator/relation/base.rb,
lib/axiom/sql/generator/relation/unary.rb,
lib/axiom/sql/generator/relation/binary.rb,
lib/axiom/sql/generator/relation/insertion.rb,
lib/axiom/sql/generator/relation/materialized.rb
Overview
Abstract base class for SQL generation from a relation
Direct Known Subclasses
Defined Under Namespace
Classes: Base, Binary, Insertion, Materialized, Set, Unary
Constant Summary collapse
- EMPTY_STRING =
''.freeze
- SEPARATOR =
', '.freeze
- STAR =
'*'.freeze
- EMPTY_HASH =
{}.freeze
Constants included from Identifier
Identifier::ESCAPED_QUOTE, Identifier::QUOTE
Constants inherited from Visitor
Visitor::DOUBLE_COLON, Visitor::NAME_REP, Visitor::NAME_SEP_REGEXP, Visitor::UNDERSCORE
Instance Attribute Summary collapse
-
#name ⇒ #to_s
readonly
private
Return the alias name.
Class Method Summary collapse
-
.visit(relation) ⇒ Generator::Relation
private
Factory method to instantiate the generator for the relation.
Instance Method Summary collapse
-
#initialize ⇒ undefined
constructor
private
Initialize a Generator.
-
#to_s ⇒ #to_s
Return the SQL for the unary relation.
-
#to_sql ⇒ String
Returns the current SQL string.
-
#to_subquery ⇒ #to_s
private
Return the SQL suitable for an subquery.
-
#visit(visitable) ⇒ self
Visit an object and generate SQL from each node.
-
#visited? ⇒ Boolean
Test if a visitable object has been visited.
Methods included from Identifier
Methods included from Attribute
Methods inherited from Visitor
Constructor Details
#initialize ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a Generator
51 52 53 54 |
# File 'lib/axiom/sql/generator/relation.rb', line 51 def initialize @sql = EMPTY_STRING @extensions = {} end |
Instance Attribute Details
#name ⇒ #to_s (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the alias name
22 23 24 |
# File 'lib/axiom/sql/generator/relation.rb', line 22 def name @name end |
Class Method Details
.visit(relation) ⇒ Generator::Relation
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Factory method to instantiate the generator for the relation
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/axiom/sql/generator/relation.rb', line 31 def self.visit(relation) klass = case relation when Axiom::Relation::Operation::Insertion then self::Insertion when Axiom::Relation::Operation::Set then self::Set when Axiom::Relation::Operation::Binary then self::Binary when Axiom::Relation::Operation::Unary then self::Unary when Axiom::Relation::Base then self::Base when Axiom::Relation::Materialized then self::Materialized else fail InvalidRelationError, "#{relation.class} is not a visitable relation" end klass.new.visit(relation) end |
Instance Method Details
#to_s ⇒ #to_s
Return the SQL for the unary relation
95 96 97 98 |
# File 'lib/axiom/sql/generator/relation.rb', line 95 def to_s return EMPTY_STRING unless visited? generate_sql(query_columns) end |
#to_sql ⇒ String
Returns the current SQL string
83 84 85 |
# File 'lib/axiom/sql/generator/relation.rb', line 83 def to_sql @sql end |
#to_subquery ⇒ #to_s
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the SQL suitable for an subquery
105 106 107 108 |
# File 'lib/axiom/sql/generator/relation.rb', line 105 def to_subquery return EMPTY_STRING unless visited? Generator.parenthesize!(generate_sql(subquery_columns)) end |
#visit(visitable) ⇒ self
Visit an object and generate SQL from each node
70 71 72 73 |
# File 'lib/axiom/sql/generator/relation.rb', line 70 def visit(visitable) @sql = dispatch(visitable).to_s.freeze freeze end |
#visited? ⇒ Boolean
Test if a visitable object has been visited
118 119 120 |
# File 'lib/axiom/sql/generator/relation.rb', line 118 def visited? instance_variable_defined?(:@name) end |