arel_extensions 1.5.3 → 2.0.0.rc3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -1
- data/.gitignore +6 -7
- data/.rubocop.yml +3 -67
- data/.travis/oracle/download.js +152 -0
- data/.travis/oracle/download.sh +30 -0
- data/.travis/oracle/download_ojdbc.js +116 -0
- data/.travis/oracle/install.sh +34 -0
- data/.travis/setup_accounts.sh +9 -0
- data/.travis/sqlite3/extension-functions.sh +6 -0
- data/.travis.yml +223 -0
- data/Gemfile +28 -2
- data/README.md +90 -239
- data/Rakefile +30 -48
- data/TODO +1 -0
- data/appveyor.yml +22 -60
- data/arel_extensions.gemspec +14 -13
- data/functions.html +3 -3
- data/gemfiles/rails3.gemfile +10 -10
- data/gemfiles/rails4.gemfile +29 -0
- data/gemfiles/rails5_0.gemfile +29 -0
- data/gemfiles/rails5_1_4.gemfile +14 -14
- data/gemfiles/rails5_2.gemfile +14 -16
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/oracle.sql +0 -0
- data/init/postgresql.sql +25 -24
- data/init/sqlite.sql +0 -0
- data/lib/arel_extensions/attributes.rb +3 -7
- data/lib/arel_extensions/boolean_functions.rb +14 -53
- data/lib/arel_extensions/common_sql_functions.rb +17 -16
- data/lib/arel_extensions/comparators.rb +28 -29
- data/lib/arel_extensions/date_duration.rb +13 -17
- data/lib/arel_extensions/insert_manager.rb +15 -18
- data/lib/arel_extensions/math.rb +53 -55
- data/lib/arel_extensions/math_functions.rb +39 -46
- data/lib/arel_extensions/nodes/abs.rb +1 -0
- data/lib/arel_extensions/nodes/blank.rb +2 -1
- data/lib/arel_extensions/nodes/case.rb +19 -20
- data/lib/arel_extensions/nodes/cast.rb +8 -10
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/coalesce.rb +4 -3
- data/lib/arel_extensions/nodes/collate.rb +10 -9
- data/lib/arel_extensions/nodes/concat.rb +18 -9
- data/lib/arel_extensions/nodes/date_diff.rb +26 -42
- data/lib/arel_extensions/nodes/duration.rb +3 -0
- data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
- data/lib/arel_extensions/nodes/floor.rb +1 -1
- data/lib/arel_extensions/nodes/format.rb +8 -35
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
- data/lib/arel_extensions/nodes/function.rb +37 -48
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +39 -52
- data/lib/arel_extensions/nodes/length.rb +0 -5
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
- data/lib/arel_extensions/nodes/locate.rb +2 -1
- data/lib/arel_extensions/nodes/log10.rb +2 -1
- data/lib/arel_extensions/nodes/matches.rb +7 -5
- data/lib/arel_extensions/nodes/md5.rb +1 -0
- data/lib/arel_extensions/nodes/power.rb +5 -5
- data/lib/arel_extensions/nodes/rand.rb +1 -0
- data/lib/arel_extensions/nodes/repeat.rb +5 -3
- data/lib/arel_extensions/nodes/replace.rb +8 -16
- data/lib/arel_extensions/nodes/round.rb +6 -5
- data/lib/arel_extensions/nodes/soundex.rb +15 -15
- data/lib/arel_extensions/nodes/std.rb +21 -18
- data/lib/arel_extensions/nodes/substring.rb +16 -8
- data/lib/arel_extensions/nodes/then.rb +1 -1
- data/lib/arel_extensions/nodes/trim.rb +6 -4
- data/lib/arel_extensions/nodes/union.rb +8 -5
- data/lib/arel_extensions/nodes/union_all.rb +7 -4
- data/lib/arel_extensions/nodes/wday.rb +4 -0
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/null_functions.rb +5 -19
- data/lib/arel_extensions/predications.rb +43 -44
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +7 -5
- data/lib/arel_extensions/string_functions.rb +36 -82
- data/lib/arel_extensions/tasks.rb +6 -6
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
- data/lib/arel_extensions/visitors/mssql.rb +192 -423
- data/lib/arel_extensions/visitors/mysql.rb +212 -354
- data/lib/arel_extensions/visitors/oracle.rb +178 -221
- data/lib/arel_extensions/visitors/oracle12.rb +31 -18
- data/lib/arel_extensions/visitors/postgresql.rb +173 -257
- data/lib/arel_extensions/visitors/sqlite.rb +126 -140
- data/lib/arel_extensions/visitors/to_sql.rb +237 -299
- data/lib/arel_extensions/visitors.rb +62 -83
- data/lib/arel_extensions.rb +31 -226
- data/test/database.yml +7 -15
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +117 -120
- data/test/support/fake_record.rb +3 -9
- data/test/test_comparators.rb +17 -14
- data/test/visitors/test_bulk_insert_oracle.rb +11 -11
- data/test/visitors/test_bulk_insert_sqlite.rb +13 -12
- data/test/visitors/test_bulk_insert_to_sql.rb +13 -11
- data/test/visitors/test_oracle.rb +55 -55
- data/test/visitors/test_to_sql.rb +226 -419
- data/test/with_ar/all_agnostic_test.rb +366 -721
- data/test/with_ar/insert_agnostic_test.rb +21 -27
- data/test/with_ar/test_bulk_sqlite.rb +16 -17
- data/test/with_ar/test_math_sqlite.rb +26 -26
- data/test/with_ar/test_string_mysql.rb +33 -31
- data/test/with_ar/test_string_sqlite.rb +34 -30
- metadata +37 -47
- data/.github/workflows/publish.yml +0 -30
- data/.github/workflows/release.yml +0 -30
- data/.github/workflows/ruby.yml +0 -403
- data/CONTRIBUTING.md +0 -102
- data/NEWS.md +0 -109
- data/bin/build +0 -15
- data/bin/compose +0 -6
- data/bin/publish +0 -8
- data/dev/arelx.dockerfile +0 -44
- data/dev/compose.yaml +0 -71
- data/dev/postgres.dockerfile +0 -5
- data/dev/rbenv +0 -189
- data/gemfiles/rails4_2.gemfile +0 -38
- data/gemfiles/rails5.gemfile +0 -29
- data/gemfiles/rails6.gemfile +0 -34
- data/gemfiles/rails6_1.gemfile +0 -42
- data/gemfiles/rails7.gemfile +0 -42
- data/gemfiles/rails7_1.gemfile +0 -41
- data/gemfiles/rails7_2.gemfile +0 -41
- data/gemspecs/arel_extensions-v1.gemspec +0 -27
- data/gemspecs/arel_extensions-v2.gemspec +0 -27
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/aliases.rb +0 -14
- data/lib/arel_extensions/helpers.rb +0 -62
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- data/lib/arel_extensions/nodes/formatted_date.rb +0 -42
- data/lib/arel_extensions/nodes/rollup.rb +0 -36
- data/lib/arel_extensions/nodes/select.rb +0 -10
- data/lib/arel_extensions/nodes/sum.rb +0 -7
- data/lib/arel_extensions/visitors/convert_format.rb +0 -37
- data/lib/arel_extensions/warning.rb +0 -42
- data/test/arelx_test_helper.rb +0 -92
- data/version_v1.rb +0 -3
- data/version_v2.rb +0 -3
|
@@ -1,102 +1,81 @@
|
|
|
1
|
-
# MSSQL visitors for java and rails ≥ 7 are painful to work with:
|
|
2
|
-
# requiring the exact path to the visitor is needed even if the
|
|
3
|
-
# AR adapter was loaded. It's also needed exactly here because:
|
|
4
|
-
# 1. putting it inside the visitor or anywhere else will not
|
|
5
|
-
# guarantee its actual loading.
|
|
6
|
-
# 2. it needs to load before arel_extensions/visitors.
|
|
7
|
-
if RUBY_PLATFORM == 'java' \
|
|
8
|
-
&& RUBY_ENGINE == 'jruby' \
|
|
9
|
-
&& (version = JRUBY_VERSION.split('.').map(&:to_i)) && version[0] == 9 && version[1] >= 4 \
|
|
10
|
-
&& Gem::Specification.find { |g| g.name == 'jdbc-mssql' }
|
|
11
|
-
begin
|
|
12
|
-
require 'arel/visitors/sqlserver'
|
|
13
|
-
rescue LoadError
|
|
14
|
-
warn 'arel/visitors/sqlserver not found: MSSQL might not work correctly.'
|
|
15
|
-
end
|
|
16
|
-
elsif RUBY_PLATFORM != 'java' \
|
|
17
|
-
&& Arel::VERSION.to_i < 10 \
|
|
18
|
-
&& Gem::Specification.find { |g| g.name == 'activerecord-sqlserver-adapter' }
|
|
19
|
-
begin
|
|
20
|
-
require 'arel_sqlserver'
|
|
21
|
-
rescue LoadError
|
|
22
|
-
warn 'arel_sqlserver not found: SQLServer Visitor might not work correctly.'
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
require 'arel_extensions/visitors/convert_format'
|
|
27
1
|
require 'arel_extensions/visitors/to_sql'
|
|
28
2
|
require 'arel_extensions/visitors/mysql'
|
|
29
|
-
require 'arel_extensions/visitors/
|
|
3
|
+
require 'arel_extensions/visitors/oracle'
|
|
4
|
+
require 'arel_extensions/visitors/oracle12'
|
|
30
5
|
require 'arel_extensions/visitors/postgresql'
|
|
31
6
|
require 'arel_extensions/visitors/sqlite'
|
|
7
|
+
require 'arel_extensions/visitors/mssql'
|
|
32
8
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
require 'arel_extensions/visitors/oracle12'
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
if defined?(Arel::Visitors::SQLServer)
|
|
39
|
-
class Arel::Visitors::SQLServer
|
|
40
|
-
include ArelExtensions::Visitors::MSSQL
|
|
41
|
-
end
|
|
42
|
-
end
|
|
9
|
+
Arel::Visitors::MSSQL.class_eval do
|
|
10
|
+
include ArelExtensions::Visitors::MSSQL
|
|
43
11
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
12
|
+
alias_method :old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As
|
|
13
|
+
def visit_Arel_Nodes_As o, collector
|
|
14
|
+
if o.left.is_a?(Arel::Nodes::Binary)
|
|
15
|
+
collector << '('
|
|
16
|
+
collector = visit o.left, collector
|
|
17
|
+
collector << ')'
|
|
18
|
+
else
|
|
19
|
+
collector = visit o.left, collector
|
|
48
20
|
end
|
|
21
|
+
collector << " AS ["
|
|
22
|
+
collector = visit o.right, collector
|
|
23
|
+
collector << "]"
|
|
24
|
+
collector
|
|
49
25
|
end
|
|
50
|
-
end
|
|
51
26
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def visit_Arel_Nodes_SelectStatement o, collector
|
|
58
|
-
if !collector.value.blank? && o.limit.blank? && o.offset.blank?
|
|
59
|
-
o = o.dup
|
|
60
|
-
o.orders = []
|
|
61
|
-
end
|
|
62
|
-
old_visit_Arel_Nodes_SelectStatement(o, collector)
|
|
27
|
+
alias_method :old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement
|
|
28
|
+
def visit_Arel_Nodes_SelectStatement o, collector
|
|
29
|
+
if !collector.value.blank? && o.limit.blank? && o.offset.blank?
|
|
30
|
+
o = o.dup
|
|
31
|
+
o.orders = []
|
|
63
32
|
end
|
|
33
|
+
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
|
64
34
|
end
|
|
65
35
|
end
|
|
66
36
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
37
|
+
begin
|
|
38
|
+
require 'arel_sqlserver'
|
|
39
|
+
if Arel::VERSION.to_i == 6
|
|
40
|
+
if Arel::Visitors::VISITORS['sqlserver'] && Arel::Visitors::VISITORS['sqlserver'] != Arel::Visitors::MSSQL
|
|
41
|
+
Arel::Visitors::VISITORS['sqlserver'].class_eval do
|
|
42
|
+
include ArelExtensions::Visitors::MSSQL
|
|
70
43
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
# The error could be seen by:
|
|
80
|
-
#
|
|
81
|
-
# 1. placing the visit_ inside the visitor, or placing it in a module
|
|
82
|
-
# then including it here.
|
|
83
|
-
# 2. replacing the `rescue nil` from aliasing trick, and printing the
|
|
84
|
-
# error.
|
|
85
|
-
#
|
|
86
|
-
# It complains that the visit_ does not exist in the module, as if it's
|
|
87
|
-
# evaluating the module eagerly, instead of lazily like in other versions
|
|
88
|
-
# of ruby.
|
|
89
|
-
#
|
|
90
|
-
# It might be something different, but this is the first thing we should
|
|
91
|
-
# investigate.
|
|
44
|
+
alias_method :old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement
|
|
45
|
+
def visit_Arel_Nodes_SelectStatement o, collector
|
|
46
|
+
if !collector.value.blank? && o.limit.blank? && o.offset.blank?
|
|
47
|
+
o = o.dup
|
|
48
|
+
o.orders = []
|
|
49
|
+
end
|
|
50
|
+
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
|
51
|
+
end
|
|
92
52
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
53
|
+
alias_method :old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As
|
|
54
|
+
def visit_Arel_Nodes_As o, collector
|
|
55
|
+
if o.left.is_a?(Arel::Nodes::Binary)
|
|
56
|
+
collector << '('
|
|
57
|
+
collector = visit o.left, collector
|
|
58
|
+
collector << ')'
|
|
59
|
+
else
|
|
60
|
+
collector = visit o.left, collector
|
|
61
|
+
end
|
|
62
|
+
collector << " AS ["
|
|
63
|
+
collector = visit o.right, collector
|
|
64
|
+
collector << "]"
|
|
65
|
+
collector
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
alias_method :old_primary_Key_From_Table, :primary_Key_From_Table
|
|
69
|
+
def primary_Key_From_Table t
|
|
70
|
+
return unless t
|
|
71
|
+
column_name = @connection.schema_cache.primary_keys(t.name) ||
|
|
72
|
+
@connection.schema_cache.columns_hash(t.name).first.try(:second).try(:name)
|
|
73
|
+
column_name ? t[column_name] : nil
|
|
74
|
+
end
|
|
98
75
|
end
|
|
99
|
-
old_visit_Arel_Nodes_SelectStatement(o, collector)
|
|
100
76
|
end
|
|
101
77
|
end
|
|
78
|
+
rescue LoadError
|
|
79
|
+
rescue => e
|
|
80
|
+
e
|
|
102
81
|
end
|
data/lib/arel_extensions.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
require 'arel'
|
|
2
|
-
require 'base64'
|
|
3
2
|
|
|
4
3
|
require 'arel_extensions/railtie' if defined?(Rails::Railtie)
|
|
5
4
|
|
|
@@ -8,54 +7,41 @@ require 'arel_extensions/railtie' if defined?(Rails::Railtie)
|
|
|
8
7
|
# Count|NamedFunction < Function < Arel::Nodes::Node
|
|
9
8
|
|
|
10
9
|
# pure Arel internals improvements
|
|
11
|
-
|
|
10
|
+
Arel::Nodes::Binary.class_eval do
|
|
12
11
|
include Arel::AliasPredication
|
|
13
12
|
include Arel::Expressions
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
Arel::Nodes::Casted.class_eval do
|
|
17
16
|
include Arel::AliasPredication
|
|
18
|
-
|
|
19
|
-
# They forget to define hash.
|
|
20
|
-
if Gem::Version.new(Arel::VERSION) < Gem::Version.new('10.0.0')
|
|
21
|
-
def hash
|
|
22
|
-
[self.class, self.val, self.attribute].hash
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
17
|
end
|
|
26
18
|
|
|
27
|
-
|
|
19
|
+
Arel::Nodes::Unary.class_eval do
|
|
28
20
|
include Arel::Math
|
|
29
21
|
include Arel::AliasPredication
|
|
30
22
|
include Arel::Expressions
|
|
31
23
|
end
|
|
32
24
|
|
|
33
|
-
|
|
25
|
+
Arel::Nodes::Grouping.class_eval do
|
|
26
|
+
include Arel::Math
|
|
27
|
+
include Arel::AliasPredication
|
|
34
28
|
include Arel::OrderPredications
|
|
29
|
+
include Arel::Expressions
|
|
35
30
|
end
|
|
36
31
|
|
|
37
|
-
|
|
38
|
-
def eql? other
|
|
39
|
-
self.hash.eql? other.hash
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
class Arel::Nodes::Function
|
|
32
|
+
Arel::Nodes::Function.class_eval do
|
|
44
33
|
include Arel::Math
|
|
45
34
|
include Arel::Expressions
|
|
46
35
|
end
|
|
47
36
|
|
|
48
|
-
if
|
|
49
|
-
|
|
37
|
+
if Arel::VERSION >= "7.1.0"
|
|
38
|
+
Arel::Nodes::Case.class_eval do
|
|
50
39
|
include Arel::Math
|
|
51
40
|
include Arel::Expressions
|
|
52
41
|
end
|
|
53
42
|
end
|
|
54
43
|
|
|
55
|
-
require 'arel_extensions/warning'
|
|
56
|
-
require 'arel_extensions/helpers'
|
|
57
44
|
require 'arel_extensions/version'
|
|
58
|
-
require 'arel_extensions/aliases'
|
|
59
45
|
require 'arel_extensions/attributes'
|
|
60
46
|
require 'arel_extensions/visitors'
|
|
61
47
|
require 'arel_extensions/nodes'
|
|
@@ -79,117 +65,42 @@ require 'arel_extensions/nodes/case'
|
|
|
79
65
|
require 'arel_extensions/nodes/soundex'
|
|
80
66
|
require 'arel_extensions/nodes/cast'
|
|
81
67
|
require 'arel_extensions/nodes/json'
|
|
82
|
-
require 'arel_extensions/nodes/rollup'
|
|
83
|
-
require 'arel_extensions/nodes/select'
|
|
84
68
|
|
|
85
|
-
# It seems like the code in lib/arel_extensions/visitors.rb that is supposed
|
|
86
|
-
# to inject ArelExtension is not enough. Different versions of the sqlserver
|
|
87
|
-
# adapter behave differently. It doesn't always proc, so we added this for
|
|
88
|
-
# coverage.
|
|
89
|
-
if defined?(Arel::Visitors::SQLServer)
|
|
90
|
-
Arel::Visitors.const_set('MSSQL', Arel::Visitors::SQLServer)
|
|
91
|
-
require 'arel_extensions/visitors/mssql'
|
|
92
|
-
class Arel::Visitors::SQLServer
|
|
93
|
-
include ArelExtensions::Visitors::MSSQL
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
69
|
|
|
97
|
-
module Arel
|
|
98
|
-
def self.column_of table_name, column_name
|
|
99
|
-
ArelExtensions.column_of(table_name, column_name)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def self.duration s, expr
|
|
103
|
-
ArelExtensions::Nodes::Duration.new("#{s}i", expr)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
# The FALSE pseudo literal.
|
|
107
|
-
def self.false
|
|
108
|
-
Arel::Nodes::Equality.new(1, 0)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def self.grouping *v
|
|
112
|
-
Arel::Nodes::Grouping.new(*v)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def self.json *expr
|
|
116
|
-
ArelExtensions::Nodes::Json.new(
|
|
117
|
-
if expr.length == 1
|
|
118
|
-
expr.first
|
|
119
|
-
else
|
|
120
|
-
expr
|
|
121
|
-
end
|
|
122
|
-
)
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def self.json_true
|
|
126
|
-
res = Arel.grouping(Arel.quoted('true'))
|
|
127
|
-
res.instance_eval {
|
|
128
|
-
def return_type
|
|
129
|
-
:boolean
|
|
130
|
-
end
|
|
131
|
-
}
|
|
132
|
-
res
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def self.json_false
|
|
136
|
-
res = Arel.grouping(Arel.quoted('false'))
|
|
137
|
-
res.instance_eval {
|
|
138
|
-
def return_type
|
|
139
|
-
:boolean
|
|
140
|
-
end
|
|
141
|
-
}
|
|
142
|
-
res
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
# The NULL literal.
|
|
146
|
-
def self.null
|
|
147
|
-
Arel.quoted(nil)
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
def self.quoted *args
|
|
151
|
-
Arel::Nodes.build_quoted(*args)
|
|
152
|
-
end
|
|
153
70
|
|
|
71
|
+
module Arel
|
|
154
72
|
def self.rand
|
|
155
73
|
ArelExtensions::Nodes::Rand.new
|
|
156
74
|
end
|
|
157
75
|
|
|
158
|
-
def self.rollup(*args)
|
|
159
|
-
Arel::Nodes::RollUp.new(args)
|
|
160
|
-
end
|
|
161
|
-
|
|
162
76
|
def self.shorten s
|
|
163
77
|
Base64.urlsafe_encode64(Digest::MD5.new.digest(s)).tr('=', '').tr('-', '_')
|
|
164
78
|
end
|
|
165
79
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
tmp = Arel.grouping(nil)
|
|
173
|
-
Arel.grouping v.map{|e| tmp.convert_to_node(e)}
|
|
80
|
+
def self.json *expr
|
|
81
|
+
if expr.length == 1
|
|
82
|
+
ArelExtensions::Nodes::Json.new(expr.first)
|
|
83
|
+
else
|
|
84
|
+
ArelExtensions::Nodes::Json.new(expr)
|
|
85
|
+
end
|
|
174
86
|
end
|
|
175
87
|
|
|
176
|
-
# For instance
|
|
177
|
-
#
|
|
178
|
-
# ```
|
|
179
|
-
# Arel.when(at[field].is_null).then(0).else(1)
|
|
180
|
-
# ```
|
|
181
88
|
def self.when condition
|
|
182
89
|
ArelExtensions::Nodes::Case.new.when(condition)
|
|
183
90
|
end
|
|
91
|
+
|
|
92
|
+
def self.duration s, expr
|
|
93
|
+
ArelExtensions::Nodes::Duration.new(s.to_s+'i',expr)
|
|
94
|
+
end
|
|
95
|
+
|
|
184
96
|
end
|
|
185
97
|
|
|
186
|
-
|
|
98
|
+
Arel::Attributes::Attribute.class_eval do
|
|
187
99
|
include Arel::Math
|
|
188
100
|
include ArelExtensions::Attributes
|
|
189
101
|
end
|
|
190
102
|
|
|
191
|
-
|
|
192
|
-
include ArelExtensions::Aliases
|
|
103
|
+
Arel::Nodes::Function.class_eval do
|
|
193
104
|
include ArelExtensions::Math
|
|
194
105
|
include ArelExtensions::Comparators
|
|
195
106
|
include ArelExtensions::DateDuration
|
|
@@ -198,150 +109,44 @@ class Arel::Nodes::Function
|
|
|
198
109
|
include ArelExtensions::BooleanFunctions
|
|
199
110
|
include ArelExtensions::NullFunctions
|
|
200
111
|
include ArelExtensions::Predications
|
|
201
|
-
|
|
202
|
-
alias_method(:old_as, :as) rescue nil
|
|
203
|
-
def as other
|
|
204
|
-
res = Arel::Nodes::As.new(self.clone, Arel.sql(other))
|
|
205
|
-
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('9.0.0')
|
|
206
|
-
self.alias = Arel.sql(other)
|
|
207
|
-
end
|
|
208
|
-
res
|
|
209
|
-
end
|
|
210
112
|
end
|
|
211
113
|
|
|
212
|
-
|
|
213
|
-
include ArelExtensions::Math
|
|
214
|
-
include ArelExtensions::Comparators
|
|
215
|
-
include ArelExtensions::DateDuration
|
|
216
|
-
include ArelExtensions::MathFunctions
|
|
217
|
-
include ArelExtensions::NullFunctions
|
|
218
|
-
include ArelExtensions::StringFunctions
|
|
219
|
-
include ArelExtensions::Predications
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
class Arel::Nodes::Unary
|
|
114
|
+
Arel::Nodes::Unary.class_eval do
|
|
223
115
|
include ArelExtensions::Math
|
|
224
116
|
include ArelExtensions::Attributes
|
|
225
117
|
include ArelExtensions::MathFunctions
|
|
226
118
|
include ArelExtensions::Comparators
|
|
227
119
|
include ArelExtensions::Predications
|
|
228
|
-
def eql? other
|
|
229
|
-
hash == other.hash
|
|
230
|
-
end
|
|
231
120
|
end
|
|
232
121
|
|
|
233
|
-
|
|
122
|
+
Arel::Nodes::Binary.class_eval do
|
|
234
123
|
include ArelExtensions::Math
|
|
235
124
|
include ArelExtensions::Attributes
|
|
236
125
|
include ArelExtensions::MathFunctions
|
|
237
126
|
include ArelExtensions::Comparators
|
|
238
127
|
include ArelExtensions::BooleanFunctions
|
|
239
128
|
include ArelExtensions::Predications
|
|
240
|
-
def eql? other
|
|
241
|
-
hash == other.hash
|
|
242
|
-
end
|
|
243
129
|
end
|
|
244
130
|
|
|
245
|
-
|
|
131
|
+
Arel::Nodes::Equality.class_eval do
|
|
246
132
|
include ArelExtensions::Comparators
|
|
247
133
|
include ArelExtensions::DateDuration
|
|
248
134
|
include ArelExtensions::MathFunctions
|
|
249
135
|
include ArelExtensions::StringFunctions
|
|
250
136
|
end
|
|
251
137
|
|
|
252
|
-
|
|
138
|
+
|
|
139
|
+
Arel::InsertManager.class_eval do
|
|
253
140
|
include ArelExtensions::InsertManager
|
|
254
141
|
end
|
|
255
142
|
|
|
256
|
-
|
|
143
|
+
Arel::SelectManager.class_eval do
|
|
257
144
|
include ArelExtensions::SetFunctions
|
|
258
145
|
include ArelExtensions::Nodes
|
|
259
|
-
|
|
260
|
-
remove_method(:as) if method_defined?(:as)
|
|
261
|
-
def as table_name
|
|
262
|
-
Arel::Nodes::TableAlias.new(self, table_name)
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
# Install an alias, if present.
|
|
266
|
-
def xas table_name
|
|
267
|
-
if table_name.present?
|
|
268
|
-
as table_name
|
|
269
|
-
else
|
|
270
|
-
self
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
146
|
end
|
|
274
147
|
|
|
275
|
-
|
|
148
|
+
Arel::Nodes::As.class_eval do
|
|
276
149
|
include ArelExtensions::Nodes
|
|
277
150
|
end
|
|
278
151
|
|
|
279
|
-
class Arel::Table
|
|
280
|
-
alias_method(:old_alias, :alias) rescue nil
|
|
281
|
-
|
|
282
|
-
# activerecord 7.1 removed the alias. We might need to remove our dependency
|
|
283
|
-
# on the alias if it proves problematic.
|
|
284
|
-
if !self.respond_to?(:table_name)
|
|
285
|
-
alias :table_name :name
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
def alias(name = "#{self.name}_2")
|
|
289
|
-
if name.present?
|
|
290
|
-
Arel::Nodes::TableAlias.new(self, name)
|
|
291
|
-
else
|
|
292
|
-
self
|
|
293
|
-
end
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
class Arel::Nodes::TableAlias
|
|
298
|
-
def method_missing(*args)
|
|
299
|
-
met = args.shift.to_sym
|
|
300
|
-
if self.relation.respond_to?(met)
|
|
301
|
-
self.relation.send(met, args)
|
|
302
|
-
else
|
|
303
|
-
super(met, *args)
|
|
304
|
-
end
|
|
305
|
-
end
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
class Arel::Attributes::Attribute
|
|
310
|
-
def to_sql(engine = Arel::Table.engine)
|
|
311
|
-
collector = Arel::Collectors::SQLString.new
|
|
312
|
-
collector = engine.connection.visitor.accept self, collector
|
|
313
|
-
collector.value
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
def rollup
|
|
317
|
-
Arel::Nodes::RollUp.new([self])
|
|
318
|
-
end
|
|
319
|
-
end
|
|
320
|
-
|
|
321
|
-
class Arel::Nodes::Node
|
|
322
|
-
def rollup
|
|
323
|
-
Arel::Nodes::RollUp.new([self])
|
|
324
|
-
end
|
|
325
|
-
end
|
|
326
|
-
|
|
327
|
-
require 'active_record'
|
|
328
|
-
if ActiveRecord.version >= Gem::Version.create('7.2')
|
|
329
|
-
class ActiveRecord::Relation::WhereClause
|
|
330
|
-
def except_predicates(columns)
|
|
331
|
-
attrs = columns.extract! { |node| node.is_a?(Arel::Attribute) }
|
|
332
|
-
non_attrs = columns.extract! { |node| node.is_a?(Arel::Predications) }
|
|
333
152
|
|
|
334
|
-
predicates.reject do |node|
|
|
335
|
-
if !non_attrs.empty? && node.equality? && node.left.is_a?(Arel::Predications)
|
|
336
|
-
non_attrs.include?(node.left)
|
|
337
|
-
end || Arel.fetch_attribute(node) do |attr|
|
|
338
|
-
attrs.find { |v| v.eql? attr } || columns.include?(attr.name.to_s) # 👈 replces
|
|
339
|
-
# attrs.include?(attr) || columns.include?(attr.name.to_s) # 👈 this
|
|
340
|
-
#
|
|
341
|
-
# And that's because our attributes override `==`, so `attrs.include?(attr)` always
|
|
342
|
-
# passes because it returns an equality node.
|
|
343
|
-
end
|
|
344
|
-
end
|
|
345
|
-
end
|
|
346
|
-
end
|
|
347
|
-
end
|
data/test/database.yml
CHANGED
|
@@ -8,30 +8,22 @@ jdbc-sqlite:
|
|
|
8
8
|
timeout: 500
|
|
9
9
|
mysql:
|
|
10
10
|
adapter: mysql2
|
|
11
|
-
database:
|
|
12
|
-
username:
|
|
13
|
-
host: 127.0.0.1
|
|
14
|
-
port: 3306
|
|
11
|
+
database: arext_test
|
|
12
|
+
username: travis
|
|
15
13
|
encoding: utf8
|
|
16
14
|
jdbc-mysql:
|
|
17
15
|
adapter: jdbcmysql
|
|
18
|
-
database:
|
|
19
|
-
username:
|
|
16
|
+
database: arext_test
|
|
17
|
+
username: travis
|
|
20
18
|
encoding: utf8
|
|
21
19
|
postgresql:
|
|
22
20
|
adapter: postgresql
|
|
23
|
-
database:
|
|
21
|
+
database: arext_test
|
|
24
22
|
username: postgres
|
|
25
|
-
password: secret
|
|
26
|
-
host: 127.0.0.1
|
|
27
|
-
port: 5432
|
|
28
23
|
jdbc-postgresql:
|
|
29
24
|
adapter: jdbcpostgresql
|
|
30
|
-
database:
|
|
25
|
+
database: arext_test
|
|
31
26
|
username: postgres
|
|
32
|
-
password: secret
|
|
33
|
-
host: 127.0.0.1
|
|
34
|
-
port: 5432
|
|
35
27
|
oracle:
|
|
36
28
|
adapter: oracle_enhanced
|
|
37
29
|
database: xe
|
|
@@ -45,7 +37,7 @@ jdbc-oracle:
|
|
|
45
37
|
ibm_db:
|
|
46
38
|
adapter: ibm_db
|
|
47
39
|
username: travis
|
|
48
|
-
database:
|
|
40
|
+
database: arext_test
|
|
49
41
|
mssql:
|
|
50
42
|
adapter: sqlserver
|
|
51
43
|
host: localhost
|
data/test/helper.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'minitest/autorun'
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'arel'
|
|
5
|
+
require 'active_record'
|
|
6
|
+
|
|
7
|
+
require 'arel_extensions'
|
|
8
|
+
|
|
9
|
+
require 'support/fake_record'
|
|
10
|
+
Arel::Table.engine = FakeRecord::Base.new
|
|
11
|
+
|
|
12
|
+
$arel_silence_type_casting_deprecation = true
|
|
13
|
+
|
|
14
|
+
class Object
|
|
15
|
+
def must_be_like other
|
|
16
|
+
gsub(/\s+/, ' ').strip.must_equal other.gsub(/\s+/, ' ').strip
|
|
17
|
+
end
|
|
18
|
+
end
|