arel_extensions 1.3.9 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +2 -1
  3. data/.gitignore +6 -7
  4. data/.rubocop.yml +3 -67
  5. data/.travis/oracle/download.js +152 -0
  6. data/.travis/oracle/download.sh +30 -0
  7. data/.travis/oracle/download_ojdbc.js +116 -0
  8. data/.travis/oracle/install.sh +34 -0
  9. data/.travis/setup_accounts.sh +9 -0
  10. data/.travis/sqlite3/extension-functions.sh +6 -0
  11. data/.travis.yml +223 -0
  12. data/Gemfile +21 -16
  13. data/README.md +90 -282
  14. data/Rakefile +30 -48
  15. data/TODO +1 -0
  16. data/appveyor.yml +22 -60
  17. data/arel_extensions.gemspec +14 -13
  18. data/functions.html +3 -3
  19. data/gemfiles/rails3.gemfile +10 -10
  20. data/gemfiles/rails4.gemfile +29 -0
  21. data/gemfiles/rails5_0.gemfile +29 -0
  22. data/gemfiles/rails5_1_4.gemfile +14 -14
  23. data/gemfiles/rails5_2.gemfile +14 -16
  24. data/init/mssql.sql +4 -4
  25. data/init/mysql.sql +38 -38
  26. data/init/oracle.sql +0 -0
  27. data/init/postgresql.sql +21 -21
  28. data/init/sqlite.sql +0 -0
  29. data/lib/arel_extensions/attributes.rb +3 -4
  30. data/lib/arel_extensions/boolean_functions.rb +14 -53
  31. data/lib/arel_extensions/common_sql_functions.rb +17 -16
  32. data/lib/arel_extensions/comparators.rb +28 -27
  33. data/lib/arel_extensions/date_duration.rb +13 -17
  34. data/lib/arel_extensions/insert_manager.rb +15 -18
  35. data/lib/arel_extensions/math.rb +53 -55
  36. data/lib/arel_extensions/math_functions.rb +39 -46
  37. data/lib/arel_extensions/nodes/abs.rb +1 -0
  38. data/lib/arel_extensions/nodes/blank.rb +2 -1
  39. data/lib/arel_extensions/nodes/case.rb +19 -20
  40. data/lib/arel_extensions/nodes/cast.rb +8 -10
  41. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  42. data/lib/arel_extensions/nodes/coalesce.rb +4 -3
  43. data/lib/arel_extensions/nodes/collate.rb +10 -9
  44. data/lib/arel_extensions/nodes/concat.rb +18 -9
  45. data/lib/arel_extensions/nodes/date_diff.rb +26 -42
  46. data/lib/arel_extensions/nodes/duration.rb +3 -0
  47. data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
  48. data/lib/arel_extensions/nodes/floor.rb +1 -1
  49. data/lib/arel_extensions/nodes/format.rb +8 -35
  50. data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
  51. data/lib/arel_extensions/nodes/function.rb +37 -42
  52. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  53. data/lib/arel_extensions/nodes/json.rb +39 -52
  54. data/lib/arel_extensions/nodes/length.rb +0 -5
  55. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  56. data/lib/arel_extensions/nodes/locate.rb +2 -1
  57. data/lib/arel_extensions/nodes/log10.rb +2 -1
  58. data/lib/arel_extensions/nodes/matches.rb +7 -5
  59. data/lib/arel_extensions/nodes/md5.rb +1 -0
  60. data/lib/arel_extensions/nodes/power.rb +5 -5
  61. data/lib/arel_extensions/nodes/rand.rb +1 -0
  62. data/lib/arel_extensions/nodes/repeat.rb +5 -3
  63. data/lib/arel_extensions/nodes/replace.rb +8 -16
  64. data/lib/arel_extensions/nodes/round.rb +6 -5
  65. data/lib/arel_extensions/nodes/soundex.rb +15 -15
  66. data/lib/arel_extensions/nodes/std.rb +21 -18
  67. data/lib/arel_extensions/nodes/substring.rb +16 -8
  68. data/lib/arel_extensions/nodes/then.rb +1 -1
  69. data/lib/arel_extensions/nodes/trim.rb +6 -4
  70. data/lib/arel_extensions/nodes/union.rb +8 -5
  71. data/lib/arel_extensions/nodes/union_all.rb +7 -4
  72. data/lib/arel_extensions/nodes/wday.rb +4 -0
  73. data/lib/arel_extensions/nodes.rb +1 -1
  74. data/lib/arel_extensions/null_functions.rb +5 -19
  75. data/lib/arel_extensions/predications.rb +43 -44
  76. data/lib/arel_extensions/railtie.rb +5 -5
  77. data/lib/arel_extensions/set_functions.rb +7 -5
  78. data/lib/arel_extensions/string_functions.rb +29 -59
  79. data/lib/arel_extensions/tasks.rb +6 -6
  80. data/lib/arel_extensions/version.rb +1 -1
  81. data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
  82. data/lib/arel_extensions/visitors/mssql.rb +180 -375
  83. data/lib/arel_extensions/visitors/mysql.rb +212 -350
  84. data/lib/arel_extensions/visitors/oracle.rb +178 -220
  85. data/lib/arel_extensions/visitors/oracle12.rb +31 -18
  86. data/lib/arel_extensions/visitors/postgresql.rb +173 -256
  87. data/lib/arel_extensions/visitors/sqlite.rb +126 -140
  88. data/lib/arel_extensions/visitors/to_sql.rb +237 -298
  89. data/lib/arel_extensions/visitors.rb +58 -82
  90. data/lib/arel_extensions.rb +31 -202
  91. data/test/database.yml +7 -15
  92. data/test/helper.rb +18 -0
  93. data/test/real_db_test.rb +116 -105
  94. data/test/support/fake_record.rb +3 -3
  95. data/test/test_comparators.rb +17 -14
  96. data/test/visitors/test_bulk_insert_oracle.rb +11 -11
  97. data/test/visitors/test_bulk_insert_sqlite.rb +13 -12
  98. data/test/visitors/test_bulk_insert_to_sql.rb +13 -11
  99. data/test/visitors/test_oracle.rb +55 -55
  100. data/test/visitors/test_to_sql.rb +226 -419
  101. data/test/with_ar/all_agnostic_test.rb +365 -709
  102. data/test/with_ar/insert_agnostic_test.rb +21 -27
  103. data/test/with_ar/test_bulk_sqlite.rb +16 -17
  104. data/test/with_ar/test_math_sqlite.rb +26 -26
  105. data/test/with_ar/test_string_mysql.rb +33 -31
  106. data/test/with_ar/test_string_sqlite.rb +34 -30
  107. metadata +34 -37
  108. data/.github/workflows/publish.yml +0 -29
  109. data/.github/workflows/release.yml +0 -30
  110. data/.github/workflows/ruby.yml +0 -345
  111. data/NEWS.md +0 -62
  112. data/bin/build +0 -15
  113. data/bin/publish +0 -8
  114. data/dev/compose.yaml +0 -29
  115. data/gemfiles/rails4_2.gemfile +0 -38
  116. data/gemfiles/rails5.gemfile +0 -29
  117. data/gemfiles/rails6.gemfile +0 -30
  118. data/gemfiles/rails6_1.gemfile +0 -30
  119. data/gemfiles/rails7.gemfile +0 -23
  120. data/gemfiles/rails7_1.gemfile +0 -22
  121. data/gemspecs/arel_extensions-v1.gemspec +0 -27
  122. data/gemspecs/arel_extensions-v2.gemspec +0 -27
  123. data/generate_gems.sh +0 -15
  124. data/lib/arel_extensions/aliases.rb +0 -14
  125. data/lib/arel_extensions/helpers.rb +0 -57
  126. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
  127. data/lib/arel_extensions/nodes/formatted_date.rb +0 -42
  128. data/lib/arel_extensions/nodes/rollup.rb +0 -36
  129. data/lib/arel_extensions/nodes/select.rb +0 -10
  130. data/lib/arel_extensions/nodes/sum.rb +0 -7
  131. data/lib/arel_extensions/visitors/convert_format.rb +0 -37
  132. data/test/arelx_test_helper.rb +0 -67
  133. data/version_v1.rb +0 -3
  134. data/version_v2.rb +0 -3
