arel_extensions 2.0.19 → 2.0.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/arel_extensions.gemspec +1 -1
- data/gemspecs/arel_extensions-v1.gemspec +1 -1
- data/gemspecs/arel_extensions-v2.gemspec +1 -1
- data/lib/arel_extensions/insert_manager.rb +19 -17
- data/lib/arel_extensions/math.rb +16 -16
- data/lib/arel_extensions/nodes/case.rb +4 -0
- data/lib/arel_extensions/nodes/cast.rb +1 -1
- data/lib/arel_extensions/nodes/function.rb +4 -2
- data/lib/arel_extensions/nodes/json.rb +3 -1
- data/lib/arel_extensions/nodes/length.rb +6 -0
- data/lib/arel_extensions/nodes/replace.rb +0 -8
- data/lib/arel_extensions/nodes/union.rb +1 -1
- data/lib/arel_extensions/nodes/union_all.rb +1 -1
- data/lib/arel_extensions/string_functions.rb +10 -2
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/mssql.rb +1 -1
- data/lib/arel_extensions/visitors/oracle.rb +2 -2
- data/lib/arel_extensions/visitors/oracle12.rb +0 -12
- data/lib/arel_extensions/visitors/postgresql.rb +6 -6
- data/lib/arel_extensions/visitors/to_sql.rb +7 -7
- data/lib/arel_extensions/visitors.rb +9 -1
- data/lib/arel_extensions.rb +44 -10
- data/test/visitors/test_to_sql.rb +2 -2
- data/test/with_ar/all_agnostic_test.rb +0 -1
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbeb1b141db51f78567bf26939ecb75832dd1c3e524407bf11a56308d8da6d14
|
4
|
+
data.tar.gz: 543d1893d29e871ebfa9ccdc8e49179cbedf49cd5ccf6b082113925bedffbc81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4957e64d63412917884f8cc79b42b81643a7e512f4a0e0ef2331672f34cf625b1cec88dbefdf3e3c65d8fca63e2258dc0ff56d8e96964a392c12a89657756c9
|
7
|
+
data.tar.gz: 2d090ca797080248a3a44521cdae686e721e627c787fa971e340c2b9dc08b91e51992fd47265aad6ccf0bee2d73c8a2e72ad5681fe09844008f5e21577a2d8ce
|
data/arel_extensions.gemspec
CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_dependency('activerecord', '>= 6.0')
|
24
24
|
|
25
25
|
s.add_development_dependency('minitest', '~> 5.9')
|
26
|
-
s.add_development_dependency('rdoc', '
|
26
|
+
s.add_development_dependency('rdoc', '>= 6.3.1')
|
27
27
|
s.add_development_dependency('rake', '~> 12.3.3')
|
28
28
|
end
|
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_dependency('arel', '>= 6.0')
|
24
24
|
|
25
25
|
s.add_development_dependency('minitest', '~> 5.9')
|
26
|
-
s.add_development_dependency('rdoc', '
|
26
|
+
s.add_development_dependency('rdoc', '>= 6.3.1')
|
27
27
|
s.add_development_dependency('rake', '~> 12.3.3')
|
28
28
|
end
|
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_dependency('activerecord', '>= 6.0')
|
24
24
|
|
25
25
|
s.add_development_dependency('minitest', '~> 5.9')
|
26
|
-
s.add_development_dependency('rdoc', '
|
26
|
+
s.add_development_dependency('rdoc', '>= 6.3.1')
|
27
27
|
s.add_development_dependency('rake', '~> 12.3.3')
|
28
28
|
end
|
@@ -3,23 +3,25 @@ require 'arel'
|
|
3
3
|
module ArelExtensions
|
4
4
|
module InsertManager
|
5
5
|
def bulk_insert(cols, data)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
6
|
+
raise ArgumentError, "cols must be present" if cols.blank?
|
7
|
+
columns =
|
8
|
+
case cols.first
|
9
|
+
when Array
|
10
|
+
case cols.first.first
|
11
|
+
when Arel::Attributes::Attribute
|
12
|
+
cols
|
13
|
+
when String, Symbol
|
14
|
+
cols.map {|c| [@ast.relation[c.first]] }
|
15
|
+
else
|
16
|
+
raise ArgumentError, "cols has an invalid type: #{cols.first.first.class}"
|
17
|
+
end
|
18
|
+
when String, Symbol
|
19
|
+
cols.map { |c| @ast.relation[c] }
|
20
|
+
else
|
21
|
+
raise ArgumentError, "cols has an invalid type: #{cols.first.class}"
|
22
|
+
end
|
23
|
+
self.values = BulkValues.new(columns, data)
|
24
|
+
@ast.columns = columns
|
23
25
|
end
|
24
26
|
|
25
27
|
class BulkValues < Arel::Nodes::Node
|
data/lib/arel_extensions/math.rb
CHANGED
@@ -22,21 +22,21 @@ module ArelExtensions
|
|
22
22
|
if self.expr.left.is_a?(String) || self.expr.right.is_a?(String)
|
23
23
|
return self.concat(other)
|
24
24
|
else
|
25
|
-
return Arel
|
25
|
+
return Arel.grouping(Arel::Nodes::Addition.new self, other)
|
26
26
|
end
|
27
27
|
when ArelExtensions::Nodes::Function,ArelExtensions::Nodes::Case
|
28
28
|
return case self.return_type
|
29
29
|
when :string, :text
|
30
30
|
self.concat(other)
|
31
31
|
when :integer, :decimal, :float, :number, :int
|
32
|
-
Arel
|
32
|
+
Arel.grouping(Arel::Nodes::Addition.new self, other)
|
33
33
|
when :date, :datetime
|
34
34
|
ArelExtensions::Nodes::DateAdd.new [self, other]
|
35
35
|
else
|
36
36
|
self.concat(other)
|
37
37
|
end
|
38
38
|
when Arel::Nodes::Function
|
39
|
-
Arel
|
39
|
+
Arel.grouping(Arel::Nodes::Addition.new self, other)
|
40
40
|
else
|
41
41
|
begin
|
42
42
|
col = Arel::Table.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s]
|
@@ -44,15 +44,15 @@ module ArelExtensions
|
|
44
44
|
col = nil
|
45
45
|
end
|
46
46
|
if (!col) # if the column doesn't exist in the database
|
47
|
-
Arel
|
47
|
+
Arel.grouping(Arel::Nodes::Addition.new(self, other))
|
48
48
|
else
|
49
49
|
arg = col.type
|
50
50
|
if arg == :integer || (!arg)
|
51
51
|
other = other.to_i if other.is_a?(String)
|
52
|
-
Arel
|
52
|
+
Arel.grouping(Arel::Nodes::Addition.new self, other)
|
53
53
|
elsif arg == :decimal || arg == :float
|
54
54
|
other = Arel.sql(other) if other.is_a?(String) # Arel should accept Float & BigDecimal!
|
55
|
-
Arel
|
55
|
+
Arel.grouping(Arel::Nodes::Addition.new self, other)
|
56
56
|
elsif arg == :datetime || arg == :date
|
57
57
|
ArelExtensions::Nodes::DateAdd.new [self, other]
|
58
58
|
elsif arg == :string || arg == :text
|
@@ -68,23 +68,23 @@ module ArelExtensions
|
|
68
68
|
case self
|
69
69
|
when Arel::Nodes::Grouping
|
70
70
|
if self.expr.left.is_a?(Date) || self.expr.left.is_a?(DateTime)
|
71
|
-
Arel
|
71
|
+
Arel.grouping(ArelExtensions::Nodes::DateSub.new [self, other])
|
72
72
|
else
|
73
|
-
Arel
|
73
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other))
|
74
74
|
end
|
75
75
|
when ArelExtensions::Nodes::Function, ArelExtensions::Nodes::Case
|
76
76
|
case self.return_type
|
77
77
|
when :string, :text # ???
|
78
|
-
Arel
|
78
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other)) # ??
|
79
79
|
when :integer, :decimal, :float, :number
|
80
|
-
Arel
|
80
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other))
|
81
81
|
when :date, :datetime
|
82
82
|
ArelExtensions::Nodes::DateSub.new [self, other]
|
83
83
|
else
|
84
|
-
Arel
|
84
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other))
|
85
85
|
end
|
86
86
|
when Arel::Nodes::Function
|
87
|
-
Arel
|
87
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other))
|
88
88
|
else
|
89
89
|
begin
|
90
90
|
col = Arel::Table.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s]
|
@@ -92,7 +92,7 @@ module ArelExtensions
|
|
92
92
|
col = nil
|
93
93
|
end
|
94
94
|
if (!col) # if the column doesn't exist in the database
|
95
|
-
Arel
|
95
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other))
|
96
96
|
else
|
97
97
|
arg = col.type
|
98
98
|
if (arg == :date || arg == :datetime)
|
@@ -123,11 +123,11 @@ module ArelExtensions
|
|
123
123
|
else
|
124
124
|
case other
|
125
125
|
when Integer, Float, BigDecimal
|
126
|
-
Arel
|
126
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.sql(other.to_s)))
|
127
127
|
when String
|
128
|
-
Arel
|
128
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.sql(other)))
|
129
129
|
else
|
130
|
-
Arel
|
130
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other))
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
@@ -52,7 +52,9 @@ module ArelExtensions
|
|
52
52
|
case att
|
53
53
|
when Arel::Attributes::Attribute
|
54
54
|
begin
|
55
|
-
Arel::Table.engine.connection.
|
55
|
+
if Arel::Table.engine.connection.tables.include? att.relation.table_name
|
56
|
+
Arel::Table.engine.connection.schema_cache.columns_hash(att.relation.table_name)[att.name.to_s].type
|
57
|
+
end
|
56
58
|
rescue
|
57
59
|
att
|
58
60
|
end
|
@@ -80,7 +82,7 @@ module ArelExtensions
|
|
80
82
|
when ActiveSupport::Duration
|
81
83
|
Arel.sql(object.to_i)
|
82
84
|
when Array
|
83
|
-
Arel
|
85
|
+
Arel.grouping(object.map{|e| convert_to_node(e)})
|
84
86
|
else
|
85
87
|
raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
|
86
88
|
end
|
@@ -10,10 +10,6 @@ module ArelExtensions
|
|
10
10
|
@substitute = convert_to_node(substitute)
|
11
11
|
super([@left,@pattern,@substitute])
|
12
12
|
end
|
13
|
-
|
14
|
-
def +(other)
|
15
|
-
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
16
|
-
end
|
17
13
|
end
|
18
14
|
|
19
15
|
class RegexpReplace < Function
|
@@ -26,10 +22,6 @@ module ArelExtensions
|
|
26
22
|
@substitute = convert_to_node(substitute)
|
27
23
|
super([@left,@pattern,@substitute])
|
28
24
|
end
|
29
|
-
|
30
|
-
def +(other)
|
31
|
-
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
32
|
-
end
|
33
25
|
end
|
34
26
|
end
|
35
27
|
end
|
@@ -14,7 +14,7 @@ module ArelExtensions
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def as other
|
17
|
-
Arel::Nodes::TableAlias.new Arel
|
17
|
+
Arel::Nodes::TableAlias.new Arel.grouping(self), Arel::Nodes::SqlLiteral.new(other.to_s)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -10,7 +10,7 @@ module ArelExtensions
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def as other
|
13
|
-
Arel::Nodes::TableAlias.new Arel
|
13
|
+
Arel::Nodes::TableAlias.new Arel.grouping(self), Arel::Nodes::SqlLiteral.new(other.to_s)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -24,9 +24,17 @@ module ArelExtensions
|
|
24
24
|
ArelExtensions::Nodes::FindInSet.new [other, self]
|
25
25
|
end
|
26
26
|
|
27
|
-
# LENGTH function returns the length of the value in a text field.
|
27
|
+
# LENGTH function returns the length (bytewise) of the value in a text field.
|
28
28
|
def length
|
29
|
-
ArelExtensions::Nodes::Length.new
|
29
|
+
ArelExtensions::Nodes::Length.new self, true
|
30
|
+
end
|
31
|
+
|
32
|
+
def byte_length
|
33
|
+
ArelExtensions::Nodes::Length.new self, true
|
34
|
+
end
|
35
|
+
|
36
|
+
def char_length
|
37
|
+
ArelExtensions::Nodes::Length.new self, false
|
30
38
|
end
|
31
39
|
|
32
40
|
# LOCATE function returns the first starting position of a string in another string.
|
@@ -5,7 +5,7 @@ module ArelExtensions
|
|
5
5
|
SPECIAL_CHARS = {"\t" => 'CHR(9)', "\n" => 'CHR(10)', "\r" => 'CHR(13)'}
|
6
6
|
DATE_MAPPING = {'d' => 'DAY', 'm' => 'MONTH', 'w' => 'IW', 'y' => 'YEAR', 'wd' => 'D', 'h' => 'HOUR', 'mn' => 'MINUTE', 's' => 'SECOND'}
|
7
7
|
DATE_FORMAT_DIRECTIVES = {
|
8
|
-
'%Y' => '
|
8
|
+
'%Y' => 'YYYY', '%C' => 'CC', '%y' => 'YY', '%m' => 'MM', '%B' => 'Month', '%^B' => 'MONTH', '%b' => 'Mon', '%^b' => 'MON',
|
9
9
|
'%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%A' => 'Day', # day, weekday
|
10
10
|
'%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours
|
11
11
|
'%M' => 'MI', '%S' => 'SS', '%L' => 'MS', '%N' => 'US', '%z' => 'tz' # seconds, subseconds
|
@@ -308,7 +308,7 @@ module ArelExtensions
|
|
308
308
|
end
|
309
309
|
|
310
310
|
def visit_ArelExtensions_Nodes_Length o, collector
|
311
|
-
collector << "LENGTH("
|
311
|
+
collector << "LENGTH#{o.bytewise ? 'B' : ''}("
|
312
312
|
collector = visit o.expr, collector
|
313
313
|
collector << ")"
|
314
314
|
collector
|
@@ -2,18 +2,6 @@ module ArelExtensions
|
|
2
2
|
module Visitors
|
3
3
|
Arel::Visitors.send(:remove_const,'Oracle12') if Arel::Visitors.const_defined?('Oracle12')
|
4
4
|
Arel::Visitors.const_set('Oracle12',Class.new(Arel::Visitors::Oracle)).class_eval do
|
5
|
-
def visit_Arel_Nodes_SelectStatement(o, collector)
|
6
|
-
# Oracle does not allow LIMIT clause with select for update
|
7
|
-
if o.limit && o.lock
|
8
|
-
raise ArgumentError, <<-MSG
|
9
|
-
'Combination of limit and lock is not supported.
|
10
|
-
because generated SQL statements
|
11
|
-
`SELECT FOR UPDATE and FETCH FIRST n ROWS` generates ORA-02014.`
|
12
|
-
MSG
|
13
|
-
end
|
14
|
-
|
15
|
-
super
|
16
|
-
end
|
17
5
|
|
18
6
|
def visit_Arel_Nodes_SelectOptions(o, collector)
|
19
7
|
collector = maybe_visit o.offset, collector
|
@@ -7,7 +7,7 @@ module ArelExtensions
|
|
7
7
|
}.freeze
|
8
8
|
|
9
9
|
DATE_FORMAT_DIRECTIVES = {
|
10
|
-
'%Y' => '
|
10
|
+
'%Y' => 'YYYY', '%C' => 'CC', '%y' => 'YY',
|
11
11
|
'%m' => 'MM', '%B' => 'Month', '%^B' => 'MONTH', '%b' => 'Mon', '%^b' => 'MON',
|
12
12
|
'%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%A' => 'Day', # day, weekday
|
13
13
|
'%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours
|
@@ -373,6 +373,8 @@ module ArelExtensions
|
|
373
373
|
Arel::Nodes::SqlLiteral.new('date')
|
374
374
|
when :binary
|
375
375
|
Arel::Nodes::SqlLiteral.new('binary')
|
376
|
+
when :jsonb
|
377
|
+
Arel::Nodes::SqlLiteral.new('jsonb')
|
376
378
|
else
|
377
379
|
Arel::Nodes::SqlLiteral.new(o.as_attr.to_s)
|
378
380
|
end
|
@@ -401,13 +403,13 @@ module ArelExtensions
|
|
401
403
|
ArelExtensions::Nodes::Concat.new([
|
402
404
|
Arel::Nodes::NamedFunction.new('TRIM',[
|
403
405
|
Arel::Nodes::NamedFunction.new('TO_CHAR',[
|
404
|
-
col.abs/Arel::Nodes.build_quoted(10).pow(col.abs.log10.floor),
|
406
|
+
Arel.when(col.not_eq 0).then(col.abs/Arel::Nodes.build_quoted(10).pow(col.abs.log10.floor)).else(1),
|
405
407
|
Arel::Nodes.build_quoted('FM'+nines_before+'"'+comma+'"V'+nines_after)
|
406
408
|
])]),
|
407
409
|
o.type,
|
408
410
|
Arel::Nodes::NamedFunction.new('TRIM',[
|
409
411
|
Arel::Nodes::NamedFunction.new('TO_CHAR',[
|
410
|
-
col.abs.log10.floor,
|
412
|
+
Arel.when(col.not_eq 0).then(col.abs.log10.floor).else(0),
|
411
413
|
Arel::Nodes.build_quoted('FM'+nines_before)
|
412
414
|
])])
|
413
415
|
])
|
@@ -511,8 +513,6 @@ module ArelExtensions
|
|
511
513
|
collector << '::jsonb'
|
512
514
|
when NilClass
|
513
515
|
collector << %Q['null'::jsonb]
|
514
|
-
when Arel::Attributes::Attribute
|
515
|
-
collector = visit o.dict.cast(:jsonb), collector
|
516
516
|
else
|
517
517
|
collector = visit o.dict, collector
|
518
518
|
collector << '::jsonb'
|
@@ -532,7 +532,7 @@ module ArelExtensions
|
|
532
532
|
|
533
533
|
def visit_ArelExtensions_Nodes_JsonGet o,collector
|
534
534
|
collector = visit o.dict, collector
|
535
|
-
collector << '
|
535
|
+
collector << ' ->> '
|
536
536
|
collector = visit o.key, collector
|
537
537
|
collector
|
538
538
|
end
|
@@ -117,7 +117,7 @@ module ArelExtensions
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def visit_ArelExtensions_Nodes_Length o, collector
|
120
|
-
collector << "LENGTH("
|
120
|
+
collector << "#{o.bytewise ? '' : 'CHAR_'}LENGTH("
|
121
121
|
collector = visit o.left, collector
|
122
122
|
collector << ")"
|
123
123
|
collector
|
@@ -601,20 +601,20 @@ module ArelExtensions
|
|
601
601
|
def json_value(o,v)
|
602
602
|
case o.type_of_node(v)
|
603
603
|
when :string
|
604
|
-
Arel.when(v.is_null).then(Arel
|
604
|
+
Arel.when(v.is_null).then(Arel.null).else(make_json_string(v))
|
605
605
|
when :date
|
606
606
|
s = v.format('%Y-%m-%d')
|
607
|
-
Arel.when(s.is_null).then(Arel
|
607
|
+
Arel.when(s.is_null).then(Arel.null).else(make_json_string(s))
|
608
608
|
when :datetime
|
609
609
|
s = v.format('%Y-%m-%dT%H:%M:%S')
|
610
|
-
Arel.when(s.is_null).then(Arel
|
610
|
+
Arel.when(s.is_null).then(Arel.null).else(make_json_string(s))
|
611
611
|
when :time
|
612
612
|
s = v.format('%H:%M:%S')
|
613
|
-
Arel.when(s.is_null).then(Arel
|
613
|
+
Arel.when(s.is_null).then(Arel.null).else(make_json_string(s))
|
614
614
|
when :nil
|
615
|
-
Arel
|
615
|
+
Arel.null
|
616
616
|
else
|
617
|
-
ArelExtensions::Nodes::Cast.new([v, :string]).coalesce(
|
617
|
+
ArelExtensions::Nodes::Cast.new([v, :string]).coalesce(Arel.null)
|
618
618
|
end
|
619
619
|
end
|
620
620
|
|
@@ -9,9 +9,17 @@ if defined?(Arel::Visitors::Oracle)
|
|
9
9
|
require 'arel_extensions/visitors/oracle12'
|
10
10
|
end
|
11
11
|
|
12
|
-
if defined?(Arel::Visitors::MSSQL)
|
12
|
+
if defined?(Arel::Visitors::SQLServer) || defined?(Arel::Visitors::MSSQL)
|
13
13
|
require 'arel_extensions/visitors/mssql'
|
14
|
+
end
|
14
15
|
|
16
|
+
if defined?(Arel::Visitors::SQLServer)
|
17
|
+
class Arel::Visitors::SQLServer
|
18
|
+
include ArelExtensions::Visitors::MSSQL
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if defined?(Arel::Visitors::MSSQL)
|
15
23
|
class Arel::Visitors::MSSQL
|
16
24
|
include ArelExtensions::Visitors::MSSQL
|
17
25
|
|
data/lib/arel_extensions.rb
CHANGED
@@ -33,6 +33,12 @@ class Arel::Nodes::Grouping
|
|
33
33
|
include Arel::OrderPredications
|
34
34
|
end
|
35
35
|
|
36
|
+
class Arel::Nodes::Ordering
|
37
|
+
def eql? other
|
38
|
+
self.hash.eql? other.hash
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
36
42
|
class Arel::Nodes::Function
|
37
43
|
include Arel::Math
|
38
44
|
include Arel::Expressions
|
@@ -82,11 +88,13 @@ module Arel
|
|
82
88
|
end
|
83
89
|
|
84
90
|
def self.json *expr
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
91
|
+
ArelExtensions::Nodes::Json.new(
|
92
|
+
if expr.length == 1
|
93
|
+
expr.first
|
94
|
+
else
|
95
|
+
expr
|
96
|
+
end
|
97
|
+
)
|
90
98
|
end
|
91
99
|
|
92
100
|
def self.when condition
|
@@ -94,20 +102,31 @@ module Arel
|
|
94
102
|
end
|
95
103
|
|
96
104
|
def self.duration s, expr
|
97
|
-
ArelExtensions::Nodes::Duration.new(s
|
105
|
+
ArelExtensions::Nodes::Duration.new("#{s}i", expr)
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.grouping *v
|
109
|
+
Arel::Nodes::Grouping.new(*v)
|
98
110
|
end
|
99
111
|
|
112
|
+
# The TRUE pseudo literal.
|
100
113
|
def self.true
|
101
|
-
Arel::Nodes::Equality.new(1,1)
|
114
|
+
Arel::Nodes::Equality.new(1, 1)
|
102
115
|
end
|
103
116
|
|
117
|
+
# The FALSE pseudo literal.
|
104
118
|
def self.false
|
105
|
-
Arel::Nodes::Equality.new(1,0)
|
119
|
+
Arel::Nodes::Equality.new(1, 0)
|
120
|
+
end
|
121
|
+
|
122
|
+
# The NULL literal.
|
123
|
+
def self.null
|
124
|
+
Arel::Nodes.build_quoted(nil)
|
106
125
|
end
|
107
126
|
|
108
127
|
def self.tuple *v
|
109
|
-
tmp = Arel
|
110
|
-
Arel
|
128
|
+
tmp = Arel.grouping(nil)
|
129
|
+
Arel.grouping v.map{|e| tmp.convert_to_node(e)}
|
111
130
|
end
|
112
131
|
end
|
113
132
|
|
@@ -134,6 +153,11 @@ class Arel::Nodes::Function
|
|
134
153
|
end
|
135
154
|
res
|
136
155
|
end
|
156
|
+
|
157
|
+
def xas other
|
158
|
+
Arel::Nodes::As.new(self, Arel.sql(other))
|
159
|
+
end
|
160
|
+
|
137
161
|
end
|
138
162
|
|
139
163
|
class Arel::Nodes::Grouping
|
@@ -152,6 +176,9 @@ class Arel::Nodes::Unary
|
|
152
176
|
include ArelExtensions::MathFunctions
|
153
177
|
include ArelExtensions::Comparators
|
154
178
|
include ArelExtensions::Predications
|
179
|
+
def eql? other
|
180
|
+
hash == other.hash
|
181
|
+
end
|
155
182
|
end
|
156
183
|
|
157
184
|
class Arel::Nodes::Binary
|
@@ -161,6 +188,9 @@ class Arel::Nodes::Binary
|
|
161
188
|
include ArelExtensions::Comparators
|
162
189
|
include ArelExtensions::BooleanFunctions
|
163
190
|
include ArelExtensions::Predications
|
191
|
+
def eql? other
|
192
|
+
hash == other.hash
|
193
|
+
end
|
164
194
|
end
|
165
195
|
|
166
196
|
class Arel::Nodes::Equality
|
@@ -177,6 +207,10 @@ end
|
|
177
207
|
class Arel::SelectManager
|
178
208
|
include ArelExtensions::SetFunctions
|
179
209
|
include ArelExtensions::Nodes
|
210
|
+
|
211
|
+
def as table_name
|
212
|
+
Arel::Nodes::TableAlias.new(self, table_name)
|
213
|
+
end
|
180
214
|
end
|
181
215
|
|
182
216
|
class Arel::Nodes::As
|
@@ -289,7 +289,7 @@ module ArelExtensions
|
|
289
289
|
_(compile((@table[:age] + 42).as('alias'))).must_be_like %{("users"."age" + 42) AS alias}
|
290
290
|
_(compile(@table[:name].coalesce('').as('alias'))).must_be_like %{COALESCE("users"."name", '') AS alias}
|
291
291
|
_(compile(Arel::Nodes.build_quoted('test').as('alias'))).must_be_like %{'test' AS alias}
|
292
|
-
_(compile(@table.project(@table[:name]).as('alias'))).must_be_like %{(SELECT "users"."name" FROM "users") alias}
|
292
|
+
_(compile(@table.project(@table[:name]).as('alias'))).must_be_like %{(SELECT "users"."name" FROM "users") "alias"}
|
293
293
|
_(compile(@table[:name].when("smith").then("cool").else("uncool").as('alias')))
|
294
294
|
.must_be_like %{CASE "users"."name" WHEN 'smith' THEN 'cool' ELSE 'uncool' END AS alias}
|
295
295
|
end
|
@@ -373,7 +373,7 @@ module ArelExtensions
|
|
373
373
|
end
|
374
374
|
|
375
375
|
it "should respecting Grouping" do
|
376
|
-
g = ->(*v) { Arel
|
376
|
+
g = ->(*v) { Arel.grouping(v) }
|
377
377
|
_(compile(g[@table[:id], @table[:age]].in [g[1, 42]]))
|
378
378
|
.must_be_like %{("users"."id", "users"."age") IN ((1, 42))}
|
379
379
|
_(compile(g[@table[:id], @table[:age]].in [g[1, 42], g[2, 51]]))
|
@@ -358,7 +358,6 @@ module ArelExtensions
|
|
358
358
|
|
359
359
|
def test_format
|
360
360
|
assert_equal '2016-05-23', t(@lucas, @created_at.format('%Y-%m-%d'))
|
361
|
-
skip "SQL Server does not accept any format" if @env_db == 'mssql'
|
362
361
|
assert_equal '2014/03/03 12:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S'))
|
363
362
|
assert_equal '12:42%', t(@lucas, @updated_at.format('%R%%'))
|
364
363
|
end
|
data/version_v1.rb
CHANGED
data/version_v2.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yann Azoury
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-01
|
13
|
+
date: 2021-12-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -44,16 +44,16 @@ dependencies:
|
|
44
44
|
name: rdoc
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - "
|
47
|
+
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
49
|
+
version: 6.3.1
|
50
50
|
type: :development
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - "
|
54
|
+
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
56
|
+
version: 6.3.1
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: rake
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
- !ruby/object:Gem::Version
|
223
223
|
version: '0'
|
224
224
|
requirements: []
|
225
|
-
rubygems_version: 3.0.
|
225
|
+
rubygems_version: 3.0.8
|
226
226
|
signing_key:
|
227
227
|
specification_version: 4
|
228
228
|
summary: Extending Arel
|