axiom-sql-generator 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/.gitignore +37 -0
- data/.rspec +4 -0
- data/.rvmrc +1 -0
- data/.travis.yml +35 -0
- data/CONTRIBUTING.md +11 -0
- data/Gemfile +8 -0
- data/Gemfile.devtools +57 -0
- data/Guardfile +23 -0
- data/LICENSE +20 -0
- data/README.md +70 -0
- data/Rakefile +5 -0
- data/TODO +34 -0
- data/axiom-sql-generator.gemspec +25 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/mutant.yml +3 -0
- data/config/reek.yml +165 -0
- data/config/yardstick.yml +2 -0
- data/lib/axiom-sql-generator.rb +3 -0
- data/lib/axiom/sql/generator.rb +61 -0
- data/lib/axiom/sql/generator/attribute.rb +25 -0
- data/lib/axiom/sql/generator/core_ext/date.rb +20 -0
- data/lib/axiom/sql/generator/core_ext/date_time.rb +46 -0
- data/lib/axiom/sql/generator/direction.rb +38 -0
- data/lib/axiom/sql/generator/function.rb +55 -0
- data/lib/axiom/sql/generator/function/aggregate.rb +134 -0
- data/lib/axiom/sql/generator/function/connective.rb +53 -0
- data/lib/axiom/sql/generator/function/numeric.rb +135 -0
- data/lib/axiom/sql/generator/function/predicate.rb +266 -0
- data/lib/axiom/sql/generator/function/proposition.rb +38 -0
- data/lib/axiom/sql/generator/function/string.rb +29 -0
- data/lib/axiom/sql/generator/identifier.rb +28 -0
- data/lib/axiom/sql/generator/literal.rb +157 -0
- data/lib/axiom/sql/generator/relation.rb +240 -0
- data/lib/axiom/sql/generator/relation/base.rb +14 -0
- data/lib/axiom/sql/generator/relation/binary.rb +136 -0
- data/lib/axiom/sql/generator/relation/insertion.rb +62 -0
- data/lib/axiom/sql/generator/relation/materialized.rb +60 -0
- data/lib/axiom/sql/generator/relation/set.rb +107 -0
- data/lib/axiom/sql/generator/relation/unary.rb +379 -0
- data/lib/axiom/sql/generator/version.rb +12 -0
- data/lib/axiom/sql/generator/visitor.rb +121 -0
- data/spec/rcov.opts +7 -0
- data/spec/shared/generated_sql_behavior.rb +15 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/config_alias.rb +3 -0
- data/spec/unit/axiom/sql/generator/attribute/visit_axiom_attribute_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/class_methods/parenthesize_spec.rb +18 -0
- data/spec/unit/axiom/sql/generator/direction/visit_axiom_relation_operation_order_ascending_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/direction/visit_axiom_relation_operation_order_descending_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_count_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_maximum_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_mean_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_minimum_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_standard_deviation_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_sum_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_variance_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/connective/visit_axiom_function_connective_conjunction_spec.rb +20 -0
- data/spec/unit/axiom/sql/generator/function/connective/visit_axiom_function_connective_disjunction_spec.rb +20 -0
- data/spec/unit/axiom/sql/generator/function/connective/visit_axiom_function_connective_negation_spec.rb +20 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_absolute_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_addition_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_division_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_exponentiation_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_modulo_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_multiplication_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_square_root_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_subtraction_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_unary_minus_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_unary_plus_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_equality_spec.rb +27 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_exclusion_spec.rb +47 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_greater_than_or_equal_to_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_greater_than_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_inclusion_spec.rb +47 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_inequality_spec.rb +55 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_less_than_or_equal_to_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_less_than_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/proposition/visit_axiom_function_proposition_contradiction_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/proposition/visit_axiom_function_proposition_tautology_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/string/visit_axiom_function_string_length_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/identifier/visit_identifier_spec.rb +26 -0
- data/spec/unit/axiom/sql/generator/literal/class_methods/dup_frozen_spec.rb +23 -0
- data/spec/unit/axiom/sql/generator/literal/visit_class_spec.rb +31 -0
- data/spec/unit/axiom/sql/generator/literal/visit_date_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/literal/visit_date_time_spec.rb +55 -0
- data/spec/unit/axiom/sql/generator/literal/visit_enumerable_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/literal/visit_false_class_spec.rb +14 -0
- data/spec/unit/axiom/sql/generator/literal/visit_nil_class_spec.rb +14 -0
- data/spec/unit/axiom/sql/generator/literal/visit_numeric_spec.rb +34 -0
- data/spec/unit/axiom/sql/generator/literal/visit_string_spec.rb +26 -0
- data/spec/unit/axiom/sql/generator/literal/visit_time_spec.rb +97 -0
- data/spec/unit/axiom/sql/generator/literal/visit_true_class_spec.rb +14 -0
- data/spec/unit/axiom/sql/generator/relation/binary/base/to_subquery_spec.rb +35 -0
- data/spec/unit/axiom/sql/generator/relation/binary/base/visit_axiom_relation_base_spec.rb +22 -0
- data/spec/unit/axiom/sql/generator/relation/binary/to_s_spec.rb +35 -0
- data/spec/unit/axiom/sql/generator/relation/binary/to_subquery_spec.rb +35 -0
- data/spec/unit/axiom/sql/generator/relation/binary/visit_axiom_algebra_join_spec.rb +179 -0
- data/spec/unit/axiom/sql/generator/relation/binary/visit_axiom_algebra_product_spec.rb +183 -0
- data/spec/unit/axiom/sql/generator/relation/class_methods/visit_spec.rb +71 -0
- data/spec/unit/axiom/sql/generator/relation/insertion/to_subquery_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/relation/insertion/visit_axiom_relation_operation_insertion_spec.rb +187 -0
- data/spec/unit/axiom/sql/generator/relation/materialized/visit_axiom_relation_materialized_spec.rb +28 -0
- data/spec/unit/axiom/sql/generator/relation/materialized/visited_spec.rb +26 -0
- data/spec/unit/axiom/sql/generator/relation/name_spec.rb +30 -0
- data/spec/unit/axiom/sql/generator/relation/set/class_methods/normalize_operand_headers_spec.rb +35 -0
- data/spec/unit/axiom/sql/generator/relation/set/to_s_spec.rb +55 -0
- data/spec/unit/axiom/sql/generator/relation/set/to_subquery_spec.rb +55 -0
- data/spec/unit/axiom/sql/generator/relation/set/visit_axiom_algebra_difference_spec.rb +191 -0
- data/spec/unit/axiom/sql/generator/relation/set/visit_axiom_algebra_intersection_spec.rb +188 -0
- data/spec/unit/axiom/sql/generator/relation/set/visit_axiom_algebra_union_spec.rb +188 -0
- data/spec/unit/axiom/sql/generator/relation/to_s_spec.rb +50 -0
- data/spec/unit/axiom/sql/generator/relation/to_sql_spec.rb +52 -0
- data/spec/unit/axiom/sql/generator/relation/to_subquery_spec.rb +49 -0
- data/spec/unit/axiom/sql/generator/relation/unary/to_s_spec.rb +55 -0
- data/spec/unit/axiom/sql/generator/relation/unary/to_subquery_spec.rb +75 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_extension_spec.rb +165 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_projection_spec.rb +193 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_rename_spec.rb +178 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_restriction_spec.rb +199 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_summarization_spec.rb +652 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_base_spec.rb +21 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_limit_spec.rb +165 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_offset_spec.rb +165 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_order_spec.rb +183 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_reverse_spec.rb +165 -0
- data/spec/unit/axiom/sql/generator/relation/visit_spec.rb +54 -0
- data/spec/unit/axiom/sql/generator/relation/visited_spec.rb +35 -0
- data/spec/unit/axiom/sql/generator/visitor/class_methods/handler_for_spec.rb +71 -0
- data/spec/unit/axiom/sql/generator/visitor/visit_spec.rb +12 -0
- data/spec/unit/axiom/sql/generator/visitor/visited_spec.rb +11 -0
- data/spec/unit/date/iso8601_spec.rb +23 -0
- data/spec/unit/date_time/iso8601_spec.rb +112 -0
- metadata +325 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Axiom
|
|
4
|
+
module SQL
|
|
5
|
+
module Generator
|
|
6
|
+
module Function
|
|
7
|
+
|
|
8
|
+
# Generates an SQL statement for a numeric function
|
|
9
|
+
module Numeric
|
|
10
|
+
include Function
|
|
11
|
+
|
|
12
|
+
ABSOLUTE = 'ABS'.freeze
|
|
13
|
+
ADD = '+'.freeze
|
|
14
|
+
SUBTRACT = '-'.freeze
|
|
15
|
+
MULTIPLY = '*'.freeze
|
|
16
|
+
DIVIDE = '/'.freeze
|
|
17
|
+
POWER = 'POWER'.freeze
|
|
18
|
+
MOD = 'MOD'.freeze
|
|
19
|
+
SQUARE_ROOT = 'SQRT'.freeze
|
|
20
|
+
|
|
21
|
+
# Visit an Absolute function
|
|
22
|
+
#
|
|
23
|
+
# @param [Function::Numeric::Absolute] absolute
|
|
24
|
+
#
|
|
25
|
+
# @return [#to_s]
|
|
26
|
+
#
|
|
27
|
+
# @api private
|
|
28
|
+
def visit_axiom_function_numeric_absolute(absolute)
|
|
29
|
+
unary_prefix_operation_sql(ABSOLUTE, absolute)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Visit an Addition function
|
|
33
|
+
#
|
|
34
|
+
# @param [Function::Numeric::Addition] addition
|
|
35
|
+
#
|
|
36
|
+
# @return [#to_s]
|
|
37
|
+
#
|
|
38
|
+
# @api private
|
|
39
|
+
def visit_axiom_function_numeric_addition(addition)
|
|
40
|
+
Generator.parenthesize!(binary_infix_operation_sql(ADD, addition))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Visit a Division function
|
|
44
|
+
#
|
|
45
|
+
# @param [Function::Numeric::Division] division
|
|
46
|
+
#
|
|
47
|
+
# @return [#to_s]
|
|
48
|
+
#
|
|
49
|
+
# @api private
|
|
50
|
+
def visit_axiom_function_numeric_division(division)
|
|
51
|
+
Generator.parenthesize!(binary_infix_operation_sql(DIVIDE, division))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Visit a Exponentiation function
|
|
55
|
+
#
|
|
56
|
+
# @param [Function::Numeric::Exponentiation] exponentiation
|
|
57
|
+
#
|
|
58
|
+
# @return [#to_s]
|
|
59
|
+
#
|
|
60
|
+
# @api private
|
|
61
|
+
def visit_axiom_function_numeric_exponentiation(exponentiation)
|
|
62
|
+
binary_prefix_operation_sql(POWER, exponentiation)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Visit a Modulo function
|
|
66
|
+
#
|
|
67
|
+
# @param [Function::Numeric::Modulo] modulo
|
|
68
|
+
#
|
|
69
|
+
# @return [#to_s]
|
|
70
|
+
#
|
|
71
|
+
# @api private
|
|
72
|
+
def visit_axiom_function_numeric_modulo(modulo)
|
|
73
|
+
binary_prefix_operation_sql(MOD, modulo)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Visit a Multiplication function
|
|
77
|
+
#
|
|
78
|
+
# @param [Function::Numeric::Multiplication] multiplication
|
|
79
|
+
#
|
|
80
|
+
# @return [#to_s]
|
|
81
|
+
#
|
|
82
|
+
# @api private
|
|
83
|
+
def visit_axiom_function_numeric_multiplication(multiplication)
|
|
84
|
+
Generator.parenthesize!(binary_infix_operation_sql(MULTIPLY, multiplication))
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Visit a Square Root function
|
|
88
|
+
#
|
|
89
|
+
# @param [Function::Numeric::SquareRoot] square_root
|
|
90
|
+
#
|
|
91
|
+
# @return [#to_s]
|
|
92
|
+
#
|
|
93
|
+
# @api private
|
|
94
|
+
def visit_axiom_function_numeric_square_root(square_root)
|
|
95
|
+
unary_prefix_operation_sql(SQUARE_ROOT, square_root)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Visit an Addition function
|
|
99
|
+
#
|
|
100
|
+
# @param [Function::Numeric::Addition] subtraction
|
|
101
|
+
#
|
|
102
|
+
# @return [#to_s]
|
|
103
|
+
#
|
|
104
|
+
# @api private
|
|
105
|
+
def visit_axiom_function_numeric_subtraction(subtraction)
|
|
106
|
+
Generator.parenthesize!(binary_infix_operation_sql(SUBTRACT, subtraction))
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Visit an Unary Minus function
|
|
110
|
+
#
|
|
111
|
+
# @param [Function::Numeric::UnaryMinus] unary_minus
|
|
112
|
+
#
|
|
113
|
+
# @return [#to_s]
|
|
114
|
+
#
|
|
115
|
+
# @api private
|
|
116
|
+
def visit_axiom_function_numeric_unary_minus(unary_minus)
|
|
117
|
+
unary_prefix_operation_sql(SUBTRACT, unary_minus)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Visit an Unary Plus function
|
|
121
|
+
#
|
|
122
|
+
# @param [Function::Numeric::UnaryPlus] unary_plus
|
|
123
|
+
#
|
|
124
|
+
# @return [#to_s]
|
|
125
|
+
#
|
|
126
|
+
# @api private
|
|
127
|
+
def visit_axiom_function_numeric_unary_plus(unary_plus)
|
|
128
|
+
unary_prefix_operation_sql(ADD, unary_plus)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
end # module Numeric
|
|
132
|
+
end # module Function
|
|
133
|
+
end # module Generator
|
|
134
|
+
end # module SQL
|
|
135
|
+
end # module Axiom
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Axiom
|
|
4
|
+
module SQL
|
|
5
|
+
module Generator
|
|
6
|
+
module Function
|
|
7
|
+
|
|
8
|
+
# Generates an SQL statement for a predicate function
|
|
9
|
+
module Predicate
|
|
10
|
+
include Function
|
|
11
|
+
|
|
12
|
+
EQUAL_TO = '='.freeze
|
|
13
|
+
EQUAL_TO_NULL = 'IS'.freeze
|
|
14
|
+
NOT_EQUAL_TO = '<>'.freeze
|
|
15
|
+
NOT_EQUAL_TO_NULL = 'IS NOT'.freeze
|
|
16
|
+
GREATER_THAN = '>'.freeze
|
|
17
|
+
GREATER_THAN_OR_EQUAL_TO = '>='.freeze
|
|
18
|
+
LESS_THAN = '<'.freeze
|
|
19
|
+
LESS_THAN_OR_EQUAL_TO = '<='.freeze
|
|
20
|
+
IN = 'IN'.freeze
|
|
21
|
+
NOT_IN = 'NOT IN'.freeze
|
|
22
|
+
BETWEEN = 'BETWEEN'.freeze
|
|
23
|
+
NOT_BETWEEN = 'NOT BETWEEN'.freeze
|
|
24
|
+
EMPTY_ARRAY = [].freeze
|
|
25
|
+
|
|
26
|
+
# Visit an Equality predicate
|
|
27
|
+
#
|
|
28
|
+
# @param [Function::Predicate::Equality] equality
|
|
29
|
+
#
|
|
30
|
+
# @return [#to_s]
|
|
31
|
+
#
|
|
32
|
+
# @api private
|
|
33
|
+
def visit_axiom_function_predicate_equality(equality)
|
|
34
|
+
binary_infix_operation_sql(equality.right.nil? ? EQUAL_TO_NULL : EQUAL_TO, equality)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Visit an Inequality predicate
|
|
38
|
+
#
|
|
39
|
+
# @param [Function::Predicate::Inequality] inequality
|
|
40
|
+
#
|
|
41
|
+
# @return [#to_s]
|
|
42
|
+
#
|
|
43
|
+
# @api private
|
|
44
|
+
def visit_axiom_function_predicate_inequality(inequality)
|
|
45
|
+
expressions = inequality_expressions(inequality)
|
|
46
|
+
expressions.one? ? expressions.first : Generator.parenthesize!(expressions.join(' OR '))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Visit an GreaterThan predicate
|
|
50
|
+
#
|
|
51
|
+
# @param [Function::Predicate::GreaterThan] greater_than
|
|
52
|
+
#
|
|
53
|
+
# @return [#to_s]
|
|
54
|
+
#
|
|
55
|
+
# @api private
|
|
56
|
+
def visit_axiom_function_predicate_greater_than(greater_than)
|
|
57
|
+
binary_infix_operation_sql(GREATER_THAN, greater_than)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Visit an GreaterThanOrEqualTo predicate
|
|
61
|
+
#
|
|
62
|
+
# @param [Function::Predicate::GreaterThanOrEqualTo] greater_than_or_equal_to
|
|
63
|
+
#
|
|
64
|
+
# @return [#to_s]
|
|
65
|
+
#
|
|
66
|
+
# @api private
|
|
67
|
+
def visit_axiom_function_predicate_greater_than_or_equal_to(greater_than_or_equal_to)
|
|
68
|
+
binary_infix_operation_sql(GREATER_THAN_OR_EQUAL_TO, greater_than_or_equal_to)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Visit an LessThan predicate
|
|
72
|
+
#
|
|
73
|
+
# @param [Function::Predicate::LessThan] less_than
|
|
74
|
+
#
|
|
75
|
+
# @return [#to_s]
|
|
76
|
+
#
|
|
77
|
+
# @api private
|
|
78
|
+
def visit_axiom_function_predicate_less_than(less_than)
|
|
79
|
+
binary_infix_operation_sql(LESS_THAN, less_than)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Visit an LessThanOrEqualTo predicate
|
|
83
|
+
#
|
|
84
|
+
# @param [Function::Predicate::LessThanOrEqualTo] less_than_or_equal_to
|
|
85
|
+
#
|
|
86
|
+
# @return [#to_s]
|
|
87
|
+
#
|
|
88
|
+
# @api private
|
|
89
|
+
def visit_axiom_function_predicate_less_than_or_equal_to(less_than_or_equal_to)
|
|
90
|
+
binary_infix_operation_sql(LESS_THAN_OR_EQUAL_TO, less_than_or_equal_to)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Visit an Inclusion predicate
|
|
94
|
+
#
|
|
95
|
+
# @param [Function::Predicate::Inclusion] inclusion
|
|
96
|
+
#
|
|
97
|
+
# @return [#to_s]
|
|
98
|
+
#
|
|
99
|
+
# @api private
|
|
100
|
+
def visit_axiom_function_predicate_inclusion(inclusion)
|
|
101
|
+
case inclusion.right
|
|
102
|
+
when Range then range_inclusion_sql(inclusion)
|
|
103
|
+
when EMPTY_ARRAY then FALSE
|
|
104
|
+
else
|
|
105
|
+
binary_infix_operation_sql(IN, inclusion)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Visit an Exclusion predicate
|
|
110
|
+
#
|
|
111
|
+
# @param [Function::Predicate::Exclusion] exclusion
|
|
112
|
+
#
|
|
113
|
+
# @return [#to_s]
|
|
114
|
+
#
|
|
115
|
+
# @api private
|
|
116
|
+
def visit_axiom_function_predicate_exclusion(exclusion)
|
|
117
|
+
case exclusion.right
|
|
118
|
+
when Range then range_exclusion_sql(exclusion)
|
|
119
|
+
when EMPTY_ARRAY then TRUE
|
|
120
|
+
else
|
|
121
|
+
binary_infix_operation_sql(NOT_IN, exclusion)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
private
|
|
126
|
+
|
|
127
|
+
# Return the SQL for an Inclusion using a Range
|
|
128
|
+
#
|
|
129
|
+
# @param [Function::Predicate::Inclusion] inclusion
|
|
130
|
+
#
|
|
131
|
+
# @return [#to_s]
|
|
132
|
+
#
|
|
133
|
+
# @api private
|
|
134
|
+
def range_inclusion_sql(inclusion)
|
|
135
|
+
if inclusion.right.exclude_end?
|
|
136
|
+
exclusive_range_inclusion_sql(inclusion)
|
|
137
|
+
else
|
|
138
|
+
inclusive_range_sql(BETWEEN, inclusion)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Return the SQL for an Exclusion using a Range
|
|
143
|
+
#
|
|
144
|
+
# @param [Function::Predicate::Exclusion] exclusion
|
|
145
|
+
#
|
|
146
|
+
# @return [#to_s]
|
|
147
|
+
#
|
|
148
|
+
# @api private
|
|
149
|
+
def range_exclusion_sql(exclusion)
|
|
150
|
+
if exclusion.right.exclude_end?
|
|
151
|
+
exclusive_range_exclusion_sql(exclusion)
|
|
152
|
+
else
|
|
153
|
+
inclusive_range_sql(NOT_BETWEEN, exclusion)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Return the SQL for an Inclusion using an exclusive Range
|
|
158
|
+
#
|
|
159
|
+
# @param [Function::Predicate::Inclusion] inclusion
|
|
160
|
+
#
|
|
161
|
+
# @return [#to_s]
|
|
162
|
+
#
|
|
163
|
+
# @api private
|
|
164
|
+
def exclusive_range_inclusion_sql(inclusion)
|
|
165
|
+
left = new_from_enumerable_predicate(Axiom::Function::Predicate::GreaterThanOrEqualTo, inclusion, :first)
|
|
166
|
+
right = new_from_enumerable_predicate(Axiom::Function::Predicate::LessThan, inclusion, :last)
|
|
167
|
+
dispatch left.and(right)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Return the SQL for an Exclusion using an exclusive Range
|
|
171
|
+
#
|
|
172
|
+
# @param [Function::Predicate::Exclusion] exclusion
|
|
173
|
+
#
|
|
174
|
+
# @return [#to_s]
|
|
175
|
+
#
|
|
176
|
+
# @api private
|
|
177
|
+
def exclusive_range_exclusion_sql(exclusion)
|
|
178
|
+
left = new_from_enumerable_predicate(Axiom::Function::Predicate::LessThan, exclusion, :first)
|
|
179
|
+
right = new_from_enumerable_predicate(Axiom::Function::Predicate::GreaterThanOrEqualTo, exclusion, :last)
|
|
180
|
+
dispatch left.or(right)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Instantiate a new Predicate object from an Enumerable Predicate
|
|
184
|
+
#
|
|
185
|
+
# @param [Class<Function::Predicate>] klass
|
|
186
|
+
# the type of predicate to create
|
|
187
|
+
# @param [Function::Predicate::Enumerable] predicate
|
|
188
|
+
# the enumerable predicate
|
|
189
|
+
# @param [Symbol] method
|
|
190
|
+
# the method to call on the right operand of the predicate
|
|
191
|
+
# @return [Function::Predicate]
|
|
192
|
+
#
|
|
193
|
+
# @api private
|
|
194
|
+
def new_from_enumerable_predicate(klass, predicate, method)
|
|
195
|
+
klass.new(predicate.left, predicate.right.send(method))
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# Return the expressions for an inequality
|
|
199
|
+
#
|
|
200
|
+
# @param [Function::Predicate::Inequality] inequality
|
|
201
|
+
#
|
|
202
|
+
# @return [Array<#to_s>]
|
|
203
|
+
#
|
|
204
|
+
# @api private
|
|
205
|
+
def inequality_expressions(inequality)
|
|
206
|
+
expressions = [
|
|
207
|
+
inequality_sql(inequality),
|
|
208
|
+
optional_is_null_sql(inequality.left),
|
|
209
|
+
optional_is_null_sql(inequality.right),
|
|
210
|
+
]
|
|
211
|
+
expressions.compact!
|
|
212
|
+
expressions
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
# Return the SQL for an inequality predicate
|
|
216
|
+
#
|
|
217
|
+
# @param [Function::Predicate::Inequality] inequality
|
|
218
|
+
#
|
|
219
|
+
# @return [#to_s]
|
|
220
|
+
#
|
|
221
|
+
# @api private
|
|
222
|
+
def inequality_sql(inequality)
|
|
223
|
+
binary_infix_operation_sql(inequality.right.nil? ? NOT_EQUAL_TO_NULL : NOT_EQUAL_TO, inequality)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# Return the SQL for an operation using an inclusive Range
|
|
227
|
+
#
|
|
228
|
+
# @param [#to_s] operator
|
|
229
|
+
#
|
|
230
|
+
# @param [Function::Predicate::Enumerable] predicate
|
|
231
|
+
#
|
|
232
|
+
# @return [#to_s]
|
|
233
|
+
#
|
|
234
|
+
# @api private
|
|
235
|
+
def inclusive_range_sql(operator, predicate)
|
|
236
|
+
right = predicate.right
|
|
237
|
+
"#{dispatch(predicate.left)} #{operator} #{dispatch(right.first)} AND #{dispatch(right.last)}"
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# Return SQL for an Equality with a nil value for optional attributes
|
|
241
|
+
#
|
|
242
|
+
# @param [Attribute] attribute
|
|
243
|
+
#
|
|
244
|
+
# @return [#to_sql, nil]
|
|
245
|
+
#
|
|
246
|
+
# @api private
|
|
247
|
+
def optional_is_null_sql(attribute)
|
|
248
|
+
dispatch(attribute.eq(nil)) if optional?(attribute)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
# Test if the object is not required
|
|
252
|
+
#
|
|
253
|
+
# @param [Object] operand
|
|
254
|
+
#
|
|
255
|
+
# @return [Boolean]
|
|
256
|
+
#
|
|
257
|
+
# @api private
|
|
258
|
+
def optional?(operand)
|
|
259
|
+
operand.respond_to?(:required?) && ! operand.required?
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
end # module Predicate
|
|
263
|
+
end # module Function
|
|
264
|
+
end # module Generator
|
|
265
|
+
end # module SQL
|
|
266
|
+
end # module Axiom
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Axiom
|
|
4
|
+
module SQL
|
|
5
|
+
module Generator
|
|
6
|
+
module Function
|
|
7
|
+
|
|
8
|
+
# Generates an SQL statement for a proposition function
|
|
9
|
+
module Proposition
|
|
10
|
+
include Function
|
|
11
|
+
|
|
12
|
+
# Visit a Tautology
|
|
13
|
+
#
|
|
14
|
+
# @param [Function::Proposition::Tautology] _tautology
|
|
15
|
+
#
|
|
16
|
+
# @return [#to_s]
|
|
17
|
+
#
|
|
18
|
+
# @api private
|
|
19
|
+
def visit_axiom_function_proposition_tautology(_tautology)
|
|
20
|
+
TRUE
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Visit a Contradiction
|
|
24
|
+
#
|
|
25
|
+
# @param [Function::Proposition::Contradiction] _contradiction
|
|
26
|
+
#
|
|
27
|
+
# @return [#to_s]
|
|
28
|
+
#
|
|
29
|
+
# @api private
|
|
30
|
+
def visit_axiom_function_proposition_contradiction(_contradiction)
|
|
31
|
+
FALSE
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end # module Proposition
|
|
35
|
+
end # module Function
|
|
36
|
+
end # module Generator
|
|
37
|
+
end # module SQL
|
|
38
|
+
end # module Axiom
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Axiom
|
|
4
|
+
module SQL
|
|
5
|
+
module Generator
|
|
6
|
+
module Function
|
|
7
|
+
|
|
8
|
+
# Generates an SQL statement for a string function
|
|
9
|
+
module String
|
|
10
|
+
include Function
|
|
11
|
+
|
|
12
|
+
LENGTH = 'LENGTH'.freeze
|
|
13
|
+
|
|
14
|
+
# Visit a Length function
|
|
15
|
+
#
|
|
16
|
+
# @param [Function::String::Length] length
|
|
17
|
+
#
|
|
18
|
+
# @return [#to_s]
|
|
19
|
+
#
|
|
20
|
+
# @api private
|
|
21
|
+
def visit_axiom_function_string_length(length)
|
|
22
|
+
unary_prefix_operation_sql(LENGTH, length)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end # module String
|
|
26
|
+
end # module Function
|
|
27
|
+
end # module Generator
|
|
28
|
+
end # module SQL
|
|
29
|
+
end # module Axiom
|