Class: Veritas::SQL::Generator::Relation::Unary
- Inherits:
-
Veritas::SQL::Generator::Relation
- Object
- Visitor
- Veritas::SQL::Generator::Relation
- Veritas::SQL::Generator::Relation::Unary
- Extended by:
- Aliasable
- Defined in:
- lib/veritas/sql/generator/relation/unary.rb
Overview
Generates an SQL statement for a unary relation
Direct Known Subclasses
Constant Summary collapse
- DISTINCT =
'DISTINCT '.freeze
- COLLAPSIBLE =
{ Algebra::Projection => Set[ Algebra::Projection, Algebra::Restriction, ].freeze, Algebra::Restriction => Set[ Algebra::Projection, Veritas::Relation::Operation::Order, Veritas::Relation::Operation::Reverse, ].freeze, Veritas::Relation::Operation::Order => Set[ Algebra::Projection, Algebra::Restriction, Veritas::Relation::Operation::Order, Veritas::Relation::Operation::Reverse, Algebra::Rename ].freeze, Veritas::Relation::Operation::Reverse => Set[ Algebra::Projection, Algebra::Restriction, Veritas::Relation::Operation::Order, Veritas::Relation::Operation::Reverse, Algebra::Rename ].freeze, Veritas::Relation::Operation::Offset => Set[ Algebra::Projection, Algebra::Restriction, Veritas::Relation::Operation::Order, Veritas::Relation::Operation::Reverse, Algebra::Rename ].freeze, Veritas::Relation::Operation::Limit => Set[ Algebra::Projection, Algebra::Restriction, Veritas::Relation::Operation::Order, Veritas::Relation::Operation::Reverse, Veritas::Relation::Operation::Offset, Algebra::Rename ].freeze, Algebra::Rename => Set[ Algebra::Projection, Algebra::Restriction, Veritas::Relation::Operation::Order, Veritas::Relation::Operation::Reverse, Veritas::Relation::Operation::Offset, Veritas::Relation::Operation::Limit ].freeze, }.freeze
Constants included from Identifier
Identifier::ESCAPED_QUOTE, Identifier::QUOTE
Constants included from Literal
Literal::DATETIME_FORMAT, Literal::DATE_FORMAT, Literal::ESCAPED_QUOTE, Literal::FALSE, Literal::NULL, Literal::QUOTE, Literal::SEPARATOR, Literal::TIME_SCALE, Literal::TRUE
Constants included from Logic
Logic::AND, Logic::BETWEEN, Logic::EMPTY_ARRAY, Logic::EQUAL_TO, Logic::EQUAL_TO_NULL, Logic::GREATER_THAN, Logic::GREATER_THAN_OR_EQUAL_TO, Logic::IN, Logic::LESS_THAN, Logic::LESS_THAN_OR_EQUAL_TO, Logic::MATCH_ALL, Logic::MATCH_NONE, Logic::NOT_BETWEEN, Logic::NOT_EQUAL_TO, Logic::NOT_EQUAL_TO_NULL, Logic::NOT_IN, Logic::OR
Constants inherited from Veritas::SQL::Generator::Relation
ALL_COLUMNS, EMPTY_STRING, SEPARATOR
Constants inherited from Visitor
Visitor::DOUBLE_COLON, Visitor::NAME_REP, Visitor::NAME_SEP_REGEXP, Visitor::UNDERSCORE
Instance Attribute Summary
Attributes inherited from Veritas::SQL::Generator::Relation
Instance Method Summary collapse
-
#initialize ⇒ undefined
constructor
private
Initialize a Unary relation SQL generator.
-
#to_s ⇒ #to_s
Return the SQL for the unary relation.
-
#to_subquery ⇒ #to_s
private
Return the SQL suitable for an subquery.
-
#visit_veritas_algebra_projection(projection) ⇒ self
private
Visit a Projection.
-
#visit_veritas_algebra_rename(rename) ⇒ self
private
Visit a Rename.
-
#visit_veritas_algebra_restriction(restriction) ⇒ self
private
Visit a Restriction.
-
#visit_veritas_base_relation(base_relation) ⇒ self
private
Visit a Base Relation.
-
#visit_veritas_relation_operation_limit(limit) ⇒ self
private
Visit a Limit.
-
#visit_veritas_relation_operation_offset(offset) ⇒ self
private
Visit an Offset.
-
#visit_veritas_relation_operation_order(order) ⇒ self
private
Visit an Order.
Methods included from Direction
#visit_veritas_relation_operation_order_ascending, #visit_veritas_relation_operation_order_descending
Methods included from Attribute
Methods included from Identifier
Methods included from Literal
dup_frozen, #visit_class, #visit_date, #visit_date_time, #visit_enumerable, #visit_false_class, #visit_nil_class, #visit_numeric, #visit_string, #visit_time, #visit_true_class
Methods included from Logic
#visit_veritas_logic_connective_conjunction, #visit_veritas_logic_connective_disjunction, #visit_veritas_logic_connective_negation, #visit_veritas_logic_predicate_equality, #visit_veritas_logic_predicate_exclusion, #visit_veritas_logic_predicate_greater_than, #visit_veritas_logic_predicate_greater_than_or_equal_to, #visit_veritas_logic_predicate_inclusion, #visit_veritas_logic_predicate_inequality, #visit_veritas_logic_predicate_less_than, #visit_veritas_logic_predicate_less_than_or_equal_to, #visit_veritas_logic_proposition_contradiction, #visit_veritas_logic_proposition_tautology
Methods inherited from Veritas::SQL::Generator::Relation
subquery, #to_sql, visit, #visit, #visited?
Methods inherited from Visitor
handler_for, #visit, #visited?
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 Unary relation SQL generator
31 32 33 34 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 31 def initialize super @scope = ::Set.new end |
Instance Method Details
#to_s ⇒ #to_s
Return the SQL for the unary relation
147 148 149 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 147 def to_s generate_sql(@columns) 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
156 157 158 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 156 def to_subquery generate_sql(all_columns? ? ALL_COLUMNS : @columns) end |
#visit_veritas_algebra_projection(projection) ⇒ self
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.
Visit a Projection
57 58 59 60 61 62 63 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 57 def visit_veritas_algebra_projection(projection) @from = subquery_for(projection) @distinct = DISTINCT @columns = columns_for(projection) scope_query(projection) self end |
#visit_veritas_algebra_rename(rename) ⇒ self
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.
Visit a Rename
72 73 74 75 76 77 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 72 def visit_veritas_algebra_rename(rename) @from = subquery_for(rename) @columns = columns_for(rename.operand, rename.aliases.to_hash) scope_query(rename) self end |
#visit_veritas_algebra_restriction(restriction) ⇒ self
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.
Visit a Restriction
86 87 88 89 90 91 92 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 86 def visit_veritas_algebra_restriction(restriction) @from = subquery_for(restriction) @where = dispatch(restriction.predicate) @columns ||= columns_for(restriction) scope_query(restriction) self end |
#visit_veritas_base_relation(base_relation) ⇒ self
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.
Visit a Base Relation
43 44 45 46 47 48 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 43 def visit_veritas_base_relation(base_relation) @name = base_relation.name @from = visit_identifier(@name) @columns = columns_for(base_relation) self end |
#visit_veritas_relation_operation_limit(limit) ⇒ self
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.
Visit a Limit
116 117 118 119 120 121 122 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 116 def visit_veritas_relation_operation_limit(limit) @from = subquery_for(limit) @limit = limit.limit @columns ||= columns_for(limit) scope_query(limit) self end |
#visit_veritas_relation_operation_offset(offset) ⇒ self
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.
Visit an Offset
131 132 133 134 135 136 137 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 131 def visit_veritas_relation_operation_offset(offset) @from = subquery_for(offset) @offset = offset.offset @columns ||= columns_for(offset) scope_query(offset) self end |
#visit_veritas_relation_operation_order(order) ⇒ self
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.
Visit an Order
101 102 103 104 105 106 107 |
# File 'lib/veritas/sql/generator/relation/unary.rb', line 101 def visit_veritas_relation_operation_order(order) @from = subquery_for(order) @order = order_for(order.directions) @columns ||= columns_for(order) scope_query(order) self end |