axiom-sql-generator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +7 -0
  2. data/.gemtest +0 -0
  3. data/.gitignore +37 -0
  4. data/.rspec +4 -0
  5. data/.rvmrc +1 -0
  6. data/.travis.yml +35 -0
  7. data/CONTRIBUTING.md +11 -0
  8. data/Gemfile +8 -0
  9. data/Gemfile.devtools +57 -0
  10. data/Guardfile +23 -0
  11. data/LICENSE +20 -0
  12. data/README.md +70 -0
  13. data/Rakefile +5 -0
  14. data/TODO +34 -0
  15. data/axiom-sql-generator.gemspec +25 -0
  16. data/config/flay.yml +3 -0
  17. data/config/flog.yml +2 -0
  18. data/config/mutant.yml +3 -0
  19. data/config/reek.yml +165 -0
  20. data/config/yardstick.yml +2 -0
  21. data/lib/axiom-sql-generator.rb +3 -0
  22. data/lib/axiom/sql/generator.rb +61 -0
  23. data/lib/axiom/sql/generator/attribute.rb +25 -0
  24. data/lib/axiom/sql/generator/core_ext/date.rb +20 -0
  25. data/lib/axiom/sql/generator/core_ext/date_time.rb +46 -0
  26. data/lib/axiom/sql/generator/direction.rb +38 -0
  27. data/lib/axiom/sql/generator/function.rb +55 -0
  28. data/lib/axiom/sql/generator/function/aggregate.rb +134 -0
  29. data/lib/axiom/sql/generator/function/connective.rb +53 -0
  30. data/lib/axiom/sql/generator/function/numeric.rb +135 -0
  31. data/lib/axiom/sql/generator/function/predicate.rb +266 -0
  32. data/lib/axiom/sql/generator/function/proposition.rb +38 -0
  33. data/lib/axiom/sql/generator/function/string.rb +29 -0
  34. data/lib/axiom/sql/generator/identifier.rb +28 -0
  35. data/lib/axiom/sql/generator/literal.rb +157 -0
  36. data/lib/axiom/sql/generator/relation.rb +240 -0
  37. data/lib/axiom/sql/generator/relation/base.rb +14 -0
  38. data/lib/axiom/sql/generator/relation/binary.rb +136 -0
  39. data/lib/axiom/sql/generator/relation/insertion.rb +62 -0
  40. data/lib/axiom/sql/generator/relation/materialized.rb +60 -0
  41. data/lib/axiom/sql/generator/relation/set.rb +107 -0
  42. data/lib/axiom/sql/generator/relation/unary.rb +379 -0
  43. data/lib/axiom/sql/generator/version.rb +12 -0
  44. data/lib/axiom/sql/generator/visitor.rb +121 -0
  45. data/spec/rcov.opts +7 -0
  46. data/spec/shared/generated_sql_behavior.rb +15 -0
  47. data/spec/spec_helper.rb +33 -0
  48. data/spec/support/config_alias.rb +3 -0
  49. data/spec/unit/axiom/sql/generator/attribute/visit_axiom_attribute_spec.rb +15 -0
  50. data/spec/unit/axiom/sql/generator/class_methods/parenthesize_spec.rb +18 -0
  51. data/spec/unit/axiom/sql/generator/direction/visit_axiom_relation_operation_order_ascending_spec.rb +15 -0
  52. data/spec/unit/axiom/sql/generator/direction/visit_axiom_relation_operation_order_descending_spec.rb +15 -0
  53. data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_count_spec.rb +16 -0
  54. data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_maximum_spec.rb +16 -0
  55. data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_mean_spec.rb +16 -0
  56. data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_minimum_spec.rb +16 -0
  57. data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_standard_deviation_spec.rb +16 -0
  58. data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_sum_spec.rb +16 -0
  59. data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_variance_spec.rb +16 -0
  60. data/spec/unit/axiom/sql/generator/function/connective/visit_axiom_function_connective_conjunction_spec.rb +20 -0
  61. data/spec/unit/axiom/sql/generator/function/connective/visit_axiom_function_connective_disjunction_spec.rb +20 -0
  62. data/spec/unit/axiom/sql/generator/function/connective/visit_axiom_function_connective_negation_spec.rb +20 -0
  63. data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_absolute_spec.rb +15 -0
  64. data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_addition_spec.rb +15 -0
  65. data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_division_spec.rb +15 -0
  66. data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_exponentiation_spec.rb +15 -0
  67. data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_modulo_spec.rb +15 -0
  68. data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_multiplication_spec.rb +15 -0
  69. data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_square_root_spec.rb +15 -0
  70. data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_subtraction_spec.rb +15 -0
  71. data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_unary_minus_spec.rb +15 -0
  72. data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_unary_plus_spec.rb +15 -0
  73. data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_equality_spec.rb +27 -0
  74. data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_exclusion_spec.rb +47 -0
  75. data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_greater_than_or_equal_to_spec.rb +15 -0
  76. data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_greater_than_spec.rb +15 -0
  77. data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_inclusion_spec.rb +47 -0
  78. data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_inequality_spec.rb +55 -0
  79. data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_less_than_or_equal_to_spec.rb +15 -0
  80. data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_less_than_spec.rb +15 -0
  81. data/spec/unit/axiom/sql/generator/function/proposition/visit_axiom_function_proposition_contradiction_spec.rb +15 -0
  82. data/spec/unit/axiom/sql/generator/function/proposition/visit_axiom_function_proposition_tautology_spec.rb +15 -0
  83. data/spec/unit/axiom/sql/generator/function/string/visit_axiom_function_string_length_spec.rb +15 -0
  84. data/spec/unit/axiom/sql/generator/identifier/visit_identifier_spec.rb +26 -0
  85. data/spec/unit/axiom/sql/generator/literal/class_methods/dup_frozen_spec.rb +23 -0
  86. data/spec/unit/axiom/sql/generator/literal/visit_class_spec.rb +31 -0
  87. data/spec/unit/axiom/sql/generator/literal/visit_date_spec.rb +15 -0
  88. data/spec/unit/axiom/sql/generator/literal/visit_date_time_spec.rb +55 -0
  89. data/spec/unit/axiom/sql/generator/literal/visit_enumerable_spec.rb +15 -0
  90. data/spec/unit/axiom/sql/generator/literal/visit_false_class_spec.rb +14 -0
  91. data/spec/unit/axiom/sql/generator/literal/visit_nil_class_spec.rb +14 -0
  92. data/spec/unit/axiom/sql/generator/literal/visit_numeric_spec.rb +34 -0
  93. data/spec/unit/axiom/sql/generator/literal/visit_string_spec.rb +26 -0
  94. data/spec/unit/axiom/sql/generator/literal/visit_time_spec.rb +97 -0
  95. data/spec/unit/axiom/sql/generator/literal/visit_true_class_spec.rb +14 -0
  96. data/spec/unit/axiom/sql/generator/relation/binary/base/to_subquery_spec.rb +35 -0
  97. data/spec/unit/axiom/sql/generator/relation/binary/base/visit_axiom_relation_base_spec.rb +22 -0
  98. data/spec/unit/axiom/sql/generator/relation/binary/to_s_spec.rb +35 -0
  99. data/spec/unit/axiom/sql/generator/relation/binary/to_subquery_spec.rb +35 -0
  100. data/spec/unit/axiom/sql/generator/relation/binary/visit_axiom_algebra_join_spec.rb +179 -0
  101. data/spec/unit/axiom/sql/generator/relation/binary/visit_axiom_algebra_product_spec.rb +183 -0
  102. data/spec/unit/axiom/sql/generator/relation/class_methods/visit_spec.rb +71 -0
  103. data/spec/unit/axiom/sql/generator/relation/insertion/to_subquery_spec.rb +15 -0
  104. data/spec/unit/axiom/sql/generator/relation/insertion/visit_axiom_relation_operation_insertion_spec.rb +187 -0
  105. data/spec/unit/axiom/sql/generator/relation/materialized/visit_axiom_relation_materialized_spec.rb +28 -0
  106. data/spec/unit/axiom/sql/generator/relation/materialized/visited_spec.rb +26 -0
  107. data/spec/unit/axiom/sql/generator/relation/name_spec.rb +30 -0
  108. data/spec/unit/axiom/sql/generator/relation/set/class_methods/normalize_operand_headers_spec.rb +35 -0
  109. data/spec/unit/axiom/sql/generator/relation/set/to_s_spec.rb +55 -0
  110. data/spec/unit/axiom/sql/generator/relation/set/to_subquery_spec.rb +55 -0
  111. data/spec/unit/axiom/sql/generator/relation/set/visit_axiom_algebra_difference_spec.rb +191 -0
  112. data/spec/unit/axiom/sql/generator/relation/set/visit_axiom_algebra_intersection_spec.rb +188 -0
  113. data/spec/unit/axiom/sql/generator/relation/set/visit_axiom_algebra_union_spec.rb +188 -0
  114. data/spec/unit/axiom/sql/generator/relation/to_s_spec.rb +50 -0
  115. data/spec/unit/axiom/sql/generator/relation/to_sql_spec.rb +52 -0
  116. data/spec/unit/axiom/sql/generator/relation/to_subquery_spec.rb +49 -0
  117. data/spec/unit/axiom/sql/generator/relation/unary/to_s_spec.rb +55 -0
  118. data/spec/unit/axiom/sql/generator/relation/unary/to_subquery_spec.rb +75 -0
  119. data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_extension_spec.rb +165 -0
  120. data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_projection_spec.rb +193 -0
  121. data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_rename_spec.rb +178 -0
  122. data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_restriction_spec.rb +199 -0
  123. data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_summarization_spec.rb +652 -0
  124. data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_base_spec.rb +21 -0
  125. data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_limit_spec.rb +165 -0
  126. data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_offset_spec.rb +165 -0
  127. data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_order_spec.rb +183 -0
  128. data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_reverse_spec.rb +165 -0
  129. data/spec/unit/axiom/sql/generator/relation/visit_spec.rb +54 -0
  130. data/spec/unit/axiom/sql/generator/relation/visited_spec.rb +35 -0
  131. data/spec/unit/axiom/sql/generator/visitor/class_methods/handler_for_spec.rb +71 -0
  132. data/spec/unit/axiom/sql/generator/visitor/visit_spec.rb +12 -0
  133. data/spec/unit/axiom/sql/generator/visitor/visited_spec.rb +11 -0
  134. data/spec/unit/date/iso8601_spec.rb +23 -0
  135. data/spec/unit/date_time/iso8601_spec.rb +112 -0
  136. metadata +325 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d25343b68c5a6f3bdd4ed65617eb70603a9cccb