@@ -1,22 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'rails', '~> 7.1'
4
-
5
- group :development, :test do
6
- gem 'activesupport', '~> 7.1'
7
- gem 'activemodel', '~> 7.1'
8
- gem 'activerecord', '~> 7.1'
9
-
10
- gem 'sqlite3', '~> 1.6', platforms: [:mri]
11
- gem 'mysql2', '~>0.5', platforms: [:mri]
12
- gem 'pg', '~> 1.5', platforms: [:mri]
13
-
14
- gem 'tiny_tds', platforms: %i[mri mingw x64_mingw mswin]
15
- gem 'activerecord-sqlserver-adapter', '~> 7.1.0.beta1', platforms: %i[mri mingw x64_mingw mswin]
16
- gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw]
17
-
18
- gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
19
- gem 'activerecord-oracle_enhanced-adapter', '~> 7.0.0' if ENV.has_key? 'ORACLE_HOME'
20
- end
21
-
22
- gemspec path: Dir.pwd
@@ -1,27 +0,0 @@
1
- $:.push File.expand_path('../lib', __FILE__)
2
- require 'arel_extensions/version'
3
-
4
- Gem::Specification.new do |s|
5
- s.name = 'arel_extensions'
6
- s.version = ArelExtensions::VERSION
7
- s.platform = Gem::Platform::RUBY
8
- s.authors = ['Yann Azoury', 'Félix Bellanger', 'Julien Delporte']
9
- s.email = ['yann.azoury@faveod.com', 'felix.bellanger@faveod.com', 'julien.delporte@faveod.com']
10
- s.homepage = 'https://github.com/Faveod/arel-extensions'
11
- s.description = 'Adds new features to Arel'
12
- s.summary = 'Extending Arel'
13
- s.license = 'MIT'
14
-
15
- s.rdoc_options = ['--main', 'README.md']
16
- s.extra_rdoc_files = ['MIT-LICENSE.txt', 'README.md', 'functions.html']
17
-
18
- # Manifest
19
- s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
- s.require_paths = ['lib']
22
-
23
- s.add_dependency('arel', '>= 6.0')
24
-
25
- s.add_development_dependency('minitest', '~> 5.9')
26
- s.add_development_dependency('rake', '~> 12.3.3')
27
- end
@@ -1,27 +0,0 @@
1
- $:.push File.expand_path('../lib', __FILE__)
2
- require 'arel_extensions/version'
3
-
4
- Gem::Specification.new do |s|
5
- s.name = 'arel_extensions'
6
- s.version = ArelExtensions::VERSION
7
- s.platform = Gem::Platform::RUBY
8
- s.authors = ['Yann Azoury', 'Félix Bellanger', 'Julien Delporte']
9
- s.email = ['yann.azoury@faveod.com', 'felix.bellanger@faveod.com', 'julien.delporte@faveod.com']
10
- s.homepage = 'https://github.com/Faveod/arel-extensions'
11
- s.description = 'Adds new features to Arel'
12
- s.summary = 'Extending Arel'
13
- s.license = 'MIT'
14
-
15
- s.rdoc_options = ['--main', 'README.md']
16
- s.extra_rdoc_files = ['MIT-LICENSE.txt', 'README.md', 'functions.html']
17
-
18
- # Manifest
19
- s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
- s.require_paths = ['lib']
22
-
23
- s.add_dependency('activerecord', '>= 6.0')
24
-
25
- s.add_development_dependency('minitest', '~> 5.9')
26
- s.add_development_dependency('rake', '~> 12.3.3')
27
- end
data/generate_gems.sh DELETED
@@ -1,15 +0,0 @@
1
-
2
- #gem uninstall arel_extensions
3
-
4
- # VERSION ~> 1
5
- cp ./version_v1.rb lib/arel_extensions/version.rb
6
- cp ./gemspecs/arel_extensions-v1.gemspec ./arel_extensions.gemspec
7
- gem build ./arel_extensions.gemspec
8
-
9
- # VERSION ~> 2
10
- cp ./version_v2.rb lib/arel_extensions/version.rb
11
- mv ./arel_extensions.gemspec ./arel_extensions.gemspec.bck
12
- cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
13
- gem build ./arel_extensions.gemspec
14
- cp ./version_v1.rb lib/arel_extensions/version.rb
15
- cp ./gemspecs/arel_extensions-v1.gemspec ./arel_extensions.gemspec
@@ -1,14 +0,0 @@
1
- module ArelExtensions
2
- module Aliases
3
-
4
- # Install an alias, if present.
5
- def xas other
6
- if other.present?
7
- Arel::Nodes::As.new(self, Arel.sql(other))
8
- else
9
- self
10
- end
11
- end
12
-
13
- end
14
- end
@@ -1,57 +0,0 @@
1
- module ArelExtensions
2
-
3
- #
4
- # column_of
5
- #
6
- # Before the creation of these methods, getting the column name was done
7
- # uniquely through the code found in `column_of_via_arel_table`.
8
- #
9
- # This turned out to be unreliable, most notably when using adapters that do
10
- # not come with activerecord standard batteries. SQL Server is the most
11
- # notorious example.
12
- #
13
- # Currently, we're using a needlessly complicated way to address this issue.
14
- # Different versions of activerecord are behaving differently; the public APIs
15
- # do not seem to come with any guarantees, so we need to be sure that we're
16
- # coveing all these cases.
17
-
18
- def self.column_of_via_arel_table(table_name, column_name)
19
- Arel::Table.engine.connection.schema_cache.columns_hash(table_name)[column_name]
20
- rescue NoMethodError
21
- nil
22
- rescue => e
23
- warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of_via_arel_table`\n#{e.class}")
24
- warn(e.backtrace)
25
- nil
26
- end
27
-
28
- def self.column_of(table_name, column_name)
29
- pool = ActiveRecord::Base.connection.pool
30
- use_arel_table = !ActiveRecord::Base.connected? || \
31
- (pool.respond_to?(:schema_cache) && pool.schema_cache.nil?)
32
-
33
- if use_arel_table
34
- column_of_via_arel_table(table_name, column_name)
35
- else
36
- if pool.respond_to?(:pool_config)
37
- if pool.pool_config.respond_to?(:schema_reflection) # activerecord >= 7.1
38
- pool.pool_config.schema_reflection.columns_hash(ActiveRecord::Base.connection, table_name)[column_name]
39
- else # activerecord < 7.1
40
- pool.pool_config.schema_cache.columns_hash(table_name)[column_name]
41
- end
42
- elsif pool.respond_to?(:schema_cache) # activerecord < 6.1
43
- pool.schema_cache.columns_hash(table_name)[column_name]
44
- else # activerecord < 5.0
45
- column_of_via_arel_table(table_name, column_name)
46
- end
47
- end
48
- rescue ActiveRecord::ConnectionNotEstablished
49
- column_of_via_arel_table(table_name, column_name)
50
- rescue ActiveRecord::StatementInvalid
51
- nil
52
- rescue => e
53
- warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of`\n#{e.class}")
54
- warn(e.backtrace)
55
- nil
56
- end
57
- end
@@ -1,13 +0,0 @@
1
- module ArelExtensions
2
- module Nodes
3
- class AggregateFunction < Function
4
- attr_accessor :order, :group
5
-
6
- def initialize node, **opts
7
- @order = Array(opts[:order]).map{|e| convert_to_node(e)}
8
- @group = Array(opts[:group]).map{|e| convert_to_node(e)}
9
- super [node]
10
- end
11
- end
12
- end
13
- end
@@ -1,42 +0,0 @@
1
- require 'strscan'
2
-
3
- module ArelExtensions
4
- module Nodes
5
- class FormattedDate < Function
6
- RETURN_TYPE = :string
7
-
8
- attr_accessor :col_type, :iso_format, :time_zone
9
-
10
- def initialize expr
11
- col = expr[0]
12
- @iso_format = convert_format(expr[1])
13
- @time_zone = expr[2]
14
- @col_type = type_of_attribute(col)
15
- super [col, convert_to_string_node(@iso_format)]
16
- end
17
-
18
- private
19
-
20
- # Address portability issues with some of the formats.
21
- def convert_format(fmt)
22
- s = StringScanner.new fmt
23
- res = StringIO.new
24
- while !s.eos?
25
- res <<
26
- case
27
- when s.scan(/%D/) then '%m/%d/%y'
28
- when s.scan(/%F/) then '%Y-%m-%d'
29
- when s.scan(/%R/) then '%H:%M'
30
- when s.scan(/%r/) then '%I:%M:%S %p'
31
- when s.scan(/%T/) then '%H:%M:%S'
32
- when s.scan(/%v/) then '%e-%b-%Y'
33
-
34
- when s.scan(/[^%]+/) then s.matched
35
- when s.scan(/./) then s.matched
36
- end
37
- end
38
- res.string
39
- end
40
- end
41
- end
42
- end
@@ -1,36 +0,0 @@
1
- # The following is a patch to activerecord when it doesn't
2
- # have RollUp defined, i.e. for rails < 5.2
3
-
4
- begin
5
- Arel::Nodes.const_get('RollUp')
6
- rescue NameError => e
7
- module Arel
8
- module Nodes
9
- class RollUp < Arel::Nodes::Unary
10
- end
11
- end
12
- end
13
-
14
- module Arel
15
- module Visitors
16
- class PostgreSQL
17
- # Utilized by GroupingSet, Cube & RollUp visitors to
18
- # handle grouping aggregation semantics
19
- def grouping_array_or_grouping_element(o, collector)
20
- if o.expr.is_a? Array
21
- collector << "( "
22
- visit o.expr, collector
23
- collector << " )"
24
- else
25
- visit o.expr, collector
26
- end
27
- end
28
-
29
- def visit_Arel_Nodes_RollUp(o, collector)
30
- collector << "ROLLUP"
31
- grouping_array_or_grouping_element o, collector
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,10 +0,0 @@
1
- module Arel
2
- module Nodes
3
- class SelectCore
4
- # havings did not exist in rails < 5.2
5
- if !method_defined?(:havings)
6
- alias :havings :having
7
- end
8
- end
9
- end
10
- end
@@ -1,7 +0,0 @@
1
- module ArelExtensions
2
- module Nodes
3
- class Sum < AggregateFunction
4
- RETURN_TYPE = :number
5
- end
6
- end
7
- end
@@ -1,37 +0,0 @@
1
- module ArelExtensions
2
- module Visitors
3
- # Convert date format in strftime syntax to whatever the RDBMs
4
- # wants, based on the table of conversion +mapping+.
5
- def self.strftime_to_format format, mapping
6
- @mapping_regexps ||= {}
7
- @mapping_regexps[mapping] ||=
8
- Regexp.new(
9
- mapping
10
- .keys
11
- .map{|k| Regexp.escape(k)}
12
- .join('|')
13
- )
14
-
15
- regexp = @mapping_regexps[mapping]
16
- s = StringScanner.new format
17
- res = StringIO.new
18
- while !s.eos?
19
- res <<
20
- case
21
- when s.scan(regexp)
22
- if v = mapping[s.matched]
23
- v
24
- else
25
- # Should never happen.
26
- s.matched
27
- end
28
- when s.scan(/[^%]+/)
29
- s.matched
30
- when s.scan(/./)
31
- s.matched
32
- end
33
- end
34
- res.string
35
- end
36
- end
37
- end
@@ -1,67 +0,0 @@
1
- require 'rubygems'
2
- require 'minitest/autorun'
3
- require 'fileutils'
4
- require 'arel'
5
- require 'active_record'
6
-
7
- require 'support/fake_record'
8
-
9
- def colored(color, msg)
10
- /^xterm|-256color$/.match?(ENV['TERM']) ? "\x1b[#{color}m#{msg}\x1b[89m\x1b[0m" : "#{msg}"
11
- end
12
-
13
- YELLOW = '33'
14
-
15
- # Load gems specific to databases
16
- # NOTE:
17
- # It's strongly advised to test each database on its own. Loading multiple
18
- # backend gems leads to undefined behavior according to tests; the backend
19
- # might not recognize the correct DB visitor and will fallback to `ToSQL`
20
- # and screw all tests.
21
- #
22
- # The issue also seems to be related to arel version: at some point, arel
23
- # dropped its wide support for DBs and kept Postgres, MySQL and SQLite.
24
- # Here, we're just trying to load the correct ones.
25
- db_and_gem =
26
- if RUBY_ENGINE == 'jruby'
27
- {
28
- 'oracle' => 'activerecord-oracle_enhanced-adapter',
29
- 'mssql' => 'activerecord-jdbcsqlserver-adapter'
30
- }
31
- else
32
- {
33
- 'oracle' => 'activerecord-oracle_enhanced-adapter',
34
- 'mssql' => 'activerecord-sqlserver-adapter'
35
- }
36
- end
37
-
38
- def load_lib(gem)
39
- if gem && (RUBY_ENGINE == 'jruby' || Arel::VERSION.to_i > 9)
40
- begin
41
- Gem::Specification.find_by_name(gem)
42
- require gem
43
- rescue Gem::MissingSpecError
44
- warn "Warning: failed to load gem #{gem}. Are you sure it's installed?"
45
- end
46
- end
47
- end
48
-
49
- load_lib(db_and_gem[ENV['DB']])
50
-
51
- require 'arel_extensions'
52
-
53
- $arel_silence_type_casting_deprecation = true
54
-
55
- module Minitest::Assertions
56
- #
57
- # Fails unless +expected and +actual are the same string, modulo extraneous spaces.
58
- #
59
- def assert_like(expected, actual, msg = nil)
60
- msg ||= "Expected #{expected.inspect} and #{actual.inspect} to be alike"
61
- assert_equal expected.gsub(/\s+/, ' ').strip, actual.gsub(/\s+/, ' ').strip
62
- end
63
- end
64
-
65
- module Minitest::Expectations
66
- infect_an_assertion :assert_like, :must_be_like
67
- end
data/version_v1.rb DELETED
@@ -1,3 +0,0 @@
1
- module ArelExtensions
2
- VERSION = '1.3.9'.freeze
3
- end
data/version_v2.rb DELETED
@@ -1,3 +0,0 @@
1
- module ArelExtensions
2
- VERSION = '2.1.9'.freeze
3
- end