arel_extensions 2.1.2 → 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -2
- data/.github/workflows/ruby.yml +43 -91
- data/.gitignore +7 -6
- data/.rubocop.yml +62 -1
- data/Gemfile +11 -11
- data/README.md +1 -1
- data/Rakefile +4 -4
- data/TODO +0 -1
- data/appveyor.yml +73 -0
- data/arel_extensions.gemspec +11 -11
- data/gemfiles/rails3.gemfile +10 -10
- data/gemfiles/rails4.gemfile +14 -14
- data/gemfiles/rails5_0.gemfile +13 -13
- data/gemfiles/rails5_1_4.gemfile +13 -13
- data/gemfiles/rails5_2.gemfile +15 -14
- data/gemfiles/rails6.gemfile +13 -12
- data/gemfiles/rails6_1.gemfile +13 -12
- data/gemfiles/rails7.gemfile +9 -8
- data/gemspecs/arel_extensions-v1.gemspec +12 -12
- data/gemspecs/arel_extensions-v2.gemspec +11 -11
- data/init/mssql.sql +0 -0
- data/init/mysql.sql +0 -0
- data/init/oracle.sql +0 -0
- data/init/postgresql.sql +0 -0
- data/init/sqlite.sql +0 -0
- data/lib/arel_extensions/attributes.rb +2 -2
- data/lib/arel_extensions/boolean_functions.rb +2 -4
- data/lib/arel_extensions/common_sql_functions.rb +12 -12
- data/lib/arel_extensions/comparators.rb +14 -14
- data/lib/arel_extensions/date_duration.rb +7 -7
- data/lib/arel_extensions/helpers.rb +19 -16
- data/lib/arel_extensions/insert_manager.rb +1 -1
- data/lib/arel_extensions/math.rb +44 -31
- data/lib/arel_extensions/math_functions.rb +18 -18
- data/lib/arel_extensions/nodes/abs.rb +0 -0
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -0
- data/lib/arel_extensions/nodes/blank.rb +1 -1
- data/lib/arel_extensions/nodes/case.rb +4 -6
- data/lib/arel_extensions/nodes/cast.rb +5 -5
- data/lib/arel_extensions/nodes/ceil.rb +0 -0
- data/lib/arel_extensions/nodes/change_case.rb +0 -0
- data/lib/arel_extensions/nodes/coalesce.rb +1 -1
- data/lib/arel_extensions/nodes/collate.rb +9 -9
- data/lib/arel_extensions/nodes/concat.rb +2 -2
- data/lib/arel_extensions/nodes/date_diff.rb +10 -10
- data/lib/arel_extensions/nodes/duration.rb +0 -0
- data/lib/arel_extensions/nodes/find_in_set.rb +0 -0
- data/lib/arel_extensions/nodes/floor.rb +0 -0
- data/lib/arel_extensions/nodes/format.rb +0 -0
- data/lib/arel_extensions/nodes/formatted_number.rb +2 -2
- data/lib/arel_extensions/nodes/function.rb +21 -21
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +7 -7
- data/lib/arel_extensions/nodes/length.rb +0 -0
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
- data/lib/arel_extensions/nodes/locate.rb +1 -1
- data/lib/arel_extensions/nodes/log10.rb +0 -0
- data/lib/arel_extensions/nodes/matches.rb +1 -1
- data/lib/arel_extensions/nodes/md5.rb +0 -0
- data/lib/arel_extensions/nodes/power.rb +0 -0
- data/lib/arel_extensions/nodes/rand.rb +0 -0
- data/lib/arel_extensions/nodes/repeat.rb +2 -2
- data/lib/arel_extensions/nodes/replace.rb +2 -2
- data/lib/arel_extensions/nodes/round.rb +0 -0
- data/lib/arel_extensions/nodes/soundex.rb +2 -2
- data/lib/arel_extensions/nodes/std.rb +0 -0
- data/lib/arel_extensions/nodes/substring.rb +1 -1
- data/lib/arel_extensions/nodes/sum.rb +0 -0
- data/lib/arel_extensions/nodes/then.rb +1 -1
- data/lib/arel_extensions/nodes/trim.rb +2 -2
- data/lib/arel_extensions/nodes/union.rb +4 -4
- data/lib/arel_extensions/nodes/union_all.rb +3 -3
- data/lib/arel_extensions/nodes/wday.rb +0 -0
- data/lib/arel_extensions/nodes.rb +0 -0
- data/lib/arel_extensions/null_functions.rb +0 -0
- data/lib/arel_extensions/predications.rb +10 -10
- data/lib/arel_extensions/railtie.rb +1 -1
- data/lib/arel_extensions/set_functions.rb +3 -3
- data/lib/arel_extensions/string_functions.rb +8 -8
- data/lib/arel_extensions/tasks.rb +2 -2
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/convert_format.rb +0 -0
- data/lib/arel_extensions/visitors/ibm_db.rb +20 -20
- data/lib/arel_extensions/visitors/mssql.rb +150 -130
- data/lib/arel_extensions/visitors/mysql.rb +147 -149
- data/lib/arel_extensions/visitors/oracle.rb +141 -135
- data/lib/arel_extensions/visitors/oracle12.rb +16 -16
- data/lib/arel_extensions/visitors/postgresql.rb +147 -139
- data/lib/arel_extensions/visitors/sqlite.rb +85 -87
- data/lib/arel_extensions/visitors/to_sql.rb +146 -148
- data/lib/arel_extensions/visitors.rb +7 -7
- data/lib/arel_extensions.rb +56 -32
- data/test/arelx_test_helper.rb +14 -13
- data/test/database.yml +5 -5
- data/test/real_db_test.rb +81 -81
- data/test/support/fake_record.rb +2 -2
- data/test/test_comparators.rb +5 -5
- data/test/visitors/test_bulk_insert_oracle.rb +5 -5
- data/test/visitors/test_bulk_insert_sqlite.rb +5 -5
- data/test/visitors/test_bulk_insert_to_sql.rb +5 -5
- data/test/visitors/test_oracle.rb +14 -14
- data/test/visitors/test_to_sql.rb +87 -87
- data/test/with_ar/all_agnostic_test.rb +411 -306
- data/test/with_ar/insert_agnostic_test.rb +19 -16
- data/test/with_ar/test_bulk_sqlite.rb +5 -5
- data/test/with_ar/test_math_sqlite.rb +12 -12
- data/test/with_ar/test_string_mysql.rb +20 -20
- data/test/with_ar/test_string_sqlite.rb +20 -20
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +3 -9
- data/.travis/oracle/download.js +0 -152
- data/.travis/oracle/download.sh +0 -30
- data/.travis/oracle/download_ojdbc.js +0 -116
- data/.travis/oracle/install.sh +0 -34
- data/.travis/setup_accounts.sh +0 -9
- data/.travis/sqlite3/extension-functions.sh +0 -6
- data/.travis.yml +0 -193
data/gemfiles/rails5_1_4.gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gem 'rails', '5.1.4'
|
4
4
|
gem 'arel', '~> 8'
|
@@ -8,23 +8,23 @@ group :development, :test do
|
|
8
8
|
gem 'activemodel', '5.1.4'
|
9
9
|
gem 'activerecord', '5.1.4'
|
10
10
|
|
11
|
-
gem
|
12
|
-
gem
|
13
|
-
gem
|
11
|
+
gem 'sqlite3', '<= 1.3.13', platforms: %i[mri mswin mingw]
|
12
|
+
gem 'mysql2', '0.4.10', platforms: %i[mri mswin mingw]
|
13
|
+
gem 'pg', '< 1.0.0', platforms: %i[mri mingw]
|
14
14
|
|
15
|
-
gem
|
16
|
-
# gem "activerecord-sqlserver-adapter", :
|
15
|
+
gem 'tiny_tds', platforms: %i[mri mingw] if RUBY_PLATFORM.match?(/windows/)
|
16
|
+
# gem "activerecord-sqlserver-adapter", platforms: [:mri, :mingw]
|
17
17
|
|
18
|
-
gem 'ruby-oci8', platforms: [
|
18
|
+
gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
|
19
19
|
gem 'activerecord-oracle_enhanced-adapter', '~> 1.8' if ENV.has_key? 'ORACLE_HOME'
|
20
20
|
|
21
21
|
# for JRuby
|
22
22
|
gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v51.0', platforms: :jruby
|
23
|
-
gem
|
24
|
-
gem
|
25
|
-
gem
|
26
|
-
gem
|
27
|
-
gem
|
23
|
+
gem 'jdbc-sqlite3', platforms: :jruby
|
24
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
|
25
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: :jruby
|
26
|
+
gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
|
27
|
+
gem 'activerecord-jdbcmssql-adapter', platforms: :jruby
|
28
28
|
end
|
29
29
|
|
30
|
-
gemspec path:
|
30
|
+
gemspec path: Dir.pwd
|
data/gemfiles/rails5_2.gemfile
CHANGED
@@ -1,31 +1,32 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gem 'rails', '~> 5.2.0'
|
4
4
|
gem 'arel', '~> 9'
|
5
5
|
|
6
6
|
group :development, :test do
|
7
|
-
gem 'bigdecimal', '1.3.5', :
|
7
|
+
gem 'bigdecimal', '1.3.5', platforms: %i[mri mingw x64_mingw mswin]
|
8
8
|
gem 'activesupport', '~> 5.2.0'
|
9
9
|
gem 'activemodel', '~> 5.2.0'
|
10
10
|
gem 'activerecord', '~> 5.2.0'
|
11
11
|
|
12
|
-
gem
|
13
|
-
gem
|
14
|
-
gem
|
12
|
+
gem 'sqlite3', '<= 1.3.13', platforms: [:mri]
|
13
|
+
gem 'mysql2', '0.4.10', platforms: [:mri]
|
14
|
+
gem 'pg', '< 1.0.0', platforms: [:mri]
|
15
15
|
|
16
|
-
gem
|
17
|
-
gem
|
16
|
+
gem 'tiny_tds', platforms: %i[mri mingw x64_mingw mswin]
|
17
|
+
gem 'activerecord-sqlserver-adapter', '~> 5.2', platforms: %i[mri mingw x64_mingw mswin]
|
18
|
+
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw]
|
18
19
|
|
19
|
-
gem 'ruby-oci8', platforms: [
|
20
|
+
gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
|
20
21
|
gem 'activerecord-oracle_enhanced-adapter', '~> 5.2.0' if ENV.has_key? 'ORACLE_HOME'
|
21
22
|
|
22
23
|
# for JRuby
|
23
24
|
gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v52.7', platforms: :jruby
|
24
|
-
gem
|
25
|
-
gem
|
26
|
-
gem
|
27
|
-
gem
|
28
|
-
gem
|
25
|
+
gem 'jdbc-sqlite3', platforms: :jruby
|
26
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
|
27
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: :jruby
|
28
|
+
gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
|
29
|
+
gem 'activerecord-jdbcsqlserver-adapter', '~> 52.0', platforms: :jruby
|
29
30
|
end
|
30
31
|
|
31
|
-
gemspec path:
|
32
|
+
gemspec path: Dir.pwd
|
data/gemfiles/rails6.gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gem 'rails', '~> 6.0.0'
|
4
4
|
|
@@ -8,22 +8,23 @@ group :development, :test do
|
|
8
8
|
gem 'activemodel', '~> 6.0.0'
|
9
9
|
gem 'activerecord', '~> 6.0.0'
|
10
10
|
|
11
|
-
gem
|
12
|
-
gem
|
13
|
-
gem
|
11
|
+
gem 'sqlite3', '~> 1.4', platforms: [:mri]
|
12
|
+
gem 'mysql2', '0.5.2', platforms: [:mri]
|
13
|
+
gem 'pg', '< 1.0.0', platforms: [:mri]
|
14
14
|
|
15
|
-
gem
|
16
|
-
gem
|
15
|
+
gem 'tiny_tds', platforms: %i[mri mingw x64_mingw mswin]
|
16
|
+
gem 'activerecord-sqlserver-adapter', '~> 6.0', platforms: %i[mri mingw x64_mingw mswin]
|
17
|
+
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw]
|
17
18
|
|
18
|
-
gem 'ruby-oci8', platforms: [
|
19
|
+
gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
|
19
20
|
gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0' if ENV.has_key? 'ORACLE_HOME'
|
20
21
|
|
21
22
|
# for JRuby
|
22
23
|
gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v60.4', platforms: :jruby
|
23
|
-
gem
|
24
|
-
gem
|
25
|
-
gem
|
26
|
-
gem
|
24
|
+
gem 'jdbc-sqlite3', platforms: :jruby
|
25
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
|
26
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: :jruby
|
27
|
+
gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
|
27
28
|
end
|
28
29
|
|
29
|
-
gemspec path:
|
30
|
+
gemspec path: Dir.pwd
|
data/gemfiles/rails6_1.gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gem 'rails', '~> 6.1.0'
|
4
4
|
|
@@ -8,22 +8,23 @@ group :development, :test do
|
|
8
8
|
gem 'activemodel', '~> 6.1.0'
|
9
9
|
gem 'activerecord', '~> 6.1.0'
|
10
10
|
|
11
|
-
gem
|
12
|
-
gem
|
13
|
-
gem
|
11
|
+
gem 'sqlite3', '~> 1.4', platforms: [:mri]
|
12
|
+
gem 'mysql2', '0.5.2', platforms: [:mri]
|
13
|
+
gem 'pg', '~> 1.1', platforms: [:mri]
|
14
14
|
|
15
|
-
gem
|
16
|
-
gem
|
15
|
+
gem 'tiny_tds', platforms: %i[mri mingw x64_mingw mswin]
|
16
|
+
gem 'activerecord-sqlserver-adapter', '~> 6.1.0', platforms: %i[mri mingw x64_mingw mswin]
|
17
|
+
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw]
|
17
18
|
|
18
|
-
gem 'ruby-oci8', platforms: [
|
19
|
+
gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
|
19
20
|
gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0' if ENV.has_key? 'ORACLE_HOME'
|
20
21
|
|
21
22
|
# for JRuby
|
22
23
|
gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v61.1', platforms: :jruby
|
23
|
-
gem
|
24
|
-
gem
|
25
|
-
gem
|
26
|
-
gem
|
24
|
+
gem 'jdbc-sqlite3', platforms: :jruby
|
25
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
|
26
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: :jruby
|
27
|
+
gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
|
27
28
|
end
|
28
29
|
|
29
|
-
gemspec path:
|
30
|
+
gemspec path: Dir.pwd
|
data/gemfiles/rails7.gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gem 'rails', '~> 7.0.1'
|
4
4
|
|
@@ -8,15 +8,16 @@ group :development, :test do
|
|
8
8
|
gem 'activemodel', '~> 7.0.1'
|
9
9
|
gem 'activerecord', '~> 7.0.1'
|
10
10
|
|
11
|
-
gem
|
12
|
-
gem
|
13
|
-
gem
|
11
|
+
gem 'sqlite3', '~> 1.4', platforms: [:mri]
|
12
|
+
gem 'mysql2', '0.5.2', platforms: [:mri]
|
13
|
+
gem 'pg', '~> 1.1', platforms: [:mri]
|
14
14
|
|
15
|
-
gem
|
16
|
-
gem
|
15
|
+
gem 'tiny_tds', platforms: %i[mri mingw x64_mingw mswin]
|
16
|
+
gem 'activerecord-sqlserver-adapter', '~> 7.0.0.0', platforms: %i[mri mingw x64_mingw mswin]
|
17
|
+
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw]
|
17
18
|
|
18
|
-
gem 'ruby-oci8', platforms: [
|
19
|
+
gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
|
19
20
|
gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0' if ENV.has_key? 'ORACLE_HOME'
|
20
21
|
end
|
21
22
|
|
22
|
-
gemspec path:
|
23
|
+
gemspec path: Dir.pwd
|
@@ -1,28 +1,28 @@
|
|
1
|
-
$:.push File.expand_path(
|
2
|
-
require
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'arel_extensions/version'
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name =
|
5
|
+
s.name = 'arel_extensions'
|
6
6
|
s.version = ArelExtensions::VERSION
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.authors = [
|
9
|
-
s.email = [
|
10
|
-
s.homepage =
|
11
|
-
s.description =
|
12
|
-
s.summary =
|
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
13
|
s.license = 'MIT'
|
14
14
|
|
15
|
-
s.rdoc_options = [
|
16
|
-
s.extra_rdoc_files = [
|
15
|
+
s.rdoc_options = ['--main', 'README.md']
|
16
|
+
s.extra_rdoc_files = ['MIT-LICENSE.txt', 'README.md', 'functions.html']
|
17
17
|
|
18
18
|
# Manifest
|
19
19
|
s.files = `git ls-files`.split("\n")
|
20
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
-
s.require_paths = [
|
21
|
+
s.require_paths = ['lib']
|
22
22
|
|
23
23
|
s.add_dependency('arel', '>= 6.0')
|
24
24
|
|
25
25
|
s.add_development_dependency('minitest', '~> 5.9')
|
26
26
|
s.add_development_dependency('rdoc', '>= 6.3.1')
|
27
27
|
s.add_development_dependency('rake', '~> 12.3.3')
|
28
|
-
end
|
28
|
+
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
$:.push File.expand_path(
|
2
|
-
require
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'arel_extensions/version'
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name =
|
5
|
+
s.name = 'arel_extensions'
|
6
6
|
s.version = ArelExtensions::VERSION
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.authors = [
|
9
|
-
s.email = [
|
10
|
-
s.homepage =
|
11
|
-
s.description =
|
12
|
-
s.summary =
|
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
13
|
s.license = 'MIT'
|
14
14
|
|
15
|
-
s.rdoc_options = [
|
16
|
-
s.extra_rdoc_files = [
|
15
|
+
s.rdoc_options = ['--main', 'README.md']
|
16
|
+
s.extra_rdoc_files = ['MIT-LICENSE.txt', 'README.md', 'functions.html']
|
17
17
|
|
18
18
|
# Manifest
|
19
19
|
s.files = `git ls-files`.split("\n")
|
20
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
-
s.require_paths = [
|
21
|
+
s.require_paths = ['lib']
|
22
22
|
|
23
23
|
s.add_dependency('activerecord', '>= 6.0')
|
24
24
|
|
data/init/mssql.sql
CHANGED
File without changes
|
data/init/mysql.sql
CHANGED
File without changes
|
data/init/oracle.sql
CHANGED
File without changes
|
data/init/postgresql.sql
CHANGED
File without changes
|
data/init/sqlite.sql
CHANGED
File without changes
|
@@ -19,11 +19,11 @@ module ArelExtensions
|
|
19
19
|
include ArelExtensions::Predications
|
20
20
|
|
21
21
|
def ==(other)
|
22
|
-
Arel::Nodes::Equality.new self, Arel
|
22
|
+
Arel::Nodes::Equality.new self, Arel.quoted(other, self)
|
23
23
|
end
|
24
24
|
|
25
25
|
def !=(other)
|
26
|
-
Arel::Nodes::NotEqual.new self, Arel
|
26
|
+
Arel::Nodes::NotEqual.new self, Arel.quoted(other, self)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
require 'arel_extensions/nodes/then'
|
4
2
|
|
5
3
|
module ArelExtensions
|
@@ -32,7 +30,7 @@ class Arel::Nodes::And
|
|
32
30
|
def self.new *children
|
33
31
|
children =
|
34
32
|
children.flatten.map { |c|
|
35
|
-
|
33
|
+
c.is_a?(self) ? c.children : c
|
36
34
|
}.flatten
|
37
35
|
super(children)
|
38
36
|
end
|
@@ -52,7 +50,7 @@ class Arel::Nodes::Or
|
|
52
50
|
def self.new *children
|
53
51
|
children =
|
54
52
|
children.flatten.map { |c|
|
55
|
-
|
53
|
+
c.is_a?(self) ? c.children : c
|
56
54
|
}.flatten
|
57
55
|
super(*children)
|
58
56
|
end
|
@@ -6,8 +6,8 @@ module ArelExtensions
|
|
6
6
|
begin
|
7
7
|
db = cnx.raw_connection
|
8
8
|
db.enable_load_extension(1)
|
9
|
-
db.load_extension(
|
10
|
-
db.load_extension(
|
9
|
+
db.load_extension('/usr/lib/sqlite3/pcre.so')
|
10
|
+
db.load_extension('/usr/lib/sqlite3/extension-functions.so')
|
11
11
|
db.enable_load_extension(0)
|
12
12
|
rescue => e
|
13
13
|
$load_extension_disabled = true
|
@@ -18,28 +18,28 @@ module ArelExtensions
|
|
18
18
|
|
19
19
|
def add_sqlite_functions
|
20
20
|
db = @cnx.raw_connection
|
21
|
-
db.create_function(
|
21
|
+
db.create_function('find_in_set', 1) do |func, val, list|
|
22
22
|
case list
|
23
23
|
when String
|
24
24
|
i = list.split(',').index(val.to_s)
|
25
|
-
func.result = i ? (i+1) : 0
|
25
|
+
func.result = i ? (i + 1) : 0
|
26
26
|
when NilClass
|
27
27
|
func.result = nil
|
28
28
|
else
|
29
29
|
i = list.to_s.split(',').index(val.to_s)
|
30
|
-
func.result = i ? (i+1) : 0
|
30
|
+
func.result = i ? (i + 1) : 0
|
31
31
|
end
|
32
32
|
end
|
33
|
-
db.create_function(
|
33
|
+
db.create_function('instr', 1) do |func, value1, value2|
|
34
34
|
i = value1.to_s.index(value2.to_s)
|
35
|
-
func.result = i ? (i+1) : 0
|
36
|
-
end rescue
|
35
|
+
func.result = i ? (i + 1) : 0
|
36
|
+
end rescue 'function instr already here (>= 3.8.5)'
|
37
37
|
end
|
38
38
|
|
39
39
|
def add_sql_functions(env_db = nil)
|
40
40
|
env_db ||= @cnx.adapter_name
|
41
|
-
env_db = 'mysql' if
|
42
|
-
if
|
41
|
+
env_db = 'mysql' if /mysql/i.match?(env_db)
|
42
|
+
if /sqlite/i.match?(env_db)
|
43
43
|
begin
|
44
44
|
add_sqlite_functions
|
45
45
|
rescue => e
|
@@ -52,8 +52,8 @@ module ArelExtensions
|
|
52
52
|
sql.split(/^GO\s*$/).each {|str|
|
53
53
|
@cnx.execute(str.strip) unless str.blank?
|
54
54
|
}
|
55
|
-
elsif env_db =='mysql'
|
56
|
-
sql.split(
|
55
|
+
elsif env_db == 'mysql'
|
56
|
+
sql.split('$$')[1..-2].each { |str|
|
57
57
|
@cnx.execute(str.strip) unless str.strip.blank?
|
58
58
|
}
|
59
59
|
else
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Comparators
|
3
3
|
def >(other)
|
4
|
-
Arel::Nodes::GreaterThan.new self, Arel
|
4
|
+
Arel::Nodes::GreaterThan.new self, Arel.quoted(other, self)
|
5
5
|
end
|
6
6
|
|
7
7
|
def >=(other)
|
8
|
-
Arel::Nodes::GreaterThanOrEqual.new self, Arel
|
8
|
+
Arel::Nodes::GreaterThanOrEqual.new self, Arel.quoted(other, self)
|
9
9
|
end
|
10
10
|
|
11
11
|
def <(other)
|
12
|
-
Arel::Nodes::LessThan.new self, Arel
|
12
|
+
Arel::Nodes::LessThan.new self, Arel.quoted(other, self)
|
13
13
|
end
|
14
14
|
|
15
15
|
def <=(other)
|
16
|
-
Arel::Nodes::LessThanOrEqual.new self, Arel
|
16
|
+
Arel::Nodes::LessThanOrEqual.new self, Arel.quoted(other, self)
|
17
17
|
end
|
18
18
|
|
19
19
|
# REGEXP function
|
@@ -21,7 +21,7 @@ module ArelExtensions
|
|
21
21
|
def =~(other)
|
22
22
|
# arg = self.relation.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s].type
|
23
23
|
# if arg == :string || arg == :text
|
24
|
-
|
24
|
+
Arel::Nodes::Regexp.new self, convert_regexp(other)
|
25
25
|
# end
|
26
26
|
end
|
27
27
|
|
@@ -30,7 +30,7 @@ module ArelExtensions
|
|
30
30
|
def !~(other)
|
31
31
|
# arg = self.relation.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s].type
|
32
32
|
# if arg == :string || arg == :text
|
33
|
-
|
33
|
+
Arel::Nodes::NotRegexp.new self, convert_regexp(other)
|
34
34
|
# end
|
35
35
|
end
|
36
36
|
|
@@ -42,17 +42,17 @@ module ArelExtensions
|
|
42
42
|
when String
|
43
43
|
# Do nothing.
|
44
44
|
when Regexp
|
45
|
-
other = other.source.gsub('\A','^')
|
46
|
-
other.gsub!('\z','$')
|
47
|
-
other.gsub!('\Z','$')
|
48
|
-
other.gsub!('\d','[0-9]')
|
49
|
-
other.gsub!('\D','[^0-9]')
|
50
|
-
other.gsub!('\w','[0-9A-Za-z]')
|
51
|
-
other.gsub!('\W','[^A-Za-z0-9_]')
|
45
|
+
other = other.source.gsub('\A', '^')
|
46
|
+
other.gsub!('\z', '$')
|
47
|
+
other.gsub!('\Z', '$')
|
48
|
+
other.gsub!('\d', '[0-9]')
|
49
|
+
other.gsub!('\D', '[^0-9]')
|
50
|
+
other.gsub!('\w', '[0-9A-Za-z]')
|
51
|
+
other.gsub!('\W', '[^A-Za-z0-9_]')
|
52
52
|
else
|
53
53
|
raise(ArgumentError)
|
54
54
|
end
|
55
|
-
Arel
|
55
|
+
Arel.quoted(other, self)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -6,22 +6,22 @@ module ArelExtensions
|
|
6
6
|
module DateDuration
|
7
7
|
# function returns the year (as a number) given a date value.
|
8
8
|
def year
|
9
|
-
ArelExtensions::Nodes::Duration.new
|
9
|
+
ArelExtensions::Nodes::Duration.new 'y', self
|
10
10
|
end
|
11
11
|
|
12
12
|
# function returns the month (as a number) given a date value.
|
13
13
|
def month
|
14
|
-
ArelExtensions::Nodes::Duration.new
|
14
|
+
ArelExtensions::Nodes::Duration.new 'm', self
|
15
15
|
end
|
16
16
|
|
17
17
|
# function returns the week (as a number) given a date value.
|
18
18
|
def week
|
19
|
-
ArelExtensions::Nodes::Duration.new
|
19
|
+
ArelExtensions::Nodes::Duration.new 'w', self
|
20
20
|
end
|
21
21
|
|
22
22
|
# function returns the month (as a number) given a date value.
|
23
23
|
def day
|
24
|
-
ArelExtensions::Nodes::Duration.new
|
24
|
+
ArelExtensions::Nodes::Duration.new 'd', self
|
25
25
|
end
|
26
26
|
|
27
27
|
def wday
|
@@ -29,15 +29,15 @@ module ArelExtensions
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def hour
|
32
|
-
ArelExtensions::Nodes::Duration.new
|
32
|
+
ArelExtensions::Nodes::Duration.new 'h', self
|
33
33
|
end
|
34
34
|
|
35
35
|
def minute
|
36
|
-
ArelExtensions::Nodes::Duration.new
|
36
|
+
ArelExtensions::Nodes::Duration.new 'mn', self
|
37
37
|
end
|
38
38
|
|
39
39
|
def second
|
40
|
-
ArelExtensions::Nodes::Duration.new
|
40
|
+
ArelExtensions::Nodes::Duration.new 's', self
|
41
41
|
end
|
42
42
|
|
43
43
|
def format(tpl, time_zone = nil)
|
@@ -16,33 +16,36 @@ module ArelExtensions
|
|
16
16
|
# coveing all these cases.
|
17
17
|
|
18
18
|
def self.column_of_via_arel_table(table_name, column_name)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
puts "This should never be reached."
|
26
|
-
puts "#{e.class}: #{e}"
|
27
|
-
nil
|
28
|
-
end
|
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}: #{e}")
|
24
|
+
nil
|
29
25
|
end
|
30
26
|
|
31
27
|
def self.column_of(table_name, column_name)
|
28
|
+
pool = ActiveRecord::Base.connection.pool
|
32
29
|
use_arel_table = !ActiveRecord::Base.connected? || \
|
33
|
-
(
|
30
|
+
(pool.respond_to?(:schema_cache) && pool.schema_cache.nil?)
|
34
31
|
|
35
32
|
if use_arel_table
|
36
33
|
column_of_via_arel_table(table_name, column_name)
|
37
34
|
else
|
38
|
-
if
|
39
|
-
|
40
|
-
elsif
|
41
|
-
|
35
|
+
if pool.respond_to?(:pool_config)
|
36
|
+
pool.pool_config.schema_cache.columns_hash(table_name)[column_name]
|
37
|
+
elsif pool.respond_to?(:schema_cache)
|
38
|
+
pool.schema_cache.columns_hash(table_name)[column_name]
|
42
39
|
else
|
43
|
-
puts ">>> We really shouldn't be here #{table_name}.#{column_name}"
|
44
40
|
column_of_via_arel_table(table_name, column_name)
|
45
41
|
end
|
46
42
|
end
|
43
|
+
rescue ActiveRecord::ConnectionNotEstablished
|
44
|
+
column_of_via_arel_table(table_name, column_name)
|
45
|
+
rescue ActiveRecord::StatementInvalid
|
46
|
+
nil
|
47
|
+
rescue => e
|
48
|
+
warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of`\n#{e.class}: #{e}")
|
49
|
+
nil
|
47
50
|
end
|
48
51
|
end
|