axiom-sql-generator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,121 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Axiom
|
4
|
+
module SQL
|
5
|
+
module Generator
|
6
|
+
|
7
|
+
# Visit each node in a axiom AST and execute an associated method
|
8
|
+
class Visitor
|
9
|
+
|
10
|
+
# Raised when the object is not handled by the generator
|
11
|
+
class UnknownObject < StandardError; end
|
12
|
+
|
13
|
+
NAME_SEP_REGEXP = /([a-z])([A-Z])/.freeze
|
14
|
+
NAME_REP = '\1_\2'.freeze
|
15
|
+
DOUBLE_COLON = '::'.freeze
|
16
|
+
UNDERSCORE = '_'.freeze
|
17
|
+
|
18
|
+
# Lookup the handler method for a visitable class
|
19
|
+
#
|
20
|
+
# @param [Class<Visitable>] visitable_class
|
21
|
+
#
|
22
|
+
# @return [#to_sym]
|
23
|
+
#
|
24
|
+
# @raise [UnknownObject]
|
25
|
+
# raised when the visitable object has no handler
|
26
|
+
#
|
27
|
+
# @api private
|
28
|
+
def self.handler_for(visitable_class)
|
29
|
+
handlers[visitable_class] or raise UnknownObject, "No handler for #{visitable_class} in #{self}"
|
30
|
+
end
|
31
|
+
|
32
|
+
# Return the handler cache that maps modules to method names
|
33
|
+
#
|
34
|
+
# @return [Hash]
|
35
|
+
#
|
36
|
+
# @api private
|
37
|
+
def self.handlers
|
38
|
+
@handlers ||= Hash.new do |hash, key|
|
39
|
+
hash[key] = ancestor_methods_for(key).detect do |method|
|
40
|
+
method_defined?(method) || private_method_defined?(method)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Return handler methods for a module's ancestors
|
46
|
+
#
|
47
|
+
# @param [Module] mod
|
48
|
+
#
|
49
|
+
# @return [Array<Symbol>]
|
50
|
+
#
|
51
|
+
# @api private
|
52
|
+
def self.ancestor_methods_for(mod)
|
53
|
+
mod.ancestors.map { |ancestor| method_for(ancestor) }
|
54
|
+
end
|
55
|
+
|
56
|
+
# Return the handler method for a given module
|
57
|
+
#
|
58
|
+
# @param [Module] mod
|
59
|
+
#
|
60
|
+
# @return [Symbol]
|
61
|
+
#
|
62
|
+
# @api private
|
63
|
+
def self.method_for(mod)
|
64
|
+
name = "visit_#{mod.name}"
|
65
|
+
name.gsub!(NAME_SEP_REGEXP, NAME_REP)
|
66
|
+
name.gsub!(DOUBLE_COLON, UNDERSCORE)
|
67
|
+
name.downcase!
|
68
|
+
name.to_sym
|
69
|
+
end
|
70
|
+
|
71
|
+
private_class_method :handlers, :ancestor_methods_for, :method_for
|
72
|
+
|
73
|
+
# Visit an object and generate SQL from each node
|
74
|
+
#
|
75
|
+
# @example
|
76
|
+
# generator.visit(visitable)
|
77
|
+
#
|
78
|
+
# @param [Visitable] _visitable
|
79
|
+
#
|
80
|
+
# @return [self]
|
81
|
+
#
|
82
|
+
# @raise [UnknownObject]
|
83
|
+
# raised when the visitable object has no handler
|
84
|
+
#
|
85
|
+
# @api public
|
86
|
+
def visit(_visitable)
|
87
|
+
raise NotImplementedError, "#{self.class}#visit must be implemented"
|
88
|
+
end
|
89
|
+
|
90
|
+
# Test if a visitable object has been visited
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# visitor.visited? # true or false
|
94
|
+
#
|
95
|
+
# @return [Boolean]
|
96
|
+
#
|
97
|
+
# @api public
|
98
|
+
def visited?
|
99
|
+
raise NotImplementedError, "#{self.class}#visited? must be implemented"
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
# Dispatch the visitable object to a handler method
|
105
|
+
#
|
106
|
+
# @param [Visitable] visitable
|
107
|
+
#
|
108
|
+
# @return [#to_s]
|
109
|
+
#
|
110
|
+
# @raise [UnknownObject]
|
111
|
+
# raised when the visitable object has no handler
|
112
|
+
#
|
113
|
+
# @api private
|
114
|
+
def dispatch(visitable)
|
115
|
+
send(self.class.handler_for(visitable.class), visitable)
|
116
|
+
end
|
117
|
+
|
118
|
+
end # class Visitor
|
119
|
+
end # module Generator
|
120
|
+
end # module SQL
|
121
|
+
end # module Axiom
|
data/spec/rcov.opts
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
shared_examples_for 'a generated SQL expression' do
|
4
|
+
it { should respond_to(:to_s) }
|
5
|
+
|
6
|
+
its(:to_s) { should be_kind_of(String) }
|
7
|
+
end
|
8
|
+
|
9
|
+
shared_examples_for 'a generated SQL SELECT query' do
|
10
|
+
it_should_behave_like 'a generated SQL expression'
|
11
|
+
|
12
|
+
its(:name) { should == relation_name }
|
13
|
+
|
14
|
+
its(:name) { should be_frozen }
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'devtools/spec_helper'
|
4
|
+
|
5
|
+
if ENV['COVERAGE'] == 'true'
|
6
|
+
require 'simplecov'
|
7
|
+
require 'coveralls'
|
8
|
+
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
10
|
+
SimpleCov::Formatter::HTMLFormatter,
|
11
|
+
Coveralls::SimpleCov::Formatter
|
12
|
+
]
|
13
|
+
|
14
|
+
SimpleCov.start do
|
15
|
+
command_name 'spec:unit'
|
16
|
+
add_filter 'config'
|
17
|
+
add_filter 'core_ext'
|
18
|
+
add_filter 'spec'
|
19
|
+
minimum_coverage 100
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'axiom-sql-generator'
|
24
|
+
|
25
|
+
include Axiom
|
26
|
+
|
27
|
+
# require spec support files and shared behavior
|
28
|
+
Dir[File.expand_path('../{support,shared}/**/*.rb', __FILE__)].each do |file|
|
29
|
+
require file
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec.configure do |config|
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator::Attribute, '#visit_axiom_attribute' do
|
6
|
+
subject { object.visit_axiom_attribute(attribute) }
|
7
|
+
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Attribute } }
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
10
|
+
let(:object) { described_class.new }
|
11
|
+
|
12
|
+
it_should_behave_like 'a generated SQL expression'
|
13
|
+
|
14
|
+
its(:to_s) { should eql('"id"') }
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator, '.parenthesize!' do
|
6
|
+
subject { object.parenthesize!(string) }
|
7
|
+
|
8
|
+
let(:string) { '1 + 1' }
|
9
|
+
let(:object) { self.class.described_class }
|
10
|
+
|
11
|
+
it_should_behave_like 'a generated SQL expression'
|
12
|
+
|
13
|
+
it 'modifies the string inline' do
|
14
|
+
should equal(string)
|
15
|
+
end
|
16
|
+
|
17
|
+
its(:to_s) { should == '(1 + 1)' }
|
18
|
+
end
|
data/spec/unit/axiom/sql/generator/direction/visit_axiom_relation_operation_order_ascending_spec.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator::Direction, '#visit_axiom_relation_operation_order_ascending' do
|
6
|
+
subject { object.visit_axiom_relation_operation_order_ascending(direction) }
|
7
|
+
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Direction } }
|
9
|
+
let(:direction) { Attribute::Integer.new(:id).asc }
|
10
|
+
let(:object) { described_class.new }
|
11
|
+
|
12
|
+
it_should_behave_like 'a generated SQL expression'
|
13
|
+
|
14
|
+
its(:to_s) { should eql('"id"') }
|
15
|
+
end
|
data/spec/unit/axiom/sql/generator/direction/visit_axiom_relation_operation_order_descending_spec.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator::Direction, '#visit_axiom_relation_operation_order_descending' do
|
6
|
+
subject { object.visit_axiom_relation_operation_order_descending(direction) }
|
7
|
+
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Direction } }
|
9
|
+
let(:direction) { Attribute::Integer.new(:id).desc }
|
10
|
+
let(:object) { described_class.new }
|
11
|
+
|
12
|
+
it_should_behave_like 'a generated SQL expression'
|
13
|
+
|
14
|
+
its(:to_s) { should eql('"id" DESC') }
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator::Function::Aggregate, '#visit_axiom_aggregate_count' do
|
6
|
+
subject { object.visit_axiom_aggregate_count(count) }
|
7
|
+
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Function::Aggregate } }
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
10
|
+
let(:count) { attribute.count }
|
11
|
+
let(:object) { described_class.new }
|
12
|
+
|
13
|
+
it_should_behave_like 'a generated SQL expression'
|
14
|
+
|
15
|
+
its(:to_s) { should eql('COUNT ("id")') }
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator::Function::Aggregate, '#visit_axiom_aggregate_maximum' do
|
6
|
+
subject { object.visit_axiom_aggregate_maximum(maximum) }
|
7
|
+
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Function::Aggregate } }
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
10
|
+
let(:maximum) { attribute.maximum }
|
11
|
+
let(:object) { described_class.new }
|
12
|
+
|
13
|
+
it_should_behave_like 'a generated SQL expression'
|
14
|
+
|
15
|
+
its(:to_s) { should eql('MAX ("id")') }
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator::Function::Aggregate, '#visit_axiom_aggregate_mean' do
|
6
|
+
subject { object.visit_axiom_aggregate_mean(mean) }
|
7
|
+
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Function::Aggregate } }
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
10
|
+
let(:mean) { attribute.mean }
|
11
|
+
let(:object) { described_class.new }
|
12
|
+
|
13
|
+
it_should_behave_like 'a generated SQL expression'
|
14
|
+
|
15
|
+
its(:to_s) { should eql('AVG ("id")') }
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator::Function::Aggregate, '#visit_axiom_aggregate_minimum' do
|
6
|
+
subject { object.visit_axiom_aggregate_minimum(minimum) }
|
7
|
+
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Function::Aggregate } }
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
10
|
+
let(:minimum) { attribute.minimum }
|
11
|
+
let(:object) { described_class.new }
|
12
|
+
|
13
|
+
it_should_behave_like 'a generated SQL expression'
|
14
|
+
|
15
|
+
its(:to_s) { should eql('MIN ("id")') }
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator::Function::Aggregate, '#visit_axiom_aggregate_standard_deviation' do
|
6
|
+
subject { object.visit_axiom_aggregate_standard_deviation(standard_deviation) }
|
7
|
+
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Function::Aggregate } }
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
10
|
+
let(:standard_deviation) { attribute.standard_deviation }
|
11
|
+
let(:object) { described_class.new }
|
12
|
+
|
13
|
+
it_should_behave_like 'a generated SQL expression'
|
14
|
+
|
15
|
+
its(:to_s) { should eql('STDDEV_POP ("id")') }
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator::Function::Aggregate, '#visit_axiom_aggregate_sum' do
|
6
|
+
subject { object.visit_axiom_aggregate_sum(sum) }
|
7
|
+
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Function::Aggregate } }
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
10
|
+
let(:sum) { attribute.sum }
|
11
|
+
let(:object) { described_class.new }
|
12
|
+
|
13
|
+
it_should_behave_like 'a generated SQL expression'
|
14
|
+
|
15
|
+
its(:to_s) { should eql('COALESCE (SUM ("id"), 0)') }
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator::Function::Aggregate, '#visit_axiom_aggregate_variance' do
|
6
|
+
subject { object.visit_axiom_aggregate_variance(variance) }
|
7
|
+
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Function::Aggregate } }
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
10
|
+
let(:variance) { attribute.variance }
|
11
|
+
let(:object) { described_class.new }
|
12
|
+
|
13
|
+
it_should_behave_like 'a generated SQL expression'
|
14
|
+
|
15
|
+
its(:to_s) { should eql('VAR_POP ("id")') }
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator::Function::Connective, '#visit_axiom_function_connective_conjunction' do
|
6
|
+
subject { object.visit_axiom_function_connective_conjunction(conjunction) }
|
7
|
+
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Function::Connective } }
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
10
|
+
let(:conjunction) { attribute.eq(1).and(attribute.ne(2)) }
|
11
|
+
let(:object) { described_class.new }
|
12
|
+
|
13
|
+
before do
|
14
|
+
described_class.class_eval { include SQL::Generator::Function::Predicate }
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_behave_like 'a generated SQL expression'
|
18
|
+
|
19
|
+
its(:to_s) { should eql('("id" = 1 AND "id" <> 2)') }
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator::Function::Connective, '#visit_axiom_function_connective_disjunction' do
|
6
|
+
subject { object.visit_axiom_function_connective_disjunction(disjunction) }
|
7
|
+
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Function::Connective } }
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
10
|
+
let(:disjunction) { attribute.eq(1).or(attribute.eq(2)) }
|
11
|
+
let(:object) { described_class.new }
|
12
|
+
|
13
|
+
before do
|
14
|
+
described_class.class_eval { include SQL::Generator::Function::Predicate }
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_behave_like 'a generated SQL expression'
|
18
|
+
|
19
|
+
its(:to_s) { should eql('("id" = 1 OR "id" = 2)') }
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SQL::Generator::Function::Connective, '#visit_axiom_function_connective_negation' do
|
6
|
+
subject { object.visit_axiom_function_connective_negation(negation) }
|
7
|
+
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Function::Connective } }
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
10
|
+
let(:negation) { Function::Connective::Negation.new(attribute.eq(1)) }
|
11
|
+
let(:object) { described_class.new }
|
12
|
+
|
13
|
+
before do
|
14
|
+
described_class.class_eval { include SQL::Generator::Function::Predicate }
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_behave_like 'a generated SQL expression'
|
18
|
+
|
19
|
+
its(:to_s) { should eql('NOT ("id" = 1)') }
|
20
|
+
end
|