4
+ data.tar.gz: f9811c6a02fa2d5164bcae6834fd0efcdc1765f4
5
+ SHA512:
6
+ metadata.gz: e653e67c840caddfad52723fd1cd9b292f5b938e58c2b4d0134ed62031d4255e4ea23706ee8b502b4af97615524bac89c4b1476ad4637a77f24d5734b9ee1742
7
+ data.tar.gz: b74b606e245597593ae5967b83511d0d84077029ab70e4fb688f0f0db6435841c17c0c551ae09ebf07aa82ed6450def109e7e949b7e7a25a02ae920f2f43960c
File without changes
@@ -0,0 +1,37 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## Rubinius
17
+ *.rbc
18
+ .rbx
19
+
20
+ ## PROJECT::GENERAL
21
+ *.gem
22
+ coverage
23
+ profiling
24
+ turbulence
25
+ rdoc
26
+ pkg
27
+ tmp
28
+ doc
29
+ log
30
+ .yardoc
31
+ measurements
32
+
33
+ ## BUNDLER
34
+ .bundle
35
+ Gemfile.lock
36
+
37
+ ## PROJECT::SPECIFIC
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format progress
3
+ --profile
4
+ --order random
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use @$(basename `pwd`) --create
@@ -0,0 +1,35 @@
1
+ language: ruby
2
+ before_install: gem install bundler
3
+ bundler_args: --without yard guard benchmarks
4
+ script: "bundle exec rake ci"
5
+ rvm:
6
+ - ree
7
+ - 1.8.7
8
+ - 1.9.2
9
+ - 1.9.3
10
+ - 2.0.0
11
+ - ruby-head
12
+ - rbx-18mode
13
+ - rbx-19mode
14
+ - jruby-18mode
15
+ notifications:
16
+ irc:
17
+ channels:
18
+ - irc.freenode.org#datamapper
19
+ on_success: never
20
+ on_failure: change
21
+ email:
22
+ recipients:
23
+ - dan.kubb@gmail.com
24
+ on_success: never
25
+ on_failure: change
26
+ matrix:
27
+ include:
28
+ - rvm: jruby-19mode
29
+ env: JRUBY_OPTS="$JRUBY_OPTS --debug"
30
+ - rvm: jruby-head
31
+ env: JRUBY_OPTS="$JRUBY_OPTS --debug"
32
+ allow_failures:
33
+ # mutant fails
34
+ - rvm: 1.9.3
35
+ - rvm: rbx-19mode
@@ -0,0 +1,11 @@
1
+ Contributing
2
+ ------------
3
+
4
+ * If you want your code merged into the mainline, please discuss the proposed changes with me before doing any work on it. This library is still in early development, and the direction it is going may not always be clear. Some features may not be appropriate yet, may need to be deferred until later when the foundation for them is laid, or may be more applicable in a plugin.
5
+ * Fork the project.
6
+ * Make your feature addition or bug fix.
7
+ * Follow this [style guide](https://github.com/dkubb/styleguide).
8
+ * Add specs for it. This is important so I don't break it in a future version unintentionally. Tests must cover all branches within the code, and code must be fully covered.
9
+ * Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
10
+ * Run "rake ci". This must pass and not show any regressions in the metrics for the code to be merged.
11
+ * Send me a pull request. Bonus points for topic branches.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'axiom', '~> 0.0.8', :git => 'https://github.com/dkubb/axiom.git'
6
+
7
+ gem 'devtools', :git => 'https://github.com/datamapper/devtools.git'
8
+ eval File.read('Gemfile.devtools')
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+
3
+ group :development do
4
+ gem 'rake', '~> 10.0.4'
5
+ gem 'rspec', '~> 2.13.0'
6
+ gem 'yard', '~> 0.8.5.2'
7
+ end
8
+
9
+ group :yard do
10
+ gem 'kramdown', '~> 1.0.1'
11
+ end
12
+
13
+ group :guard do
14
+ gem 'guard', '~> 1.7.0'
15
+ gem 'guard-bundler', '~> 1.0.0'
16
+ gem 'guard-rspec', '~> 2.5.2'
17
+
18
+ # file system change event handling
19
+ gem 'listen', '~> 0.7.3'
20
+ gem 'rb-fchange', '~> 0.0.6', :require => false
21
+ gem 'rb-fsevent', '~> 0.9.3', :require => false
22
+ gem 'rb-inotify', '~> 0.9.0', :require => false
23
+
24
+ # notification handling
25
+ gem 'libnotify', '~> 0.8.0', :require => false
26
+ gem 'rb-notifu', '~> 0.0.4', :require => false
27
+ gem 'terminal-notifier-guard', '~> 1.5.3', :require => false
28
+ end
29
+
30
+ group :metrics do
31
+ gem 'backports', '~> 3.3', '>= 3.3.0'
32
+ gem 'coveralls', '~> 0.6.4'
33
+ gem 'flay', '~> 2.1.0'
34
+ gem 'flog', '~> 3.2.3'
35
+ gem 'reek', '~> 1.3.1', :git => 'https://github.com/troessner/reek.git'
36
+ gem 'simplecov', '~> 0.7.1'
37
+ gem 'yardstick', '~> 0.9.5'
38
+ gem 'yard-spellcheck', '~> 0.1.5'
39
+
40
+ platforms :mri_19, :rbx do
41
+ gem 'mutant', '~> 0.2.20'
42
+ end
43
+
44
+ platforms :rbx do
45
+ gem 'pelusa', '~> 0.2.2'
46
+ end
47
+ end
48
+
49
+ group :benchmarks do
50
+ gem 'rbench', '~> 0.2.3'
51
+ end
52
+
53
+ platform :jruby do
54
+ group :jruby do
55
+ gem 'jruby-openssl', '~> 0.8.5'
56
+ end
57
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ guard :bundler do
4
+ watch('Gemfile')
5
+ end
6
+
7
+ guard :rspec, :cli => File.read('.rspec').split.join(' '), :keep_failed => false do
8
+ # run all specs if configuration is modified
9
+ watch('Guardfile') { 'spec' }
10
+ watch('Gemfile.lock') { 'spec' }
11
+ watch('spec/spec_helper.rb') { 'spec' }
12
+
13
+ # run all specs if supporting files files are modified
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(%r{\Alib/(.+)/support/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}/#{m[2]}"] }
19
+ watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec' }
20
+
21
+ # run a spec if it is modified
22
+ watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
23
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010-2013 Dan Kubb
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,70 @@
1
+ axiom-sql-generator
2
+ ===================
3
+
4
+ Relational algebra SQL generator
5
+
6
+ [![Gem Version](https://badge.fury.io/rb/axiom-sql-generator.png)][gem]
7
+ [![Build Status](https://secure.travis-ci.org/dkubb/axiom-sql-generator.png?branch=master)][travis]
8
+ [![Dependency Status](https://gemnasium.com/dkubb/axiom-sql-generator.png)][gemnasium]
9
+ [![Code Climate](https://codeclimate.com/github/dkubb/axiom-sql-generator.png)][codeclimate]
10
+ [![Coverage Status](https://coveralls.io/repos/dkubb/axiom-sql-generator/badge.png?branch=master)][coveralls]
11
+
12
+ [gem]: https://rubygems.org/gems/axiom-sql-generator
13
+ [travis]: https://travis-ci.org/dkubb/axiom-sql-generator
14
+ [gemnasium]: https://gemnasium.com/dkubb/axiom-sql-generator
15
+ [codeclimate]: https://codeclimate.com/github/dkubb/axiom-sql-generator
16
+ [coveralls]: https://coveralls.io/r/dkubb/axiom-sql-generator
17
+
18
+ Installation
19
+ ------------
20
+
21
+ With Rubygems:
22
+
23
+ ```bash
24
+ $ gem install axiom-sql-generator
25
+ $ irb -rubygems
26
+ >> require 'axiom-sql-generator'
27
+ => true
28
+ ```
29
+
30
+ With git and local working copy:
31
+
32
+ ```bash
33
+ $ git clone git://github.com/dkubb/axiom-sql-generator.git
34
+ $ cd axiom-sql-generator
35
+ $ rake install
36
+ $ irb -rubygems
37
+ >> require 'axiom-sql-generator'
38
+ => true
39
+ ```
40
+
41
+ Usage
42
+ -----
43
+
44
+ ```ruby
45
+ # visit every node in the relation AST
46
+ generator = Axiom::SQL::Generator::Relation.visit(relation)
47
+
48
+ # generate an SQL string
49
+ sql = generator.to_sql
50
+
51
+ # generate an SQL subquery string
52
+ subquery_sql = generator.to_subquery
53
+ ```
54
+
55
+ Description
56
+ -----------
57
+
58
+ The purpose of this gem is to produce valid SQL from a [axiom](https://github.com/dkubb/axiom) relation. A relation is a representation of a query constructed using relational algebra organized into an AST. Each node in the AST corresponds to an operation defined in the algebra.
59
+
60
+ The SQL produced has been verified and tested against [PostgreSQL](http://www.postgresql.org/) 9.0.4. Dialects for [MySQL](http://www.mysql.com/), [SQLite](http://www.sqlite.org/), [Oracle](http://www.oracle.com/) and [SQL Server](http://www.microsoft.com/sqlserver/) are planned.
61
+
62
+ Contributing
63
+ ------------
64
+
65
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
66
+
67
+ Copyright
68
+ ---------
69
+
70
+ Copyright © 2010-2013 Dan Kubb. See LICENSE for details.
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ require 'devtools'
4
+
5
+ Devtools.init_rake_tasks
data/TODO ADDED
@@ -0,0 +1,34 @@
1
+ * Replace some of the conditional function with polymorphism, especially
2
+ where there is special case function for certain types of generators
3
+ within other generators.
4
+ * Replace Equality/Inequality with classes that handle all of the
5
+ special cases.
6
+ * Use different classes for inclusive/exclusive Range literals so that
7
+ they can be serialized to SQL differently.
8
+ * Create Axiom::Literal::Range proxy object w/factory method
9
+ * Create Axiom::Literal::Range::Inclusive
10
+ * Create Axiom::Literal::Range::Exclusive
11
+
12
+ * Handle cases where an Inequality/Exclusion predicate is used (or a
13
+ Negation wrapping an Equality/Inclusion) on an *optional* attribute.
14
+ * Add "OR attribute IS NULL" to the statement to ensure cases when
15
+ the value is NULL still matches.
16
+
17
+ * Handle case where Inclusion/Exclusion predicate enumerable contains a nil value.
18
+ * Remove the nil value from the enumerable.
19
+ * If the attribute is *optional*, change query so that "OR attribute IS * NULL"
20
+ is added to the output statement.
21
+
22
+ * Handle cases where WHERE clause does and does not reference a function
23
+ in the SELECT list.
24
+ * It should collapse the inner subquery when there is no reference, and
25
+ keep the subquery when it is referenced.
26
+ * This will likely apply to projection and rename operators too.
27
+
28
+ * When Restriction wraps a Summarization, and it would normally wrap the
29
+ statement and apply a WHERE clause, it should apply the clause using
30
+ HAVING instead.
31
+
32
+ * Handle case where Extension does not reference a column in the
33
+ wrapped Summarization or Rename. It should be safe to collapse the query
34
+ in those cases.
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../lib/axiom/sql/generator/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'axiom-sql-generator'
7
+ gem.version = Axiom::SQL::Generator::VERSION.dup
8
+ gem.authors = ['Dan Kubb']
9
+ gem.email = 'dan.kubb@gmail.com'
10
+ gem.description = 'Generate SQL from a axiom relation'
11
+ gem.summary = 'Relational algebra SQL generator'
12
+ gem.homepage = 'https://github.com/dkubb/axiom-sql-generator'
13
+ gem.licenses = %w[MIT]
14
+
15
+ gem.require_paths = %w[lib]
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.test_files = `git ls-files -- spec/unit`.split($/)
18
+ gem.extra_rdoc_files = %w[LICENSE README.md CONTRIBUTING.md TODO]
19
+
20
+ gem.add_runtime_dependency('axiom', '~> 0.1.0')
21
+
22
+ gem.add_development_dependency('rake', '~> 10.0.4')
23
+ gem.add_development_dependency('rspec', '~> 2.13.0')
24
+ gem.add_development_dependency('yard', '~> 0.8.5.2')
25
+ end
@@ -0,0 +1,3 @@
1
+ ---
2
+ threshold: 63
3
+ total_score: 396
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 12.0
@@ -0,0 +1,3 @@
1
+ ---
2
+ name: axiom-sql-generator
3
+ namespace: Axiom::SQL::Generator
@@ -0,0 +1,165 @@
1
+ ---
2
+ Attribute:
3
+ enabled: true
4
+ exclude:
5
+ - Axiom::SQL::Generator::Relation
6
+ BooleanParameter:
7
+ enabled: true
8
+ exclude: []
9
+ ClassVariable:
10
+ enabled: true
11
+ exclude: []
12
+ ControlParameter:
13
+ enabled: true
14
+ exclude: []
15
+ DataClump:
16
+ enabled: true
17
+ exclude:
18
+ - Axiom::SQL::Generator::Function
19
+ max_copies: 2
20
+ min_clump_size: 2
21
+ DuplicateMethodCall:
22
+ enabled: true
23
+ exclude: []
24
+ max_calls: 1
25
+ allow_calls: []
26
+ FeatureEnvy:
27
+ enabled: true
28
+ exclude:
29
+ - Axiom::SQL::Generator::Function::Predicate#new_from_enumerable_predicate
30
+ - Axiom::SQL::Generator::Function::Predicate#optional?
31
+ - Axiom::SQL::Generator::Function::Predicate#visit_axiom_function_predicate_inequality
32
+ - Axiom::SQL::Generator::Identifier#visit_identifier
33
+ - Axiom::SQL::Generator::Identifier#visit_identifier
34
+ - Axiom::SQL::Generator::Literal#visit_numeric
35
+ - Axiom::SQL::Generator::Literal#visit_string
36
+ - Axiom::SQL::Generator::Literal#visit_string
37
+ - Axiom::SQL::Generator::Relation#column_list_for
38
+ IrresponsibleModule:
39
+ enabled: true
40
+ exclude: []
41
+ LongParameterList:
42
+ enabled: true
43
+ exclude:
44
+ - Axiom::SQL::Generator::Function::Predicate#new_from_enumerable_predicate
45
+ max_params: 2
46
+ overrides:
47
+ initialize:
48
+ max_params: 3
49
+ LongYieldList:
50
+ enabled: true
51
+ exclude: []
52
+ max_params: 2
53
+ NestedIterators:
54
+ enabled: true
55
+ exclude:
56
+ - Axiom::SQL::Generator::Relation::Materialized#visit_axiom_relation_materialized
57
+ - Axiom::SQL::Generator::Visitor#self.handlers
58
+ max_allowed_nesting: 1
59
+ ignore_iterators: []
60
+ NilCheck:
61
+ enabled: true
62
+ exclude:
63
+ - Axiom::SQL::Generator::Function::Predicate#inequality_sql
64
+ - Axiom::SQL::Generator::Function::Predicate#visit_axiom_function_predicate_equality
65
+ RepeatedConditional:
66
+ enabled: true
67
+ exclude:
68
+ - Axiom::SQL::Generator::Relation
69
+ max_ifs: 1
70
+ TooManyInstanceVariables:
71
+ enabled: true
72
+ exclude:
73
+ - Axiom::SQL::Generator::Relation::Binary
74
+ - Axiom::SQL::Generator::Relation::Unary
75
+ max_instance_variables: 3
76
+ TooManyMethods:
77
+ enabled: true
78
+ exclude:
79
+ - Axiom::SQL::Generator::Relation
80
+ - Axiom::SQL::Generator::Relation::Unary
81
+ max_methods: 10
82
+ TooManyStatements:
83
+ enabled: true
84
+ exclude:
85
+ - Date#iso8601
86
+ - DateTime#iso8601_timediv
87
+ - Axiom::SQL::Generator::Function::Predicate#exclusive_range_exclusion_sql
88
+ - Axiom::SQL::Generator::Function::Predicate#exclusive_range_inclusion_sql
89
+ - Axiom::SQL::Generator::Function::Predicate#inequality_expressions
90
+ - Axiom::SQL::Generator::Function::Predicate#visit_axiom_function_predicate_inequality
91
+ - Axiom::SQL::Generator::Literal#visit_class
92
+ - Axiom::SQL::Generator::Relation#column_list_for
93
+ - Axiom::SQL::Generator::Relation#columns_for
94
+ - Axiom::SQL::Generator::Relation#implicit_columns
95
+ - Axiom::SQL::Generator::Relation#self.visit
96
+ - Axiom::SQL::Generator::Relation::Binary#set_operands
97
+ - Axiom::SQL::Generator::Relation::Binary#visit_axiom_algebra_join
98
+ - Axiom::SQL::Generator::Relation::Binary#visit_axiom_algebra_product
99
+ - Axiom::SQL::Generator::Relation::Insertion#visit_axiom_relation_operation_insertion
100
+ - Axiom::SQL::Generator::Relation::Materialized#generate_sql
101
+ - Axiom::SQL::Generator::Relation::Set#self.normalize_operand_headers
102
+ - Axiom::SQL::Generator::Relation::Set#visit_axiom_algebra_difference
103
+ - Axiom::SQL::Generator::Relation::Set#visit_axiom_algebra_intersection
104
+ - Axiom::SQL::Generator::Relation::Set#visit_axiom_algebra_union
105
+ - Axiom::SQL::Generator::Relation::Unary#reset_query_state
106
+ - Axiom::SQL::Generator::Relation::Unary#subquery_for
107
+ - Axiom::SQL::Generator::Relation::Unary#summarize_per
108
+ - Axiom::SQL::Generator::Relation::Unary#visit_axiom_algebra_extension
109
+ - Axiom::SQL::Generator::Relation::Unary#visit_axiom_algebra_projection
110
+ - Axiom::SQL::Generator::Relation::Unary#visit_axiom_algebra_rename
111
+ - Axiom::SQL::Generator::Relation::Unary#visit_axiom_algebra_restriction
112
+ - Axiom::SQL::Generator::Relation::Unary#visit_axiom_algebra_summarization
113
+ - Axiom::SQL::Generator::Relation::Unary#visit_axiom_relation_base
114
+ - Axiom::SQL::Generator::Relation::Unary#visit_axiom_relation_operation_binary
115
+ - Axiom::SQL::Generator::Relation::Unary#visit_axiom_relation_operation_limit
116
+ - Axiom::SQL::Generator::Relation::Unary#visit_axiom_relation_operation_offset
117
+ - Axiom::SQL::Generator::Relation::Unary#visit_axiom_relation_operation_order
118
+ - Axiom::SQL::Generator::Visitor#self.method_for
119
+ - each
120
+ max_statements: 2
121
+ UncommunicativeMethodName:
122
+ enabled: true
123
+ exclude:
124
+ - Date#iso8601
125
+ - DateTime#iso8601
126
+ reject:
127
+ - !ruby/regexp /^[a-z]$/
128
+ - !ruby/regexp /[0-9]$/
129
+ - !ruby/regexp /[A-Z]/
130
+ accept: []
131
+ UncommunicativeModuleName:
132
+ enabled: true
133
+ exclude: []
134
+ reject:
135
+ - !ruby/regexp /^.$/
136
+ - !ruby/regexp /[0-9]$/
137
+ accept: []
138
+ UncommunicativeParameterName:
139
+ enabled: true
140
+ exclude: []
141
+ reject:
142
+ - !ruby/regexp /^.$/
143
+ - !ruby/regexp /[0-9]$/
144
+ - !ruby/regexp /[A-Z]/
145
+ accept: []
146
+ UncommunicativeVariableName:
147
+ enabled: true
148
+ exclude: []
149
+ reject:
150
+ - !ruby/regexp /^.$/
151
+ - !ruby/regexp /[0-9]$/
152
+ - !ruby/regexp /[A-Z]/
153
+ accept: []
154
+ UnusedParameters:
155
+ enabled: true
156
+ exclude: []
157
+ UtilityFunction:
158
+ enabled: true
159
+ exclude:
160
+ - Axiom::SQL::Generator::Function::Predicate#new_from_enumerable_predicate
161
+ - Axiom::SQL::Generator::Function::Predicate#optional?
162
+ - Axiom::SQL::Generator::Identifier#visit_identifier
163
+ - Axiom::SQL::Generator::Literal#visit_numeric
164
+ - Axiom::SQL::Generator::Literal#visit_string
165
+ max_helper_calls: 0