arel_extensions 2.3.2 → 2.4.0
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/.github/workflows/publish.yml +2 -1
- data/.github/workflows/ruby.yml +94 -45
- data/.rubocop.yml +4 -4
- data/Makefile +18 -0
- data/NEWS.md +12 -0
- data/README.md +21 -3
- data/dev/arelx.dockerfile +13 -16
- data/dev/compose.yaml +26 -28
- data/gemfiles/rails6.gemfile +1 -0
- data/gemfiles/rails6_1.gemfile +1 -0
- data/gemfiles/rails7.gemfile +1 -0
- data/gemfiles/rails7_1.gemfile +0 -1
- data/gemfiles/rails8.gemfile +40 -0
- data/gemfiles/rails8_1.gemfile +41 -0
- data/init/postgresql.sql +3 -4
- data/lib/arel_extensions/comparators.rb +2 -0
- data/lib/arel_extensions/constants.rb +13 -0
- data/lib/arel_extensions/helpers.rb +3 -4
- data/lib/arel_extensions/math_functions.rb +1 -1
- data/lib/arel_extensions/nodes/byte_size.rb +11 -0
- data/lib/arel_extensions/nodes/case.rb +1 -1
- data/lib/arel_extensions/nodes/char_length.rb +11 -0
- data/lib/arel_extensions/nodes/function.rb +1 -3
- data/lib/arel_extensions/nodes/matches.rb +2 -2
- data/lib/arel_extensions/predications.rb +1 -1
- data/lib/arel_extensions/string_functions.rb +15 -2
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/mssql.rb +23 -8
- data/lib/arel_extensions/visitors/mysql.rb +14 -0
- data/lib/arel_extensions/visitors/oracle.rb +15 -1
- data/lib/arel_extensions/visitors/postgresql.rb +14 -0
- data/lib/arel_extensions/visitors/sqlite.rb +17 -1
- data/lib/arel_extensions/visitors/to_sql.rb +1 -1
- data/lib/arel_extensions/visitors.rb +1 -1
- data/lib/arel_extensions.rb +15 -6
- data/test/arelx_test_helper.rb +8 -6
- data/test/config_loader.rb +9 -0
- data/test/database.yml +8 -6
- data/test/real_db_test.rb +2 -2
- data/test/support/fake_record.rb +3 -1
- data/test/visitors/test_bulk_insert_oracle.rb +2 -2
- data/test/visitors/test_bulk_insert_sqlite.rb +2 -2
- data/test/visitors/test_to_sql.rb +1 -1
- data/test/with_ar/all_agnostic_test.rb +76 -18
- data/test/with_ar/insert_agnostic_test.rb +2 -2
- data/test/with_ar/test_bulk_sqlite.rb +2 -2
- data/test/with_ar/test_math_sqlite.rb +2 -2
- data/test/with_ar/test_string_mysql.rb +2 -2
- data/test/with_ar/test_string_sqlite.rb +2 -2
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +9 -5
- data/bin/compose +0 -6
- data/gemfiles/rails3.gemfile +0 -20
- data/gemfiles/rails4_2.gemfile +0 -38
data/init/postgresql.sql
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
CREATE OR REPLACE FUNCTION public.find_in_set(n
|
|
1
|
+
CREATE OR REPLACE FUNCTION public.find_in_set(n TEXT, s TEXT)
|
|
2
2
|
RETURNS INT4
|
|
3
3
|
LANGUAGE sql
|
|
4
4
|
AS $function$
|
|
5
5
|
SELECT * FROM (
|
|
6
6
|
select int4(z.row_number) from (
|
|
7
7
|
select row_number() over(), y.x
|
|
8
|
-
from (select unnest((
|
|
8
|
+
from (select unnest(regexp_split_to_array($2, ',')) as x) as y -- use string_to_array if on pg 14+.
|
|
9
9
|
) as z
|
|
10
10
|
where z.x = $1
|
|
11
11
|
UNION ALL
|
|
12
12
|
SELECT 0) z
|
|
13
13
|
LIMIT 1
|
|
14
|
-
$function
|
|
15
|
-
;
|
|
14
|
+
$function$;
|
|
16
15
|
|
|
17
16
|
CREATE OR REPLACE FUNCTION public.levenshtein_distance(s text, t text)
|
|
18
17
|
RETURNS integer AS $$
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module ArelExtensions
|
|
2
|
+
ACTIVE_RECORD_VERSION = Gem::Version.new(ActiveRecord::VERSION::STRING).freeze
|
|
3
|
+
AREL_VERSION = Gem::Version.new(Arel::VERSION).freeze
|
|
4
|
+
V10 = Gem::Version.new('10.0').freeze
|
|
5
|
+
V5 = Gem::Version.new('5.0').freeze
|
|
6
|
+
V6 = Gem::Version.new('6.0').freeze
|
|
7
|
+
V7 = Gem::Version.new('7.0').freeze
|
|
8
|
+
V7_0 = Gem::Version.new('7.0').freeze
|
|
9
|
+
V7_1 = Gem::Version.new('7.1').freeze
|
|
10
|
+
V7_2 = Gem::Version.new('7.2').freeze
|
|
11
|
+
V8_1 = Gem::Version.new('8.1').freeze
|
|
12
|
+
V9_0 = Gem::Version.new('9.0').freeze
|
|
13
|
+
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
module ArelExtensions
|
|
2
|
-
|
|
3
2
|
#
|
|
4
3
|
# column_of
|
|
5
4
|
#
|
|
@@ -34,13 +33,13 @@ module ArelExtensions
|
|
|
34
33
|
column_of_via_arel_table(table_name, column_name)
|
|
35
34
|
else
|
|
36
35
|
if pool.respond_to?(:pool_config)
|
|
37
|
-
if pool.pool_config.respond_to?(:schema_reflection)
|
|
38
|
-
if
|
|
36
|
+
if pool.pool_config.respond_to?(:schema_reflection)
|
|
37
|
+
if ACTIVE_RECORD_VERSION >= V7_2
|
|
39
38
|
pool.pool_config.schema_reflection.columns_hash(pool, table_name)[column_name]
|
|
40
39
|
else
|
|
41
40
|
pool.pool_config.schema_reflection.columns_hash(ActiveRecord::Base.connection, table_name)[column_name]
|
|
42
41
|
end
|
|
43
|
-
else
|
|
42
|
+
else
|
|
44
43
|
pool.pool_config.schema_cache.columns_hash(table_name)[column_name]
|
|
45
44
|
end
|
|
46
45
|
elsif pool.respond_to?(:schema_cache) # activerecord < 6.1
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
module ArelExtensions
|
|
2
2
|
module Nodes
|
|
3
3
|
class IMatches < Arel::Nodes::Matches
|
|
4
|
-
attr_accessor :case_sensitive if
|
|
4
|
+
attr_accessor :case_sensitive if AREL_VERSION < V7
|
|
5
5
|
|
|
6
6
|
def initialize(left, right, escape = nil)
|
|
7
7
|
r = Arel.quoted(right)
|
|
8
|
-
if
|
|
8
|
+
if AREL_VERSION < V7 # managed by default in version 7+ (rails 5), so useful for rails 3 & 4
|
|
9
9
|
super(left, r, escape)
|
|
10
10
|
@case_sensitive = false
|
|
11
11
|
else
|
|
@@ -5,7 +5,7 @@ module ArelExtensions
|
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def matches(other, escape = nil, case_sensitive = nil)
|
|
8
|
-
if
|
|
8
|
+
if AREL_VERSION < V7
|
|
9
9
|
Arel::Nodes::Matches.new(self, Arel.quoted(other), escape)
|
|
10
10
|
else
|
|
11
11
|
Arel::Nodes::Matches.new(self, Arel.quoted(other), escape, case_sensitive)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'arel_extensions/nodes/byte_size'
|
|
2
|
+
require 'arel_extensions/nodes/char_length'
|
|
1
3
|
require 'arel_extensions/nodes/concat' # if Arel::VERSION.to_i < 7
|
|
2
4
|
require 'arel_extensions/nodes/length'
|
|
3
5
|
require 'arel_extensions/nodes/locate'
|
|
@@ -19,22 +21,33 @@ require 'arel_extensions/nodes/md5'
|
|
|
19
21
|
|
|
20
22
|
module ArelExtensions
|
|
21
23
|
module StringFunctions
|
|
24
|
+
include ArelExtensions::Warning
|
|
25
|
+
|
|
22
26
|
# *FindInSet function .......
|
|
23
27
|
def &(other)
|
|
24
|
-
ArelExtensions::Nodes::FindInSet.new [
|
|
28
|
+
ArelExtensions::Nodes::FindInSet.new [
|
|
29
|
+
Arel.quoted(other.is_a?(Integer) ? other.to_s : other),
|
|
30
|
+
self,
|
|
31
|
+
]
|
|
25
32
|
end
|
|
26
33
|
|
|
27
34
|
# LENGTH function returns the length (bytewise) of the value in a text field.
|
|
28
35
|
def length
|
|
36
|
+
deprecated "Use `byte_size` or `char_length` instead. `length` relies on the vendor's `LEN/LENGTH` implementation and it's not portable"
|
|
29
37
|
ArelExtensions::Nodes::Length.new self, true
|
|
30
38
|
end
|
|
31
39
|
|
|
32
40
|
def byte_length
|
|
41
|
+
deprecated "Use `byte_size` instead. `byte_length` relies on the vendor's `LEN/LENGTH` implementation and it's not portable"
|
|
33
42
|
ArelExtensions::Nodes::Length.new self, true
|
|
34
43
|
end
|
|
35
44
|
|
|
45
|
+
def byte_size
|
|
46
|
+
ArelExtensions::Nodes::ByteSize.new self
|
|
47
|
+
end
|
|
48
|
+
|
|
36
49
|
def char_length
|
|
37
|
-
ArelExtensions::Nodes::
|
|
50
|
+
ArelExtensions::Nodes::CharLength.new self
|
|
38
51
|
end
|
|
39
52
|
|
|
40
53
|
# LOCATE function returns the first starting position of a string in another string.
|
|
@@ -76,7 +76,7 @@ module ArelExtensions
|
|
|
76
76
|
# The following is adapted from
|
|
77
77
|
# https://github.com/rails/rails/blob/main/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
|
|
78
78
|
#
|
|
79
|
-
if RUBY_PLATFORM == 'java' &&
|
|
79
|
+
if RUBY_PLATFORM == 'java' && AREL_VERSION <= V6
|
|
80
80
|
def quote_string(s)
|
|
81
81
|
s.gsub('\\', '\&\&').gsub("'", "''") # ' (for ruby-mode)
|
|
82
82
|
end
|
|
@@ -133,7 +133,7 @@ module ArelExtensions
|
|
|
133
133
|
value.to_s('F')
|
|
134
134
|
when Numeric, ActiveSupport::Duration
|
|
135
135
|
value.to_s
|
|
136
|
-
when
|
|
136
|
+
when AREL_VERSION > V6 && ActiveRecord::Type::Time::Value
|
|
137
137
|
"'#{quoted_time(value)}'"
|
|
138
138
|
when Date, Time
|
|
139
139
|
"'#{quoted_date(value)}'"
|
|
@@ -216,8 +216,6 @@ module ArelExtensions
|
|
|
216
216
|
collector
|
|
217
217
|
end
|
|
218
218
|
|
|
219
|
-
|
|
220
|
-
|
|
221
219
|
def visit_ArelExtensions_Nodes_DateDiff o, collector
|
|
222
220
|
case o.right_node_type
|
|
223
221
|
when :ruby_date, :ruby_time, :date, :datetime, :time
|
|
@@ -274,6 +272,23 @@ module ArelExtensions
|
|
|
274
272
|
collector
|
|
275
273
|
end
|
|
276
274
|
|
|
275
|
+
def visit_ArelExtensions_Nodes_ByteSize o, collector
|
|
276
|
+
collector << 'DATALENGTH(CAST('
|
|
277
|
+
collector = visit o.expr.coalesce(''), collector
|
|
278
|
+
collector << ' AS VARCHAR(MAX)))'
|
|
279
|
+
collector
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def visit_ArelExtensions_Nodes_CharLength o, collector
|
|
283
|
+
# According to the docs https://learn.microsoft.com/en-us/sql/t-sql/functions/len-transact-sql?view=sql-server-ver17
|
|
284
|
+
# LEN doesn't take into account the trailing white space, and that's why
|
|
285
|
+
# we need to do acrobatics.
|
|
286
|
+
collector << 'LEN('
|
|
287
|
+
collector = visit o.expr.coalesce(''), collector
|
|
288
|
+
collector << " + 'x') - 1"
|
|
289
|
+
collector
|
|
290
|
+
end
|
|
291
|
+
|
|
277
292
|
def visit_ArelExtensions_Nodes_Length o, collector
|
|
278
293
|
if o.bytewise
|
|
279
294
|
collector << '(DATALENGTH('
|
|
@@ -575,11 +590,11 @@ module ArelExtensions
|
|
|
575
590
|
# Sometimes these values are already quoted, if they are, don't double quote it
|
|
576
591
|
lft, rgt =
|
|
577
592
|
if o.right.is_a?(Arel::Nodes::SqlLiteral)
|
|
578
|
-
if
|
|
593
|
+
if AREL_VERSION >= V6 && o.right[0] != '[' && o.right[-1] != ']'
|
|
579
594
|
# This is a lie, it's not about arel version, but SQL Server's (>= 2000).
|
|
580
|
-
[
|
|
581
|
-
elsif o.right[0] != '"' && o.right[-1] != '"'
|
|
582
|
-
|
|
595
|
+
%w([ ])
|
|
596
|
+
elsif ACTIVE_RECORD_VERSION < V8_1 && o.right[0] != '"' && o.right[-1] != '"'
|
|
597
|
+
%w(" ")
|
|
583
598
|
else
|
|
584
599
|
[]
|
|
585
600
|
end
|
|
@@ -86,6 +86,20 @@ module ArelExtensions
|
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
# String functions
|
|
89
|
+
def visit_ArelExtensions_Nodes_ByteSize o, collector
|
|
90
|
+
collector << 'LENGTH('
|
|
91
|
+
collector = visit o.expr.coalesce(''), collector
|
|
92
|
+
collector << ')'
|
|
93
|
+
collector
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def visit_ArelExtensions_Nodes_CharLength o, collector
|
|
97
|
+
collector << 'CHAR_LENGTH('
|
|
98
|
+
collector = visit o.expr.coalesce(''), collector
|
|
99
|
+
collector << ')'
|
|
100
|
+
collector
|
|
101
|
+
end
|
|
102
|
+
|
|
89
103
|
def visit_ArelExtensions_Nodes_IMatches o, collector # insensitive on ASCII
|
|
90
104
|
collector << 'LOWER('
|
|
91
105
|
collector = visit o.left, collector
|
|
@@ -13,6 +13,20 @@ module ArelExtensions
|
|
|
13
13
|
}
|
|
14
14
|
NUMBER_COMMA_MAPPING = {'en_US' => '.,', 'fr_FR' => ',', 'sv_SE' => ', '}
|
|
15
15
|
|
|
16
|
+
def visit_ArelExtensions_Nodes_ByteSize o, collector
|
|
17
|
+
collector << 'LENGTHB('
|
|
18
|
+
collector = visit o.expr.coalesce(''), collector
|
|
19
|
+
collector << ')'
|
|
20
|
+
collector
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def visit_ArelExtensions_Nodes_CharLength o, collector
|
|
24
|
+
collector << 'LENGTH('
|
|
25
|
+
collector = visit o.expr.coalesce(''), collector
|
|
26
|
+
collector << ')'
|
|
27
|
+
collector
|
|
28
|
+
end
|
|
29
|
+
|
|
16
30
|
def visit_ArelExtensions_Nodes_Log10 o, collector
|
|
17
31
|
collector << 'LOG('
|
|
18
32
|
o.expressions.each_with_index { |arg, i|
|
|
@@ -489,7 +503,7 @@ module ArelExtensions
|
|
|
489
503
|
end
|
|
490
504
|
|
|
491
505
|
# add primary_key if not present, avoid zip
|
|
492
|
-
if
|
|
506
|
+
if AREL_VERSION < V7
|
|
493
507
|
def visit_ArelExtensions_InsertManager_BulkValues o, collector
|
|
494
508
|
collector << '('
|
|
495
509
|
o.left.each_with_index do |row, idx| # values
|
|
@@ -20,6 +20,20 @@ module ArelExtensions
|
|
|
20
20
|
'en_US' => '.,', 'fr_FR' => ',', 'sv_SE' => ', '
|
|
21
21
|
}.freeze
|
|
22
22
|
|
|
23
|
+
def visit_ArelExtensions_Nodes_ByteSize o, collector
|
|
24
|
+
collector << 'octet_length('
|
|
25
|
+
collector = visit o.expr.coalesce(''), collector
|
|
26
|
+
collector << ')'
|
|
27
|
+
collector
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def visit_ArelExtensions_Nodes_CharLength o, collector
|
|
31
|
+
collector << 'length('
|
|
32
|
+
collector = visit o.expr.coalesce(''), collector
|
|
33
|
+
collector << ')'
|
|
34
|
+
collector
|
|
35
|
+
end
|
|
36
|
+
|
|
23
37
|
def visit_ArelExtensions_Nodes_Rand o, collector
|
|
24
38
|
collector << 'RANDOM('
|
|
25
39
|
if (o.left != nil && o.right != nil)
|
|
@@ -18,6 +18,22 @@ module ArelExtensions
|
|
|
18
18
|
}.freeze
|
|
19
19
|
|
|
20
20
|
# String functions
|
|
21
|
+
def visit_ArelExtensions_Nodes_ByteSize o, collector
|
|
22
|
+
# sqlite 3.43.0 (2023-08-24) introduced `octet_length`, but we still support older versions.
|
|
23
|
+
# https://sqlite.org/changes.html
|
|
24
|
+
collector << 'length(CAST('
|
|
25
|
+
collector = visit o.expr.coalesce(''), collector
|
|
26
|
+
collector << ' AS BLOB))'
|
|
27
|
+
collector
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def visit_ArelExtensions_Nodes_CharLength o, collector
|
|
31
|
+
collector << 'length('
|
|
32
|
+
collector = visit o.expr.coalesce(''), collector
|
|
33
|
+
collector << ')'
|
|
34
|
+
collector
|
|
35
|
+
end
|
|
36
|
+
|
|
21
37
|
def visit_ArelExtensions_Nodes_IMatches o, collector # insensitive on ASCII
|
|
22
38
|
collector = visit o.left.ci_collate, collector
|
|
23
39
|
collector << ' LIKE '
|
|
@@ -237,7 +253,7 @@ module ArelExtensions
|
|
|
237
253
|
collector
|
|
238
254
|
end
|
|
239
255
|
|
|
240
|
-
if
|
|
256
|
+
if AREL_VERSION < V7
|
|
241
257
|
def visit_ArelExtensions_InsertManager_BulkValues o, collector
|
|
242
258
|
o.left.each_with_index do |row, idx|
|
|
243
259
|
collector << 'SELECT '
|
|
@@ -14,7 +14,7 @@ if RUBY_PLATFORM == 'java' \
|
|
|
14
14
|
warn 'arel/visitors/sqlserver not found: MSSQL might not work correctly.'
|
|
15
15
|
end
|
|
16
16
|
elsif RUBY_PLATFORM != 'java' \
|
|
17
|
-
&&
|
|
17
|
+
&& ArelExtensions::AREL_VERSION < ArelExtensions::V10 \
|
|
18
18
|
&& Gem::Specification.find { |g| g.name == 'activerecord-sqlserver-adapter' }
|
|
19
19
|
begin
|
|
20
20
|
require 'arel_sqlserver'
|
data/lib/arel_extensions.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'arel'
|
|
2
|
+
require 'arel_extensions/constants'
|
|
2
3
|
require 'base64'
|
|
3
4
|
|
|
4
5
|
require 'arel_extensions/railtie' if defined?(Rails::Railtie)
|
|
@@ -17,7 +18,7 @@ class Arel::Nodes::Casted
|
|
|
17
18
|
include Arel::AliasPredication
|
|
18
19
|
|
|
19
20
|
# They forget to define hash.
|
|
20
|
-
if
|
|
21
|
+
if ArelExtensions::AREL_VERSION < ArelExtensions::V10
|
|
21
22
|
def hash
|
|
22
23
|
[self.class, self.val, self.attribute].hash
|
|
23
24
|
end
|
|
@@ -45,7 +46,7 @@ class Arel::Nodes::Function
|
|
|
45
46
|
include Arel::Expressions
|
|
46
47
|
end
|
|
47
48
|
|
|
48
|
-
if
|
|
49
|
+
if ArelExtensions::AREL_VERSION >= ArelExtensions::V7_1
|
|
49
50
|
class Arel::Nodes::Case
|
|
50
51
|
include Arel::Math
|
|
51
52
|
include Arel::Expressions
|
|
@@ -199,12 +200,20 @@ class Arel::Nodes::Function
|
|
|
199
200
|
include ArelExtensions::NullFunctions
|
|
200
201
|
include ArelExtensions::Predications
|
|
201
202
|
|
|
203
|
+
if ArelExtensions::ACTIVE_RECORD_VERSION >= ArelExtensions::V8_1
|
|
204
|
+
attr_accessor :alias
|
|
205
|
+
alias_method :old_initialize, :initialize
|
|
206
|
+
|
|
207
|
+
def initialize(expr, aliaz = nil)
|
|
208
|
+
old_initialize(expr)
|
|
209
|
+
self.alias = aliaz
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
202
213
|
alias_method(:old_as, :as) rescue nil
|
|
203
214
|
def as other
|
|
204
215
|
res = Arel::Nodes::As.new(self.clone, Arel.sql(other))
|
|
205
|
-
|
|
206
|
-
self.alias = Arel.sql(other)
|
|
207
|
-
end
|
|
216
|
+
self.alias = Arel.sql(other)
|
|
208
217
|
res
|
|
209
218
|
end
|
|
210
219
|
end
|
|
@@ -325,7 +334,7 @@ class Arel::Nodes::Node
|
|
|
325
334
|
end
|
|
326
335
|
|
|
327
336
|
require 'active_record'
|
|
328
|
-
if
|
|
337
|
+
if ArelExtensions::ACTIVE_RECORD_VERSION >= ArelExtensions::V7_2
|
|
329
338
|
class ActiveRecord::Relation::WhereClause
|
|
330
339
|
def except_predicates(columns)
|
|
331
340
|
attrs = columns.extract! { |node| node.is_a?(Arel::Attribute) }
|
data/test/arelx_test_helper.rb
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
require 'minitest/autorun'
|
|
3
|
-
require 'fileutils'
|
|
4
|
-
require 'arel'
|
|
5
1
|
require 'active_record'
|
|
6
|
-
|
|
2
|
+
require 'arel'
|
|
3
|
+
require 'arel_extensions/constants'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'minitest/autorun'
|
|
6
|
+
require 'rubygems'
|
|
7
7
|
require 'support/fake_record'
|
|
8
8
|
|
|
9
|
+
require_relative './config_loader'
|
|
10
|
+
|
|
9
11
|
ENV['AREL_EXTENSIONS_IN_TEST'] = '1' # Useful for deprecation warnings.
|
|
10
12
|
|
|
11
13
|
def colored(color, msg)
|
|
@@ -59,7 +61,7 @@ end
|
|
|
59
61
|
|
|
60
62
|
|
|
61
63
|
def load_lib(gems)
|
|
62
|
-
if gems && (RUBY_PLATFORM == 'java' ||
|
|
64
|
+
if gems && (RUBY_PLATFORM == 'java' || ArelExtensions::AREL_VERSION > ArelExtensions::V9_0)
|
|
63
65
|
gems.each do |gem|
|
|
64
66
|
begin
|
|
65
67
|
require gem
|
data/test/database.yml
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# Updated to use ENV vars mapped in compose.yml
|
|
1
2
|
sqlite:
|
|
2
3
|
adapter: sqlite3
|
|
3
4
|
database: ":memory:"
|
|
@@ -10,27 +11,28 @@ mysql:
|
|
|
10
11
|
adapter: mysql2
|
|
11
12
|
database: arelx_test
|
|
12
13
|
username: root
|
|
13
|
-
host: 127.0.0.1
|
|
14
|
+
host: <%= ENV.fetch('MYSQL_HOST', '127.0.0.1') %>
|
|
14
15
|
port: 3306
|
|
15
|
-
encoding:
|
|
16
|
+
encoding: utf8mb4
|
|
16
17
|
jdbc-mysql:
|
|
17
18
|
adapter: jdbcmysql
|
|
18
19
|
database: arelx_test
|
|
19
20
|
username: root
|
|
20
|
-
encoding:
|
|
21
|
+
encoding: utf8mb4
|
|
22
|
+
host: <%= ENV.fetch('MYSQL_HOST', '127.0.0.1') %>
|
|
21
23
|
postgresql:
|
|
22
24
|
adapter: postgresql
|
|
23
25
|
database: arelx_test
|
|
24
26
|
username: postgres
|
|
25
27
|
password: secret
|
|
26
|
-
host: 127.0.0.1
|
|
28
|
+
host: <%= ENV.fetch('POSTGRES_HOST', '127.0.0.1') %>
|
|
27
29
|
port: 5432
|
|
28
30
|
jdbc-postgresql:
|
|
29
31
|
adapter: jdbcpostgresql
|
|
30
32
|
database: arelx_test
|
|
31
33
|
username: postgres
|
|
32
34
|
password: secret
|
|
33
|
-
host: 127.0.0.1
|
|
35
|
+
host: <%= ENV.fetch('POSTGRES_HOST', '127.0.0.1') %>
|
|
34
36
|
port: 5432
|
|
35
37
|
oracle:
|
|
36
38
|
adapter: oracle_enhanced
|
|
@@ -48,7 +50,7 @@ ibm_db:
|
|
|
48
50
|
database: arelx_test
|
|
49
51
|
mssql:
|
|
50
52
|
adapter: sqlserver
|
|
51
|
-
host: localhost
|
|
53
|
+
host: <%= ENV.fetch('MSSQL_HOST', 'localhost') %>
|
|
52
54
|
database: master
|
|
53
55
|
username: sa
|
|
54
56
|
password: Password12!
|
data/test/real_db_test.rb
CHANGED
|
@@ -6,9 +6,9 @@ $:.unshift "#{File.dirname(__FILE__)}../../lib"
|
|
|
6
6
|
require 'arel_extensions'
|
|
7
7
|
|
|
8
8
|
def setup_db
|
|
9
|
-
ActiveRecord::Base.configurations =
|
|
9
|
+
ActiveRecord::Base.configurations = ConfigLoader.load('test/database.yml')
|
|
10
10
|
ActiveRecord::Base.establish_connection(ENV['DB'].try(:to_sym) || (RUBY_PLATFORM == 'java' ? :"jdbc-sqlite" : :sqlite))
|
|
11
|
-
if
|
|
11
|
+
if ACTIVE_RECORD_VERSION >= V7_0
|
|
12
12
|
ActiveRecord.default_timezone = :utc
|
|
13
13
|
else
|
|
14
14
|
ActiveRecord::Base.default_timezone = :utc
|
data/test/support/fake_record.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'arel_extensions/constants'
|
|
2
|
+
|
|
1
3
|
module FakeRecord
|
|
2
4
|
class Column < Struct.new(:name, :type)
|
|
3
5
|
end
|
|
@@ -146,7 +148,7 @@ module FakeRecord
|
|
|
146
148
|
connection_pool.connection
|
|
147
149
|
end
|
|
148
150
|
|
|
149
|
-
if
|
|
151
|
+
if ArelExtensions::ACTIVE_RECORD_VERSION >= ArelExtensions::V7_2
|
|
150
152
|
def with_connection(*args, **kwargs, &block)
|
|
151
153
|
connection_pool.with_connection(*args, **kwargs, &block)
|
|
152
154
|
end
|
|
@@ -15,7 +15,7 @@ module ArelExtensions
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def compile node
|
|
18
|
-
if
|
|
18
|
+
if AREL_VERSION > V5
|
|
19
19
|
@visitor.accept(node, Arel::Collectors::SQLString.new).value
|
|
20
20
|
else
|
|
21
21
|
@visitor.accept(node)
|
|
@@ -23,7 +23,7 @@ module ArelExtensions
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it 'should import large set of data in Oracle' do
|
|
26
|
-
insert_manager =
|
|
26
|
+
insert_manager = AREL_VERSION > V6 ? Arel::InsertManager.new.into(@table) : Arel::InsertManager.new(@conn).into(@table)
|
|
27
27
|
insert_manager.bulk_insert(@cols, @data)
|
|
28
28
|
_(compile(insert_manager.ast))
|
|
29
29
|
.must_be_like %Q[INSERT INTO "users" ("name", "comments", "created_at")
|
|
@@ -16,7 +16,7 @@ module ArelExtensions
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def compile node
|
|
19
|
-
if
|
|
19
|
+
if AREL_VERSION > V5
|
|
20
20
|
@visitor.accept(node, Arel::Collectors::SQLString.new).value
|
|
21
21
|
else
|
|
22
22
|
@visitor.accept(node)
|
|
@@ -24,7 +24,7 @@ module ArelExtensions
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it 'should import large set of data' do
|
|
27
|
-
insert_manager =
|
|
27
|
+
insert_manager = AREL_VERSION > V6 ? Arel::InsertManager.new.into(@table) : Arel::InsertManager.new(@conn).into(@table)
|
|
28
28
|
insert_manager.bulk_insert(@cols, @data)
|
|
29
29
|
_(compile(insert_manager.ast))
|
|
30
30
|
.must_be_like %Q[INSERT INTO "users" ("id", "name", "comments", "created_at")
|
|
@@ -115,7 +115,7 @@ module ArelExtensions
|
|
|
115
115
|
# puts (c.length.round + 42).inspect
|
|
116
116
|
_(compile(c.length.round + 42)).must_be_like %{(ROUND(LENGTH("users"."name")) + 42)}
|
|
117
117
|
_(compile(c.locate('test'))).must_be_like %{LOCATE('test', "users"."name")}
|
|
118
|
-
_(compile(c & 42)).must_be_like %{FIND_IN_SET(42, "users"."name")}
|
|
118
|
+
_(compile(c & 42)).must_be_like %{FIND_IN_SET('42', "users"."name")}
|
|
119
119
|
|
|
120
120
|
_(compile((c >= 'test').as('new_name'))).must_be_like %{("users"."name" >= 'test') AS new_name}
|
|
121
121
|
_(compile(c <= @table[:comments])).must_be_like %{"users"."name" <= "users"."comments"}
|