veritas-sql-generator 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/Gemfile +33 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +27 -0
  4. data/Rakefile +25 -0
  5. data/TODO +17 -0
  6. data/config/flay.yml +3 -0
  7. data/config/flog.yml +2 -0
  8. data/config/roodi.yml +16 -0
  9. data/config/site.reek +124 -0
  10. data/config/yardstick.yml +2 -0
  11. data/lib/veritas-sql-generator.rb +3 -0
  12. data/lib/veritas/base_relation.rb +36 -0
  13. data/lib/veritas/sql/generator.rb +35 -0
  14. data/lib/veritas/sql/generator/attribute.rb +25 -0
  15. data/lib/veritas/sql/generator/direction.rb +36 -0
  16. data/lib/veritas/sql/generator/identifier.rb +27 -0
  17. data/lib/veritas/sql/generator/literal.rb +160 -0
  18. data/lib/veritas/sql/generator/logic.rb +349 -0
  19. data/lib/veritas/sql/generator/relation.rb +111 -0
  20. data/lib/veritas/sql/generator/relation/base.rb +14 -0
  21. data/lib/veritas/sql/generator/relation/binary.rb +184 -0
  22. data/lib/veritas/sql/generator/relation/set.rb +99 -0
  23. data/lib/veritas/sql/generator/relation/unary.rb +326 -0
  24. data/lib/veritas/sql/generator/version.rb +9 -0
  25. data/lib/veritas/sql/generator/visitor.rb +121 -0
  26. data/spec/rcov.opts +6 -0
  27. data/spec/shared/command_method_behavior.rb +7 -0
  28. data/spec/shared/generated_sql_behavior.rb +15 -0
  29. data/spec/shared/idempotent_method_behavior.rb +7 -0
  30. data/spec/spec.opts +3 -0
  31. data/spec/spec_helper.rb +15 -0
  32. data/spec/unit/veritas/base_relation/name_spec.rb +45 -0
  33. data/spec/unit/veritas/sql/generator/attribute/visit_veritas_attribute_spec.rb +15 -0
  34. data/spec/unit/veritas/sql/generator/direction/visit_veritas_relation_operation_order_ascending_spec.rb +15 -0
  35. data/spec/unit/veritas/sql/generator/direction/visit_veritas_relation_operation_order_descending_spec.rb +15 -0
  36. data/spec/unit/veritas/sql/generator/identifier/visit_identifier_spec.rb +26 -0
  37. data/spec/unit/veritas/sql/generator/literal/class_methods/dup_frozen_spec.rb +23 -0
  38. data/spec/unit/veritas/sql/generator/literal/visit_class_spec.rb +31 -0
  39. data/spec/unit/veritas/sql/generator/literal/visit_date_spec.rb +15 -0
  40. data/spec/unit/veritas/sql/generator/literal/visit_date_time_spec.rb +61 -0
  41. data/spec/unit/veritas/sql/generator/literal/visit_enumerable_spec.rb +15 -0
  42. data/spec/unit/veritas/sql/generator/literal/visit_false_class_spec.rb +14 -0
  43. data/spec/unit/veritas/sql/generator/literal/visit_nil_class_spec.rb +14 -0
  44. data/spec/unit/veritas/sql/generator/literal/visit_numeric_spec.rb +34 -0
  45. data/spec/unit/veritas/sql/generator/literal/visit_string_spec.rb +26 -0
  46. data/spec/unit/veritas/sql/generator/literal/visit_time_spec.rb +97 -0
  47. data/spec/unit/veritas/sql/generator/literal/visit_true_class_spec.rb +14 -0
  48. data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_connective_conjunction_spec.rb +16 -0
  49. data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_connective_disjunction_spec.rb +16 -0
  50. data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_connective_negation_spec.rb +16 -0
  51. data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_equality_spec.rb +27 -0
  52. data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_exclusion_spec.rb +43 -0
  53. data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_greater_than_or_equal_to_spec.rb +15 -0
  54. data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_greater_than_spec.rb +15 -0
  55. data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_inclusion_spec.rb +43 -0
  56. data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_inequality_spec.rb +55 -0
  57. data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_less_than_or_equal_to_spec.rb +15 -0
  58. data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_less_than_spec.rb +15 -0
  59. data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_proposition_contradiction_spec.rb +15 -0
  60. data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_proposition_tautology_spec.rb +15 -0
  61. data/spec/unit/veritas/sql/generator/relation/binary/base/to_subquery_spec.rb +35 -0
  62. data/spec/unit/veritas/sql/generator/relation/binary/base/visit_veritas_base_relation_spec.rb +22 -0
  63. data/spec/unit/veritas/sql/generator/relation/binary/class_methods/subquery_spec.rb +42 -0
  64. data/spec/unit/veritas/sql/generator/relation/binary/to_s_spec.rb +35 -0
  65. data/spec/unit/veritas/sql/generator/relation/binary/to_subquery_spec.rb +35 -0
  66. data/spec/unit/veritas/sql/generator/relation/binary/visit_veritas_algebra_join_spec.rb +138 -0
  67. data/spec/unit/veritas/sql/generator/relation/binary/visit_veritas_algebra_product_spec.rb +139 -0
  68. data/spec/unit/veritas/sql/generator/relation/class_methods/subquery_spec.rb +33 -0
  69. data/spec/unit/veritas/sql/generator/relation/class_methods/visit_spec.rb +61 -0
  70. data/spec/unit/veritas/sql/generator/relation/name_spec.rb +30 -0
  71. data/spec/unit/veritas/sql/generator/relation/set/to_s_spec.rb +55 -0
  72. data/spec/unit/veritas/sql/generator/relation/set/to_subquery_spec.rb +55 -0
  73. data/spec/unit/veritas/sql/generator/relation/set/visit_veritas_algebra_difference_spec.rb +138 -0
  74. data/spec/unit/veritas/sql/generator/relation/set/visit_veritas_algebra_intersection_spec.rb +138 -0
  75. data/spec/unit/veritas/sql/generator/relation/set/visit_veritas_algebra_union_spec.rb +138 -0
  76. data/spec/unit/veritas/sql/generator/relation/to_sql_spec.rb +52 -0
  77. data/spec/unit/veritas/sql/generator/relation/unary/to_s_spec.rb +55 -0
  78. data/spec/unit/veritas/sql/generator/relation/unary/to_subquery_spec.rb +75 -0
  79. data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_projection_spec.rb +138 -0
  80. data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_rename_spec.rb +136 -0
  81. data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_restriction_spec.rb +157 -0
  82. data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_base_relation_spec.rb +21 -0
  83. data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_limit_spec.rb +125 -0
  84. data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_offset_spec.rb +125 -0
  85. data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_order_spec.rb +136 -0
  86. data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_reverse_spec.rb +125 -0
  87. data/spec/unit/veritas/sql/generator/relation/visit_spec.rb +54 -0
  88. data/spec/unit/veritas/sql/generator/relation/visited_spec.rb +35 -0
  89. data/spec/unit/veritas/sql/generator/visitor/class_methods/handler_for_spec.rb +71 -0
  90. data/spec/unit/veritas/sql/generator/visitor/visit_spec.rb +12 -0
  91. data/spec/unit/veritas/sql/generator/visitor/visited_spec.rb +11 -0
  92. data/tasks/quality/ci.rake +2 -0
  93. data/tasks/quality/flay.rake +41 -0
  94. data/tasks/quality/flog.rake +45 -0
  95. data/tasks/quality/heckle.rake +203 -0
  96. data/tasks/quality/metric_fu.rake +26 -0
  97. data/tasks/quality/reek.rake +9 -0
  98. data/tasks/quality/roodi.rake +15 -0
  99. data/tasks/quality/yardstick.rake +23 -0
  100. data/tasks/spec.rake +38 -0
  101. data/tasks/yard.rake +9 -0
  102. data/veritas-sql-generator.gemspec +222 -0
  103. metadata +285 -0
