veritas-sql-generator 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.rvmrc +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +20 -10
- data/Guardfile +22 -0
- data/README.rdoc +2 -0
- data/Rakefile +4 -2
- data/TODO +16 -2
- data/config/flay.yml +2 -2
- data/config/flog.yml +1 -1
- data/config/roodi.yml +5 -5
- data/config/site.reek +21 -19
- data/lib/veritas/sql/generator.rb +25 -2
- data/lib/veritas/sql/generator/core_ext/date.rb +20 -0
- data/lib/veritas/sql/generator/core_ext/date_time.rb +45 -0
- data/lib/veritas/sql/generator/direction.rb +3 -1
- data/lib/veritas/sql/generator/function.rb +54 -0
- data/lib/veritas/sql/generator/function/aggregate.rb +134 -0
- data/lib/veritas/sql/generator/function/connective.rb +53 -0
- data/lib/veritas/sql/generator/function/numeric.rb +135 -0
- data/lib/veritas/sql/generator/function/predicate.rb +266 -0
- data/lib/veritas/sql/generator/function/proposition.rb +38 -0
- data/lib/veritas/sql/generator/function/string.rb +29 -0
- data/lib/veritas/sql/generator/identifier.rb +2 -1
- data/lib/veritas/sql/generator/literal.rb +15 -18
- data/lib/veritas/sql/generator/relation.rb +144 -17
- data/lib/veritas/sql/generator/relation/binary.rb +16 -64
- data/lib/veritas/sql/generator/relation/set.rb +30 -22
- data/lib/veritas/sql/generator/relation/unary.rb +131 -78
- data/lib/veritas/sql/generator/version.rb +1 -1
- data/spec/unit/date/iso8601_spec.rb +23 -0
- data/spec/unit/date_time/iso_8601_spec.rb +115 -0
- data/spec/unit/veritas/sql/generator/class_methods/parenthesize_spec.rb +18 -0
- data/spec/unit/veritas/sql/generator/function/aggregate/visit_veritas_aggregate_count_spec.rb +16 -0
- data/spec/unit/veritas/sql/generator/function/aggregate/visit_veritas_aggregate_maximum_spec.rb +16 -0
- data/spec/unit/veritas/sql/generator/function/aggregate/visit_veritas_aggregate_mean_spec.rb +16 -0
- data/spec/unit/veritas/sql/generator/function/aggregate/visit_veritas_aggregate_minimum_spec.rb +16 -0
- data/spec/unit/veritas/sql/generator/function/aggregate/visit_veritas_aggregate_standard_deviation_spec.rb +16 -0
- data/spec/unit/veritas/sql/generator/function/aggregate/visit_veritas_aggregate_sum_spec.rb +16 -0
- data/spec/unit/veritas/sql/generator/function/aggregate/visit_veritas_aggregate_variance_spec.rb +16 -0
- data/spec/unit/veritas/sql/generator/function/connective/visit_veritas_function_connective_conjunction_spec.rb +20 -0
- data/spec/unit/veritas/sql/generator/function/connective/visit_veritas_function_connective_disjunction_spec.rb +20 -0
- data/spec/unit/veritas/sql/generator/function/connective/visit_veritas_function_connective_negation_spec.rb +20 -0
- data/spec/unit/veritas/sql/generator/function/numeric/visit_veritas_function_numeric_absolute_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/function/numeric/visit_veritas_function_numeric_addition_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/function/numeric/visit_veritas_function_numeric_division_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/function/numeric/visit_veritas_function_numeric_exponentiation_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/function/numeric/visit_veritas_function_numeric_modulo_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/function/numeric/visit_veritas_function_numeric_multiplication_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/function/numeric/visit_veritas_function_numeric_square_root_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/function/numeric/visit_veritas_function_numeric_subtraction_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/function/numeric/visit_veritas_function_numeric_unary_minus_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/function/numeric/visit_veritas_function_numeric_unary_plus_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/{logic/visit_veritas_logic_predicate_equality_spec.rb → function/predicate/visit_veritas_function_predicate_equality_spec.rb} +5 -5
- data/spec/unit/veritas/sql/generator/{logic/visit_veritas_logic_predicate_exclusion_spec.rb → function/predicate/visit_veritas_function_predicate_exclusion_spec.rb} +10 -6
- data/spec/unit/veritas/sql/generator/function/predicate/visit_veritas_function_predicate_greater_than_or_equal_to_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/{logic/visit_veritas_logic_predicate_greater_than_spec.rb → function/predicate/visit_veritas_function_predicate_greater_than_spec.rb} +5 -5
- data/spec/unit/veritas/sql/generator/{logic/visit_veritas_logic_predicate_inclusion_spec.rb → function/predicate/visit_veritas_function_predicate_inclusion_spec.rb} +10 -6
- data/spec/unit/veritas/sql/generator/{logic/visit_veritas_logic_predicate_inequality_spec.rb → function/predicate/visit_veritas_function_predicate_inequality_spec.rb} +8 -8
- data/spec/unit/veritas/sql/generator/function/predicate/visit_veritas_function_predicate_less_than_or_equal_to_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/{logic/visit_veritas_logic_predicate_less_than_spec.rb → function/predicate/visit_veritas_function_predicate_less_than_spec.rb} +5 -5
- data/spec/unit/veritas/sql/generator/function/proposition/visit_veritas_function_proposition_contradiction_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/function/proposition/visit_veritas_function_proposition_tautology_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/function/string/visit_veritas_function_string_length_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/literal/class_methods/dup_frozen_spec.rb +2 -2
- data/spec/unit/veritas/sql/generator/relation/binary/base/to_subquery_spec.rb +1 -1
- data/spec/unit/veritas/sql/generator/relation/binary/base/{visit_veritas_base_relation_spec.rb → visit_veritas_relation_base_spec.rb} +3 -3
- data/spec/unit/veritas/sql/generator/relation/binary/to_s_spec.rb +2 -2
- data/spec/unit/veritas/sql/generator/relation/binary/to_subquery_spec.rb +2 -2
- data/spec/unit/veritas/sql/generator/relation/binary/visit_veritas_algebra_join_spec.rb +74 -33
- data/spec/unit/veritas/sql/generator/relation/binary/visit_veritas_algebra_product_spec.rb +63 -19
- data/spec/unit/veritas/sql/generator/relation/class_methods/visit_spec.rb +1 -1
- data/spec/unit/veritas/sql/generator/relation/set/class_methods/normalize_operand_headers_spec.rb +35 -0
- data/spec/unit/veritas/sql/generator/relation/set/to_s_spec.rb +1 -1
- data/spec/unit/veritas/sql/generator/relation/set/to_subquery_spec.rb +4 -4
- data/spec/unit/veritas/sql/generator/relation/set/visit_veritas_algebra_difference_spec.rb +83 -30
- data/spec/unit/veritas/sql/generator/relation/set/visit_veritas_algebra_intersection_spec.rb +80 -30
- data/spec/unit/veritas/sql/generator/relation/set/visit_veritas_algebra_union_spec.rb +80 -30
- data/spec/unit/veritas/sql/generator/relation/to_s_spec.rb +50 -0
- data/spec/unit/veritas/sql/generator/relation/to_subquery_spec.rb +49 -0
- data/spec/unit/veritas/sql/generator/relation/unary/to_s_spec.rb +1 -1
- data/spec/unit/veritas/sql/generator/relation/unary/to_subquery_spec.rb +6 -6
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_extension_spec.rb +165 -0
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_projection_spec.rb +84 -29
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_rename_spec.rb +69 -27
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_restriction_spec.rb +64 -22
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_summarization_spec.rb +652 -0
- data/spec/unit/veritas/sql/generator/relation/unary/{visit_veritas_base_relation_spec.rb → visit_veritas_relation_base_spec.rb} +4 -4
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_limit_spec.rb +60 -20
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_offset_spec.rb +60 -20
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_order_spec.rb +63 -23
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_reverse_spec.rb +60 -20
- data/spec/unit/veritas/sql/generator/relation/visited_spec.rb +1 -1
- data/tasks/metrics/ci.rake +7 -0
- data/tasks/{quality → metrics}/flay.rake +0 -0
- data/tasks/{quality → metrics}/flog.rake +0 -0
- data/tasks/{quality → metrics}/heckle.rake +1 -0
- data/tasks/{quality → metrics}/metric_fu.rake +3 -0
- data/tasks/{quality → metrics}/reek.rake +0 -0
- data/tasks/{quality → metrics}/roodi.rake +0 -0
- data/tasks/{quality → metrics}/yardstick.rake +0 -0
- data/tasks/spec.rake +1 -0
- data/veritas-sql-generator.gemspec +82 -114
- metadata +137 -125
- data/lib/veritas/base_relation.rb +0 -36
- data/lib/veritas/sql/generator/logic.rb +0 -349
- data/spec/unit/veritas/base_relation/name_spec.rb +0 -45
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_connective_conjunction_spec.rb +0 -16
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_connective_disjunction_spec.rb +0 -16
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_connective_negation_spec.rb +0 -16
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_greater_than_or_equal_to_spec.rb +0 -15
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_less_than_or_equal_to_spec.rb +0 -15
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_proposition_contradiction_spec.rb +0 -15
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_proposition_tautology_spec.rb +0 -15
- data/spec/unit/veritas/sql/generator/relation/binary/class_methods/subquery_spec.rb +0 -42
- data/spec/unit/veritas/sql/generator/relation/class_methods/subquery_spec.rb +0 -33
- data/tasks/quality/ci.rake +0 -2
data/.gemtest
ADDED
File without changes
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use @$(basename `pwd`) --create
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,23 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
source :rubygems
|
2
4
|
|
3
|
-
gem 'veritas', '0.0.
|
5
|
+
gem 'veritas', '0.0.4', :git => 'git://github.com/dkubb/veritas.git'
|
4
6
|
|
5
7
|
group :development do
|
6
|
-
gem 'backports', '~> 2.1
|
7
|
-
gem 'jeweler', '~> 1.
|
8
|
-
gem 'rake', '~> 0.
|
8
|
+
gem 'backports', '~> 2.2.1'
|
9
|
+
gem 'jeweler', '~> 1.6.0'
|
10
|
+
gem 'rake', '~> 0.9.0'
|
9
11
|
gem 'rspec', '~> 1.3.2'
|
10
|
-
gem 'yard', '~> 0.
|
12
|
+
gem 'yard', '~> 0.7.1'
|
13
|
+
end
|
14
|
+
|
15
|
+
group :guard do
|
16
|
+
gem 'growl', '~> 1.0.3'
|
17
|
+
gem 'guard', '~> 0.3.4'
|
18
|
+
gem 'guard-bundler', '~> 0.1.3'
|
19
|
+
gem 'guard-ego', '~> 0.0.1'
|
20
|
+
gem 'guard-rspec', '~> 0.3.1'
|
11
21
|
end
|
12
22
|
|
13
|
-
|
14
|
-
|
15
|
-
gem 'jruby-openssl', '~> 0.7.
|
23
|
+
platform :jruby do
|
24
|
+
group :jruby do
|
25
|
+
gem 'jruby-openssl', '~> 0.7.4'
|
16
26
|
end
|
17
27
|
end
|
18
28
|
|
19
29
|
platforms :mri_18 do
|
20
|
-
group :
|
30
|
+
group :metrics do
|
21
31
|
gem 'flay', '~> 1.4.2'
|
22
32
|
gem 'flog', '~> 2.5.1'
|
23
33
|
gem 'heckle', '~> 1.4.3'
|
@@ -28,6 +38,6 @@ platforms :mri_18 do
|
|
28
38
|
gem 'reek', '~> 1.2.8', :git => 'git://github.com/dkubb/reek.git'
|
29
39
|
gem 'roodi', '~> 2.1.0'
|
30
40
|
gem 'ruby2ruby', '= 1.2.2'
|
31
|
-
gem 'yardstick', '~> 0.
|
41
|
+
gem 'yardstick', '~> 0.4.0'
|
32
42
|
end
|
33
43
|
end
|
data/Guardfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
guard 'ego' do
|
4
|
+
watch('Guardfile')
|
5
|
+
end
|
6
|
+
|
7
|
+
guard 'bundler' do
|
8
|
+
watch('Gemfile')
|
9
|
+
end
|
10
|
+
|
11
|
+
guard 'rspec' do
|
12
|
+
# run all specs if the spec_helper or supporting files files are modified
|
13
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
14
|
+
watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
|
15
|
+
|
16
|
+
# run unit specs if associated lib code is modified
|
17
|
+
watch(%r{\Alib/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}"] }
|
18
|
+
watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec' }
|
19
|
+
|
20
|
+
# run a spec if it is modified
|
21
|
+
watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
|
22
|
+
end
|
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'rake'
|
2
4
|
|
3
5
|
require File.expand_path('../lib/veritas/sql/generator/version', __FILE__)
|
4
6
|
|
5
7
|
begin
|
6
|
-
gem('jeweler', '~> 1.
|
8
|
+
gem('jeweler', '~> 1.6.0') if respond_to?(:gem, true)
|
7
9
|
require 'jeweler'
|
8
10
|
|
9
11
|
Jeweler::Tasks.new do |gem|
|
@@ -21,5 +23,5 @@ begin
|
|
21
23
|
|
22
24
|
FileList['tasks/**/*.rake'].each { |task| import task }
|
23
25
|
rescue LoadError
|
24
|
-
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.
|
26
|
+
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.6.0'
|
25
27
|
end
|
data/TODO
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
* Replace some of the conditional
|
2
|
-
where there is special case
|
1
|
+
* Replace some of the conditional function with polymorphism, especially
|
2
|
+
where there is special case function for certain types of generators
|
3
3
|
within other generators.
|
4
4
|
* Replace Equality/Inequality with classes that handle all of the
|
5
5
|
special cases.
|
@@ -15,3 +15,17 @@
|
|
15
15
|
Negation wrapping an Equality/Inclusion) on an *optional* attribute.
|
16
16
|
* Add "OR attribute IS NULL" to the statement to ensure cases when
|
17
17
|
the value is NULL still matches.
|
18
|
+
|
19
|
+
* Handle cases where WHERE clause does and does not reference a function
|
20
|
+
in the SELECT list.
|
21
|
+
* It should collapse the inner subquery when there is no reference, and
|
22
|
+
keep the subquery when it is referenced.
|
23
|
+
* This will likely apply to projection and rename operators too.
|
24
|
+
|
25
|
+
* When Restriction wraps a Summarization, and it would normally wrap the
|
26
|
+
statement and apply a WHERE clause, it should apply the clause using
|
27
|
+
HAVING instead.
|
28
|
+
|
29
|
+
* Handle case where Extension does not reference a column in the
|
30
|
+
wrapped Summarization or Rename. It should be safe to collapse the query
|
31
|
+
in those cases.
|
data/config/flay.yml
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
---
|
2
|
-
threshold:
|
3
|
-
total_score:
|
2
|
+
threshold: 7
|
3
|
+
total_score: 10
|
data/config/flog.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
---
|
2
|
-
threshold:
|
2
|
+
threshold: 14.9
|
data/config/roodi.yml
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
---
|
2
|
-
AbcMetricMethodCheck: { score:
|
2
|
+
AbcMetricMethodCheck: { score: 9.1 }
|
3
3
|
AssignmentInConditionalCheck: { }
|
4
4
|
CaseMissingElseCheck: { }
|
5
|
-
ClassLineCountCheck: { line_count:
|
5
|
+
ClassLineCountCheck: { line_count: 369 }
|
6
6
|
ClassNameCheck: { pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/ }
|
7
7
|
ClassVariableCheck: { }
|
8
8
|
CyclomaticComplexityBlockCheck: { complexity: 2 }
|
9
9
|
CyclomaticComplexityMethodCheck: { complexity: 6 }
|
10
10
|
EmptyRescueBodyCheck: { }
|
11
11
|
ForLoopCheck: { }
|
12
|
-
MethodLineCountCheck: { line_count:
|
13
|
-
MethodNameCheck: { pattern: !ruby/regexp /\A(?:[a-z](?:_?[a-z])+[?!=]?|\[\]=?|==|<=>|[+*&|-])\z/ }
|
14
|
-
ModuleLineCountCheck: { line_count:
|
12
|
+
MethodLineCountCheck: { line_count: 10 }
|
13
|
+
MethodNameCheck: { pattern: !ruby/regexp /\A(?:[a-z\d](?:_?[a-z\d])+[?!=]?|\[\]=?|==|<=>|[+*&|-])\z/ }
|
14
|
+
ModuleLineCountCheck: { line_count: 375 }
|
15
15
|
ModuleNameCheck: { pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/ }
|
16
16
|
ParameterNumberCheck: { parameter_count: 3 }
|
data/config/site.reek
CHANGED
@@ -8,13 +8,16 @@ UncommunicativeParameterName:
|
|
8
8
|
- !ruby/regexp /[0-9]$/
|
9
9
|
- !ruby/regexp /[A-Z]/
|
10
10
|
LargeClass:
|
11
|
-
max_methods:
|
11
|
+
max_methods: 26 # TODO: reduce this in UnaryRelation
|
12
12
|
exclude: []
|
13
13
|
enabled: true
|
14
|
-
max_instance_variables:
|
14
|
+
max_instance_variables: 12 # TODO: reduce this in UnaryRelation
|
15
15
|
UncommunicativeMethodName:
|
16
16
|
accept: []
|
17
|
-
exclude: [
|
17
|
+
exclude: [
|
18
|
+
'Date#iso8601',
|
19
|
+
'DateTime#iso8601'
|
20
|
+
]
|
18
21
|
enabled: true
|
19
22
|
reject:
|
20
23
|
- !ruby/regexp /^[a-z]$/
|
@@ -30,16 +33,15 @@ FeatureEnvy:
|
|
30
33
|
# TODO: change these methods to be class methods
|
31
34
|
'Veritas::SQL::Generator::Attribute#visit_veritas_attribute',
|
32
35
|
'Veritas::SQL::Generator::Identifier#visit_identifier',
|
33
|
-
'Veritas::SQL::Generator::Literal#visit_date_time',
|
34
36
|
'Veritas::SQL::Generator::Literal#visit_numeric',
|
35
37
|
'Veritas::SQL::Generator::Literal#visit_string',
|
36
|
-
'Veritas::SQL::Generator::
|
37
|
-
'Veritas::SQL::Generator::
|
38
|
-
'Veritas::SQL::Generator::
|
39
|
-
'Veritas::SQL::Generator::
|
40
|
-
'Veritas::SQL::Generator::
|
41
|
-
'Veritas::SQL::Generator::
|
42
|
-
'Veritas::SQL::Generator::Relation
|
38
|
+
'Veritas::SQL::Generator::Function::Predicate#visit_veritas_function_predicate_inequality',
|
39
|
+
'Veritas::SQL::Generator::Function::Predicate#exclusive_range_exclusion_sql',
|
40
|
+
'Veritas::SQL::Generator::Function::Predicate#exclusive_range_inclusion_sql',
|
41
|
+
'Veritas::SQL::Generator::Function::Predicate#new_from_enumerable_predicate',
|
42
|
+
'Veritas::SQL::Generator::Function::Predicate#optional?',
|
43
|
+
'Veritas::SQL::Generator::Relation::Unary#collapse_subquery_for?',
|
44
|
+
'Veritas::SQL::Generator::Relation#column_list_for'
|
43
45
|
]
|
44
46
|
enabled: true
|
45
47
|
ClassVariable:
|
@@ -66,7 +68,7 @@ NestedIterators:
|
|
66
68
|
enabled: true
|
67
69
|
max_allowed_nesting: 1
|
68
70
|
LongMethod:
|
69
|
-
max_statements:
|
71
|
+
max_statements: 9
|
70
72
|
exclude: [
|
71
73
|
'Veritas::SQL::Generator::Relation::Unary#to_s'
|
72
74
|
]
|
@@ -84,11 +86,11 @@ UtilityFunction:
|
|
84
86
|
'Veritas::SQL::Generator::Identifier#visit_identifier',
|
85
87
|
'Veritas::SQL::Generator::Literal#visit_numeric',
|
86
88
|
'Veritas::SQL::Generator::Literal#visit_string',
|
87
|
-
'Veritas::SQL::Generator::
|
88
|
-
'Veritas::SQL::Generator::
|
89
|
-
'Veritas::SQL::Generator::
|
90
|
-
'Veritas::SQL::Generator::
|
91
|
-
'Veritas::SQL::Generator::
|
89
|
+
'Veritas::SQL::Generator::Function::Predicate#visit_veritas_function_predicate_inequality',
|
90
|
+
'Veritas::SQL::Generator::Function::Predicate#exclusive_range_exclusion_sql',
|
91
|
+
'Veritas::SQL::Generator::Function::Predicate#exclusive_range_inclusion_sql',
|
92
|
+
'Veritas::SQL::Generator::Function::Predicate#new_from_enumerable_predicate',
|
93
|
+
'Veritas::SQL::Generator::Function::Predicate#optional?',
|
92
94
|
'Veritas::SQL::Generator::Relation::Unary#collapse_subquery_for?'
|
93
95
|
]
|
94
96
|
enabled: true
|
@@ -106,11 +108,11 @@ UncommunicativeVariableName:
|
|
106
108
|
SimulatedPolymorphism:
|
107
109
|
exclude: []
|
108
110
|
enabled: true
|
109
|
-
max_ifs:
|
111
|
+
max_ifs: 2
|
110
112
|
DataClump:
|
111
113
|
exclude: [
|
112
114
|
# TODO: split Range handling methods into separate class/module
|
113
|
-
'Veritas::SQL::Generator::
|
115
|
+
'Veritas::SQL::Generator::Function'
|
114
116
|
]
|
115
117
|
enabled: true
|
116
118
|
max_copies: 1
|
@@ -5,7 +5,8 @@ require 'time'
|
|
5
5
|
|
6
6
|
require 'veritas'
|
7
7
|
|
8
|
-
require 'veritas/
|
8
|
+
require 'veritas/sql/generator/core_ext/date'
|
9
|
+
require 'veritas/sql/generator/core_ext/date_time'
|
9
10
|
|
10
11
|
require 'veritas/sql/generator/visitor'
|
11
12
|
|
@@ -13,7 +14,14 @@ require 'veritas/sql/generator/identifier'
|
|
13
14
|
require 'veritas/sql/generator/attribute'
|
14
15
|
require 'veritas/sql/generator/direction'
|
15
16
|
require 'veritas/sql/generator/literal'
|
16
|
-
|
17
|
+
|
18
|
+
require 'veritas/sql/generator/function'
|
19
|
+
require 'veritas/sql/generator/function/aggregate'
|
20
|
+
require 'veritas/sql/generator/function/connective'
|
21
|
+
require 'veritas/sql/generator/function/numeric'
|
22
|
+
require 'veritas/sql/generator/function/predicate'
|
23
|
+
require 'veritas/sql/generator/function/proposition'
|
24
|
+
require 'veritas/sql/generator/function/string'
|
17
25
|
|
18
26
|
require 'veritas/sql/generator/relation'
|
19
27
|
require 'veritas/sql/generator/relation/unary'
|
@@ -30,6 +38,21 @@ module Veritas
|
|
30
38
|
# Raised when an invalid relation is visited
|
31
39
|
class InvalidRelationError < StandardError; end
|
32
40
|
|
41
|
+
LEFT_PARENTHESIS = '('.freeze
|
42
|
+
RIGHT_PARENTHESIS = ')'.freeze
|
43
|
+
|
44
|
+
# Return a parenthesized SQL statement (inline modification)
|
45
|
+
#
|
46
|
+
# @param [#to_s] sql
|
47
|
+
#
|
48
|
+
# @return [#to_s]
|
49
|
+
# same instance as sql
|
50
|
+
#
|
51
|
+
# @api private
|
52
|
+
def self.parenthesize!(sql)
|
53
|
+
sql.insert(0, LEFT_PARENTHESIS) << RIGHT_PARENTHESIS
|
54
|
+
end
|
55
|
+
|
33
56
|
end # module Generator
|
34
57
|
end # module SQL
|
35
58
|
end # module Veritas
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Extend Date with methods available in ruby 1.9
|
4
|
+
class Date
|
5
|
+
|
6
|
+
ISO_8601_FORMAT = '%F'.freeze
|
7
|
+
|
8
|
+
# Return the Date in ISO8601 date format
|
9
|
+
#
|
10
|
+
# @return [#to_s]
|
11
|
+
#
|
12
|
+
# @todo Remove once backports adds this method
|
13
|
+
#
|
14
|
+
# @api private
|
15
|
+
def iso8601
|
16
|
+
date = frozen? ? dup : self
|
17
|
+
date.strftime(ISO_8601_FORMAT)
|
18
|
+
end unless method_defined? :iso8601
|
19
|
+
|
20
|
+
end # class Date
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Extend DateTime with methods available in ruby 1.9
|
4
|
+
class DateTime
|
5
|
+
|
6
|
+
SEC_FRACTION_MULTIPLIER = RUBY_VERSION < '1.9' ? 60 * 60 * 24 : 1
|
7
|
+
|
8
|
+
# Return the DateTime in ISO8601 date-time format
|
9
|
+
#
|
10
|
+
# @param [Integer] time_scale
|
11
|
+
# the number of significant digits to use for fractional seconds
|
12
|
+
#
|
13
|
+
# @return [#to_s]
|
14
|
+
#
|
15
|
+
# @todo Remove once backports adds this method
|
16
|
+
#
|
17
|
+
# @api private
|
18
|
+
def iso8601(time_scale = 0)
|
19
|
+
super() + iso8601_timediv(time_scale)
|
20
|
+
end unless method_defined?(:iso8601) && instance_method(:iso8601).arity == 1
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# Return the time with fraction seconds
|
25
|
+
#
|
26
|
+
# @param [Integer] time_scale
|
27
|
+
# the number of significant digits to use for fractional seconds
|
28
|
+
#
|
29
|
+
# @return [#to_s]
|
30
|
+
#
|
31
|
+
# @api private
|
32
|
+
def iso8601_timediv(time_scale)
|
33
|
+
date_time = frozen? ? dup : self
|
34
|
+
|
35
|
+
fractional_seconds = unless time_scale.zero?
|
36
|
+
'.%0*d' % [
|
37
|
+
time_scale,
|
38
|
+
date_time.sec_fraction * SEC_FRACTION_MULTIPLIER * 10**time_scale
|
39
|
+
]
|
40
|
+
end
|
41
|
+
|
42
|
+
date_time.strftime("T%T#{fractional_seconds}%Z")
|
43
|
+
end unless method_defined? :iso8601_timediv
|
44
|
+
|
45
|
+
end # class Date
|
@@ -8,6 +8,8 @@ module Veritas
|
|
8
8
|
module Direction
|
9
9
|
include Attribute
|
10
10
|
|
11
|
+
DESC = ' DESC'.freeze
|
12
|
+
|
11
13
|
# Visit an Ascending Direction
|
12
14
|
#
|
13
15
|
# @param [Relation::Operation::Order::Ascending] direction
|
@@ -27,7 +29,7 @@ module Veritas
|
|
27
29
|
#
|
28
30
|
# @api private
|
29
31
|
def visit_veritas_relation_operation_order_descending(direction)
|
30
|
-
|
32
|
+
dispatch(direction.attribute) << DESC
|
31
33
|
end
|
32
34
|
|
33
35
|
end # module Direction
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Veritas
|
4
|
+
module SQL
|
5
|
+
module Generator
|
6
|
+
|
7
|
+
# Generates an SQL statement for a function expression
|
8
|
+
module Function
|
9
|
+
include Attribute, Literal
|
10
|
+
|
11
|
+
private
|
12
|
+
# Return the SQL for a umary prefix operation
|
13
|
+
#
|
14
|
+
# @param [#to_s] operator
|
15
|
+
#
|
16
|
+
# @param [Function::Unary] function
|
17
|
+
#
|
18
|
+
# @return [#to_s]
|
19
|
+
#
|
20
|
+
# @api private
|
21
|
+
def unary_prefix_operation_sql(operator, function)
|
22
|
+
"#{operator} (#{dispatch(function.operand)})"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Return the SQL for a binary prefix operation
|
26
|
+
#
|
27
|
+
# @param [#to_s] operator
|
28
|
+
#
|
29
|
+
# @param [Function::Binary] function
|
30
|
+
#
|
31
|
+
# @return [#to_s]
|
32
|
+
#
|
33
|
+
# @api private
|
34
|
+
def binary_prefix_operation_sql(operator, function)
|
35
|
+
"#{operator} (#{dispatch(function.left)}, #{dispatch(function.right)})"
|
36
|
+
end
|
37
|
+
|
38
|
+
# Return the SQL for a binary infix operation
|
39
|
+
#
|
40
|
+
# @param [#to_s] operator
|
41
|
+
#
|
42
|
+
# @param [Function::Binary] function
|
43
|
+
#
|
44
|
+
# @return [#to_s]
|
45
|
+
#
|
46
|
+
# @api private
|
47
|
+
def binary_infix_operation_sql(operator, function)
|
48
|
+
"#{dispatch(function.left)} #{operator} #{dispatch(function.right)}"
|
49
|
+
end
|
50
|
+
|
51
|
+
end # module Function
|
52
|
+
end # module Generator
|
53
|
+
end # module SQL
|
54
|
+
end # module Veritas
|