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
@@ -1,45 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe BaseRelation, '#name' do
|
6
|
-
subject { object.name }
|
7
|
-
|
8
|
-
let(:header) { [ [ :id, Integer ] ] }
|
9
|
-
let(:body) { [ [ 1 ] ].each }
|
10
|
-
let(:object) { described_class.new(name, header, body) }
|
11
|
-
|
12
|
-
context 'when name is a frozen String' do
|
13
|
-
let(:name) { 'users'.freeze }
|
14
|
-
|
15
|
-
it_should_behave_like 'an idempotent method'
|
16
|
-
|
17
|
-
it { should equal(name) }
|
18
|
-
|
19
|
-
it { should be_frozen }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when name is a String' do
|
23
|
-
let(:name) { 'users' }
|
24
|
-
|
25
|
-
it_should_behave_like 'an idempotent method'
|
26
|
-
|
27
|
-
it { should_not equal(name) }
|
28
|
-
|
29
|
-
it { should eql(name) }
|
30
|
-
|
31
|
-
it { should be_frozen }
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when name responds to #to_s' do
|
35
|
-
let(:name) { :users }
|
36
|
-
|
37
|
-
it_should_behave_like 'an idempotent method'
|
38
|
-
|
39
|
-
it { should_not equal(name) }
|
40
|
-
|
41
|
-
it { should eql(name.to_s) }
|
42
|
-
|
43
|
-
it { should be_frozen }
|
44
|
-
end
|
45
|
-
end
|
data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_connective_conjunction_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SQL::Generator::Logic, '#visit_veritas_logic_connective_conjunction' do
|
6
|
-
subject { object.visit_veritas_logic_connective_conjunction(conjunction) }
|
7
|
-
|
8
|
-
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
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
|
-
it_should_behave_like 'a generated SQL expression'
|
14
|
-
|
15
|
-
its(:to_s) { should eql('("id" = 1 AND "id" <> 2)') }
|
16
|
-
end
|
data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_connective_disjunction_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SQL::Generator::Logic, '#visit_veritas_logic_connective_disjunction' do
|
6
|
-
subject { object.visit_veritas_logic_connective_disjunction(disjunction) }
|
7
|
-
|
8
|
-
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
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
|
-
it_should_behave_like 'a generated SQL expression'
|
14
|
-
|
15
|
-
its(:to_s) { should eql('("id" = 1 OR "id" = 2)') }
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SQL::Generator::Logic, '#visit_veritas_logic_connective_negation' do
|
6
|
-
subject { object.visit_veritas_logic_connective_negation(negation) }
|
7
|
-
|
8
|
-
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
9
|
-
let(:attribute) { Attribute::Integer.new(:id) }
|
10
|
-
let(:negation) { Logic::Connective::Negation.new(attribute.eq(1)) }
|
11
|
-
let(:object) { described_class.new }
|
12
|
-
|
13
|
-
it_should_behave_like 'a generated SQL expression'
|
14
|
-
|
15
|
-
its(:to_s) { should eql('NOT "id" = 1') }
|
16
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SQL::Generator::Logic, '#visit_veritas_logic_predicate_greater_than_or_equal_to' do
|
6
|
-
subject { object.visit_veritas_logic_predicate_greater_than_or_equal_to(greater_than_or_equal_to) }
|
7
|
-
|
8
|
-
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
9
|
-
let(:greater_than_or_equal_to) { Attribute::Integer.new(:id).gte(1) }
|
10
|
-
let(:object) { described_class.new }
|
11
|
-
|
12
|
-
it_should_behave_like 'a generated SQL expression'
|
13
|
-
|
14
|
-
its(:to_s) { should eql('"id" >= 1') }
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SQL::Generator::Logic, '#visit_veritas_logic_predicate_less_than_or_equal_to' do
|
6
|
-
subject { object.visit_veritas_logic_predicate_less_than_or_equal_to(less_than_or_equal_to) }
|
7
|
-
|
8
|
-
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
9
|
-
let(:less_than_or_equal_to) { Attribute::Integer.new(:id).lte(1) }
|
10
|
-
let(:object) { described_class.new }
|
11
|
-
|
12
|
-
it_should_behave_like 'a generated SQL expression'
|
13
|
-
|
14
|
-
its(:to_s) { should eql('"id" <= 1') }
|
15
|
-
end
|
data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_proposition_contradiction_spec.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SQL::Generator::Logic, '#visit_veritas_logic_proposition_contradiction' do
|
6
|
-
subject { object.visit_veritas_logic_proposition_contradiction(contradiction) }
|
7
|
-
|
8
|
-
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
9
|
-
let(:contradiction) { Logic::Proposition::Contradiction.instance }
|
10
|
-
let(:object) { described_class.new }
|
11
|
-
|
12
|
-
it_should_behave_like 'a generated SQL expression'
|
13
|
-
|
14
|
-
its(:to_s) { should eql('1 = 0') }
|
15
|
-
end
|
data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_proposition_tautology_spec.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SQL::Generator::Logic, '#visit_veritas_logic_proposition_tautology' do
|
6
|
-
subject { object.visit_veritas_logic_proposition_tautology(tautology) }
|
7
|
-
|
8
|
-
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
9
|
-
let(:tautology) { Logic::Proposition::Tautology.instance }
|
10
|
-
let(:object) { described_class.new }
|
11
|
-
|
12
|
-
it_should_behave_like 'a generated SQL expression'
|
13
|
-
|
14
|
-
its(:to_s) { should eql('1 = 1') }
|
15
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SQL::Generator::Relation::Binary, '.subquery' do
|
6
|
-
subject { object.subquery(generator) }
|
7
|
-
|
8
|
-
let(:id) { Attribute::Integer.new(:id) }
|
9
|
-
let(:name) { Attribute::String.new(:name) }
|
10
|
-
let(:age) { Attribute::Integer.new(:age, :required => false) }
|
11
|
-
let(:header) { [ id, name, age ] }
|
12
|
-
let(:body) { [ [ 1, 'Dan Kubb', 35 ] ].each }
|
13
|
-
let(:base_relation) { BaseRelation.new('users', header, body) }
|
14
|
-
let(:object) { described_class }
|
15
|
-
|
16
|
-
context 'when generator is a base' do
|
17
|
-
let(:relation) { base_relation }
|
18
|
-
let(:generator) { SQL::Generator::Relation::Binary::Base.new.visit(relation) }
|
19
|
-
|
20
|
-
it_should_behave_like 'a generated SQL expression'
|
21
|
-
|
22
|
-
its(:to_s) { should == '"users"' }
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when generator is a unary' do
|
26
|
-
let(:relation) { base_relation.project([ :id ]) }
|
27
|
-
let(:generator) { SQL::Generator::Relation::Unary.new.visit(relation) }
|
28
|
-
|
29
|
-
it_should_behave_like 'a generated SQL expression'
|
30
|
-
|
31
|
-
its(:to_s) { should eql('(SELECT DISTINCT "id" FROM "users") AS "users"') }
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when generator is a binary' do
|
35
|
-
let(:relation) { base_relation.join(base_relation) }
|
36
|
-
let(:generator) { SQL::Generator::Relation::Binary.new.visit(relation) }
|
37
|
-
|
38
|
-
it_should_behave_like 'a generated SQL expression'
|
39
|
-
|
40
|
-
its(:to_s) { should eql('(SELECT * FROM "users" NATURAL JOIN "users") AS "users"') }
|
41
|
-
end
|
42
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe SQL::Generator::Relation, '.subquery' do
|
6
|
-
subject { object.subquery(generator) }
|
7
|
-
|
8
|
-
let(:id) { Attribute::Integer.new(:id) }
|
9
|
-
let(:name) { Attribute::String.new(:name) }
|
10
|
-
let(:age) { Attribute::Integer.new(:age, :required => false) }
|
11
|
-
let(:header) { [ id, name, age ] }
|
12
|
-
let(:body) { [ [ 1, 'Dan Kubb', 35 ] ].each }
|
13
|
-
let(:base_relation) { BaseRelation.new('users', header, body) }
|
14
|
-
let(:object) { described_class }
|
15
|
-
|
16
|
-
context 'when generator is a unary' do
|
17
|
-
let(:relation) { base_relation.project([ :id ]) }
|
18
|
-
let(:generator) { SQL::Generator::Relation::Unary.new.visit(relation) }
|
19
|
-
|
20
|
-
it_should_behave_like 'a generated SQL expression'
|
21
|
-
|
22
|
-
its(:to_s) { should eql('(SELECT DISTINCT "id" FROM "users") AS "users"') }
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when generator is a binary' do
|
26
|
-
let(:relation) { base_relation.join(base_relation) }
|
27
|
-
let(:generator) { SQL::Generator::Relation::Binary.new.visit(relation) }
|
28
|
-
|
29
|
-
it_should_behave_like 'a generated SQL expression'
|
30
|
-
|
31
|
-
its(:to_s) { should eql('(SELECT * FROM "users" NATURAL JOIN "users") AS "users"') }
|
32
|
-
end
|
33
|
-
end
|
data/tasks/quality/ci.rake
DELETED