data/Gemfile ADDED
@@ -0,0 +1,33 @@
1
+ source :rubygems
2
+
3
+ gem 'veritas', '0.0.3', :git => 'git://github.com/dkubb/veritas.git'
4
+
5
+ group :development do
6
+ gem 'backports', '~> 2.1.0'
7
+ gem 'jeweler', '~> 1.5.2'
8
+ gem 'rake', '~> 0.8.7'
9
+ gem 'rspec', '~> 1.3.2'
10
+ gem 'yard', '~> 0.6.8'
11
+ end
12
+
13
+ group :jruby do
14
+ platform :jruby do
15
+ gem 'jruby-openssl', '~> 0.7.3'
16
+ end
17
+ end
18
+
19
+ platforms :mri_18 do
20
+ group :quality do
21
+ gem 'flay', '~> 1.4.2'
22
+ gem 'flog', '~> 2.5.1'
23
+ gem 'heckle', '~> 1.4.3'
24
+ gem 'json', '~> 1.5.1'
25
+ gem 'metric_fu', '~> 2.1.1'
26
+ gem 'mspec', '~> 1.5.17'
27
+ gem 'rcov', '~> 0.9.9'
28
+ gem 'reek', '~> 1.2.8', :git => 'git://github.com/dkubb/reek.git'
29
+ gem 'roodi', '~> 2.1.0'
30
+ gem 'ruby2ruby', '= 1.2.2'
31
+ gem 'yardstick', '~> 0.3.0'
32
+ end
33
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010-2011 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,27 @@
1
+ = Veritas SQL Generator
2
+
3
+ Relational algebra SQL generator
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * If you want your code merged into the mainline, please discuss
8
+ the proposed changes with me before doing any work on it. This
9
+ library is still in early development, and it may not always be
10
+ clear the direction it is going. Some features may not be appropriate
11
+ yet, may need to be deferred until later when the foundation for
12
+ them is laid, or may be more applicable in a plugin.
13
+ * Fork the project.
14
+ * Make your feature addition or bug fix.
15
+ * Follow this {style guide}[https://github.com/dkubb/styleguide].
16
+ * Add specs for it. This is important so I don't break it in a
17
+ future version unintentionally. Tests must cover all branches
18
+ within the code, and code must be fully covered.
19
+ * Commit, do not mess with Rakefile, version, or history.
20
+ (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)
21
+ * Run "rake ci". This must pass and not show any regressions in the
22
+ metrics for the code to be merged.
23
+ * Send me a pull request. Bonus points for topic branches.
24
+
25
+ == Copyright
26
+
27
+ Copyright (c) 2010-2011 Dan Kubb. See LICENSE for details.
@@ -0,0 +1,25 @@
1
+ require 'rake'
2
+
3
+ require File.expand_path('../lib/veritas/sql/generator/version', __FILE__)
4
+
5
+ begin
6
+ gem('jeweler', '~> 1.5.2') if respond_to?(:gem, true)
7
+ require 'jeweler'
8
+
9
+ Jeweler::Tasks.new do |gem|
10
+ gem.name = 'veritas-sql-generator'
11
+ gem.summary = 'Relational algebra SQL generator'
12
+ gem.description = 'Generate SQL from a veritas relation'
13
+ gem.email = 'dan.kubb@gmail.com'
14
+ gem.homepage = 'https://github.com/dkubb/veritas-sql-generator'
15
+ gem.authors = [ 'Dan Kubb' ]
16
+
17
+ gem.version = Veritas::SQL::Generator::VERSION
18
+ end
19
+
20
+ Jeweler::GemcutterTasks.new
21
+
22
+ FileList['tasks/**/*.rake'].each { |task| import task }
23
+ rescue LoadError
24
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.5.2'
25
+ end
data/TODO ADDED
@@ -0,0 +1,17 @@
1
+ * Replace some of the conditional logic with polymorphism, especially
2
+ where there is special case logic 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 Veritas::Literal::Range proxy object w/factory method
9
+ * Create Veritas::Literal::Range::Inclusive
10
+ * Create Veritas::Literal::Range::Exclusive
11
+
12
+ * Adjust reek and roodi scores down to lower thresholds
13
+
14
+ * Handle cases where an Inequality/Exclusion predicate is used (or a
15
+ Negation wrapping an Equality/Inclusion) on an *optional* attribute.
16
+ * Add "OR attribute IS NULL" to the statement to ensure cases when
17
+ the value is NULL still matches.
@@ -0,0 +1,3 @@
1
+ ---
2
+ threshold: 3
3
+ total_score: 3
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 13.3
@@ -0,0 +1,16 @@
1
+ ---
2
+ AbcMetricMethodCheck: { score: 7.1 }
3
+ AssignmentInConditionalCheck: { }
4
+ CaseMissingElseCheck: { }
5
+ ClassLineCountCheck: { line_count: 316 }
6
+ ClassNameCheck: { pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/ }
7
+ ClassVariableCheck: { }
8
+ CyclomaticComplexityBlockCheck: { complexity: 2 }
9
+ CyclomaticComplexityMethodCheck: { complexity: 6 }
10
+ EmptyRescueBodyCheck: { }
11
+ ForLoopCheck: { }
12
+ MethodLineCountCheck: { line_count: 7 }
13
+ MethodNameCheck: { pattern: !ruby/regexp /\A(?:[a-z](?:_?[a-z])+[?!=]?|\[\]=?|==|<=>|[+*&|-])\z/ }
14
+ ModuleLineCountCheck: { line_count: 345 }
15
+ ModuleNameCheck: { pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/ }
16
+ ParameterNumberCheck: { parameter_count: 3 }
@@ -0,0 +1,124 @@
1
+ ---
2
+ UncommunicativeParameterName:
3
+ accept: []
4
+ exclude: []
5
+ enabled: true
6
+ reject:
7
+ - !ruby/regexp /^.$/
8
+ - !ruby/regexp /[0-9]$/
9
+ - !ruby/regexp /[A-Z]/
10
+ LargeClass:
11
+ max_methods: 22 # TODO: reduce this in UnaryRelation
12
+ exclude: []
13
+ enabled: true
14
+ max_instance_variables: 9 # TODO: reduce this in UnaryRelation
15
+ UncommunicativeMethodName:
16
+ accept: []
17
+ exclude: []
18
+ enabled: true
19
+ reject:
20
+ - !ruby/regexp /^[a-z]$/
21
+ - !ruby/regexp /[0-9]$/
22
+ - !ruby/regexp /[A-Z]/
23
+ LongParameterList:
24
+ max_params: 3
25
+ exclude: []
26
+ enabled: true
27
+ overrides: {}
28
+ FeatureEnvy:
29
+ exclude: [
30
+ # TODO: change these methods to be class methods
31
+ 'Veritas::SQL::Generator::Attribute#visit_veritas_attribute',
32
+ 'Veritas::SQL::Generator::Identifier#visit_identifier',
33
+ 'Veritas::SQL::Generator::Literal#visit_date_time',
34
+ 'Veritas::SQL::Generator::Literal#visit_numeric',
35
+ 'Veritas::SQL::Generator::Literal#visit_string',
36
+ 'Veritas::SQL::Generator::Literal#visit_time',
37
+ 'Veritas::SQL::Generator::Logic#visit_veritas_logic_predicate_inequality',
38
+ 'Veritas::SQL::Generator::Logic#exclusive_range_exclusion_sql',
39
+ 'Veritas::SQL::Generator::Logic#exclusive_range_inclusion_sql',
40
+ 'Veritas::SQL::Generator::Logic#new_from_enumerable_predicate',
41
+ 'Veritas::SQL::Generator::Logic#optional?',
42
+ 'Veritas::SQL::Generator::Relation::Unary#collapse_subquery_for?'
43
+ ]
44
+ enabled: true
45
+ ClassVariable:
46
+ exclude: []
47
+ enabled: true
48
+ BooleanParameter:
49
+ exclude: []
50
+ enabled: true
51
+ IrresponsibleModule:
52
+ exclude: []
53
+ enabled: true
54
+ UncommunicativeModuleName:
55
+ accept: []
56
+ exclude: []
57
+ enabled: true
58
+ reject:
59
+ - !ruby/regexp /^.$/
60
+ - !ruby/regexp /[0-9]$/
61
+ NestedIterators:
62
+ ignore_iterators: []
63
+ exclude: [
64
+ 'Veritas::SQL::Generator::Visitor#self.handlers'
65
+ ]
66
+ enabled: true
67
+ max_allowed_nesting: 1
68
+ LongMethod:
69
+ max_statements: 7
70
+ exclude: [
71
+ 'Veritas::SQL::Generator::Relation::Unary#to_s'
72
+ ]
73
+ enabled: true
74
+ Duplication:
75
+ allow_calls: []
76
+ exclude: []
77
+ enabled: true
78
+ max_calls: 1
79
+ UtilityFunction:
80
+ max_helper_calls: 1
81
+ exclude: [
82
+ # TODO: change these methods to be class methods
83
+ 'Veritas::SQL::Generator::Attribute#visit_veritas_attribute',
84
+ 'Veritas::SQL::Generator::Identifier#visit_identifier',
85
+ 'Veritas::SQL::Generator::Literal#visit_numeric',
86
+ 'Veritas::SQL::Generator::Literal#visit_string',
87
+ 'Veritas::SQL::Generator::Logic#visit_veritas_logic_predicate_inequality',
88
+ 'Veritas::SQL::Generator::Logic#exclusive_range_exclusion_sql',
89
+ 'Veritas::SQL::Generator::Logic#exclusive_range_inclusion_sql',
90
+ 'Veritas::SQL::Generator::Logic#new_from_enumerable_predicate',
91
+ 'Veritas::SQL::Generator::Logic#optional?',
92
+ 'Veritas::SQL::Generator::Relation::Unary#collapse_subquery_for?'
93
+ ]
94
+ enabled: true
95
+ Attribute:
96
+ exclude: []
97
+ enabled: false
98
+ UncommunicativeVariableName:
99
+ accept: []
100
+ exclude: []
101
+ enabled: true
102
+ reject:
103
+ - !ruby/regexp /^.$/
104
+ - !ruby/regexp /[0-9]$/
105
+ - !ruby/regexp /[A-Z]/
106
+ SimulatedPolymorphism:
107
+ exclude: []
108
+ enabled: true
109
+ max_ifs: 1
110
+ DataClump:
111
+ exclude: [
112
+ # TODO: split Range handling methods into separate class/module
113
+ 'Veritas::SQL::Generator::Logic'
114
+ ]
115
+ enabled: true
116
+ max_copies: 1
117
+ min_clump_size: 2
118
+ ControlCouple:
119
+ exclude: []
120
+ enabled: true
121
+ LongYieldList:
122
+ max_params: 1
123
+ exclude: []
124
+ enabled: true
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 100
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+
3
+ require 'veritas/sql/generator'
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+
5
+ # A class that represents a base relation in an RDBMS
6
+ class BaseRelation < Relation
7
+
8
+ # The base relation name
9
+ #
10
+ # @example
11
+ # name = base_relation.name
12
+ #
13
+ # @return [#to_s]
14
+ #
15
+ # @api public
16
+ attr_reader :name
17
+
18
+ # Initialize a base relation
19
+ #
20
+ # @param [#to_s] name
21
+ # the relation name
22
+ # @param [Header, #to_ary] header
23
+ # the relation header
24
+ # @param [Enumerable] tuples
25
+ # the relation tuples
26
+ #
27
+ # @return [undefined]
28
+ #
29
+ # @api private
30
+ def initialize(name, *args)
31
+ super(*args)
32
+ @name = Immutable.freeze_object(name.to_s)
33
+ end
34
+
35
+ end # class BaseRelation
36
+ end # module Veritas
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ require 'date'
4
+ require 'time'
5
+
6
+ require 'veritas'
7
+
8
+ require 'veritas/base_relation'
9
+
10
+ require 'veritas/sql/generator/visitor'
11
+
12
+ require 'veritas/sql/generator/identifier'
13
+ require 'veritas/sql/generator/attribute'
14
+ require 'veritas/sql/generator/direction'
15
+ require 'veritas/sql/generator/literal'
16
+ require 'veritas/sql/generator/logic'
17
+
18
+ require 'veritas/sql/generator/relation'
19
+ require 'veritas/sql/generator/relation/unary'
20
+ require 'veritas/sql/generator/relation/base'
21
+ require 'veritas/sql/generator/relation/binary'
22
+ require 'veritas/sql/generator/relation/set'
23
+
24
+ require 'veritas/sql/generator/version'
25
+
26
+ module Veritas
27
+ module SQL
28
+ module Generator
29
+
30
+ # Raised when an invalid relation is visited
31
+ class InvalidRelationError < StandardError; end
32
+
33
+ end # module Generator
34
+ end # module SQL
35
+ end # module Veritas
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ module SQL
5
+ module Generator
6
+
7
+ # Generates an SQL statement for an attribute
8
+ module Attribute
9
+ include Identifier
10
+
11
+ # Visit an Attribute
12
+ #
13
+ # @param [Attribute] attribute
14
+ #
15
+ # @return [#to_s]
16
+ #
17
+ # @api private
18
+ def visit_veritas_attribute(attribute)
19
+ visit_identifier(attribute.name)
20
+ end
21
+
22
+ end # module Attribute
23
+ end # module Generator
24
+ end # module SQL
25
+ end # module Veritas
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ module SQL
5
+ module Generator
6
+
7
+ # Generates an SQL statement for a direction
8
+ module Direction
9
+ include Attribute
10
+
11
+ # Visit an Ascending Direction
12
+ #
13
+ # @param [Relation::Operation::Order::Ascending] direction
14
+ #
15
+ # @return [#to_s]
16
+ #
17
+ # @api private
18
+ def visit_veritas_relation_operation_order_ascending(direction)
19
+ dispatch direction.attribute
20
+ end
21
+
22
+ # Visit an Descending Direction
23
+ #
24
+ # @param [Relation::Operation::Order::Descending] direction
25
+ #
26
+ # @return [#to_s]
27
+ #
28
+ # @api private
29
+ def visit_veritas_relation_operation_order_descending(direction)
30
+ "#{dispatch direction.attribute} DESC"
31
+ end
32
+
33
+ end # module Direction
34
+ end # module Generator
35
+ end # module SQL
36
+ end # module Veritas
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ module SQL
5
+ module Generator
6
+
7
+ # Generates an SQL statement for an identifier
8
+ module Identifier
9
+
10
+ QUOTE = '"'.freeze
11
+ ESCAPED_QUOTE = '""'.freeze
12
+
13
+ # Quote the identifier
14
+ #
15
+ # @param [#to_s] identifier
16
+ #
17
+ # @return [#to_s]
18
+ #
19
+ # @api private
20
+ def visit_identifier(identifier)
21
+ "#{QUOTE}#{identifier.to_s.gsub(QUOTE, ESCAPED_QUOTE)}#{QUOTE}"
22
+ end
23
+
24
+ end # module Identifier
25
+ end # module Generator
26
+ end # module SQL
27
+ end # module Veritas