Class: Veritas::SQL::Generator::Relation
- Extended by:
- Identifier
- Includes:
- Attribute
- Defined in:
- lib/veritas/sql/generator/relation.rb,
lib/veritas/sql/generator/relation/set.rb,
lib/veritas/sql/generator/relation/base.rb,
lib/veritas/sql/generator/relation/unary.rb,
lib/veritas/sql/generator/relation/binary.rb
Overview
Abstract base class for SQL generation from a relation
Defined Under Namespace
Classes: Base, Binary, 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
48 49 50 51 |
# File 'lib/veritas/sql/generator/relation.rb', line 48 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/veritas/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 |
# File 'lib/veritas/sql/generator/relation.rb', line 31 def self.visit(relation) klass = case relation when Veritas::Relation::Operation::Set then self::Set when Veritas::Relation::Operation::Binary then self::Binary when Veritas::Relation::Operation::Unary then self::Unary when Veritas::Relation::Base then self::Base else raise 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
92 93 94 95 |
# File 'lib/veritas/sql/generator/relation.rb', line 92 def to_s return EMPTY_STRING unless visited? generate_sql(query_columns) end |
#to_sql ⇒ String
Returns the current SQL string
80 81 82 |
# File 'lib/veritas/sql/generator/relation.rb', line 80 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
102 103 104 105 |
# File 'lib/veritas/sql/generator/relation.rb', line 102 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
67 68 69 70 |
# File 'lib/veritas/sql/generator/relation.rb', line 67 def visit(visitable) @sql = dispatch(visitable).to_s.freeze freeze end |
#visited? ⇒ Boolean
Test if a visitable object has been visited
115 116 117 |
# File 'lib/veritas/sql/generator/relation.rb', line 115 def visited? ! @name.nil? end |