arel_extensions 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arel_extensions/nodes/json.rb +17 -12
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/mssql.rb +1 -1
- data/lib/arel_extensions/visitors/mysql.rb +12 -12
- data/lib/arel_extensions/visitors/oracle12.rb +58 -58
- data/lib/arel_extensions/visitors/postgresql.rb +12 -12
- data/lib/arel_extensions/visitors/to_sql.rb +39 -22
- data/test/visitors/test_oracle.rb +1 -1
- data/test/visitors/test_to_sql.rb +8 -8
- data/test/with_ar/all_agnostic_test.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d16042c9625c2efb1154a69f7717050b164269d
|
4
|
+
data.tar.gz: a9760058285052d730a80997691cbb1beeacc985
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42e83c94f94962e39052a624c772b88bdb5200a265b0dc062aed6f0cd76cb039b59797b3b163970742a80ac7db88b4648ebdec40739b153cffc798c9eabe046b
|
7
|
+
data.tar.gz: 31c805934070166c47f758f49732cd21efa56e1a7b4216edd443ed059e9039652789f431c3faa1cc2e40867849827270b9c485d0fdb790d57263e0e12062df5d
|
@@ -3,7 +3,7 @@ module ArelExtensions
|
|
3
3
|
class JsonNode < Function
|
4
4
|
RETURN_TYPE = :json
|
5
5
|
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :dict
|
7
7
|
|
8
8
|
def merge *expr
|
9
9
|
args = [self] + expr.map{|e| Json.new(e)}
|
@@ -22,6 +22,10 @@ module ArelExtensions
|
|
22
22
|
JsonGroup.new(self,as_array, orders)
|
23
23
|
end
|
24
24
|
|
25
|
+
def hash
|
26
|
+
[@dict].hash
|
27
|
+
end
|
28
|
+
|
25
29
|
end
|
26
30
|
|
27
31
|
class Json < JsonNode
|
@@ -30,30 +34,31 @@ module ArelExtensions
|
|
30
34
|
if expr.length == 1
|
31
35
|
case expr.first
|
32
36
|
when JsonNode
|
33
|
-
@
|
37
|
+
@dict = expr.first.dict
|
34
38
|
when Array
|
35
|
-
@
|
39
|
+
@dict = expr.first.map{|e|
|
36
40
|
(e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_node(e)
|
37
41
|
}
|
38
42
|
when Hash
|
39
|
-
@
|
43
|
+
@dict = expr.first.inject({}){|acc,v|
|
40
44
|
acc[convert_to_node(v[0])] = (v[1].is_a?(Array) || v[1].is_a?(Hash)) ? Json.new(v[1]) : convert_to_node(v[1])
|
41
45
|
acc
|
42
46
|
}
|
43
47
|
when String, Numeric, TrueClass, FalseClass
|
44
|
-
@
|
48
|
+
@dict = convert_to_node(expr.first)
|
45
49
|
when NilClass
|
46
|
-
@
|
50
|
+
@dict = Arel.sql('null')
|
47
51
|
else
|
48
52
|
if expr.first.is_a?(String) || (expr.first.is_a?(Arel::Attributes::Attribute) && type_of_attribute(expr.first) == :string) || (expr.first.return_type == :string)
|
49
|
-
@
|
53
|
+
@dict = convert_to_node(expr.first)
|
50
54
|
else
|
51
|
-
@
|
55
|
+
@dict = [convert_to_node(expr.first)]
|
52
56
|
end
|
53
57
|
end
|
54
58
|
else
|
55
|
-
@
|
59
|
+
@dict = expr.map{|e| (e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_node(e) }
|
56
60
|
end
|
61
|
+
super
|
57
62
|
end
|
58
63
|
|
59
64
|
end
|
@@ -65,7 +70,7 @@ module ArelExtensions
|
|
65
70
|
attr_accessor :as_array, :orders
|
66
71
|
|
67
72
|
def initialize json, as_array = true, orders = nil
|
68
|
-
@
|
73
|
+
@dict = as_array ? json : json.dict
|
69
74
|
@as_array = as_array
|
70
75
|
if orders
|
71
76
|
if orders.is_a?(Array)
|
@@ -81,7 +86,7 @@ module ArelExtensions
|
|
81
86
|
attr_accessor :key
|
82
87
|
|
83
88
|
def initialize json, key
|
84
|
-
@
|
89
|
+
@dict = json
|
85
90
|
@key = convert_to_node(key)
|
86
91
|
end
|
87
92
|
|
@@ -91,7 +96,7 @@ module ArelExtensions
|
|
91
96
|
attr_accessor :key, :value
|
92
97
|
|
93
98
|
def initialize json, key, value
|
94
|
-
@
|
99
|
+
@dict = json
|
95
100
|
@key = convert_to_node(key)
|
96
101
|
@value = Json.new(value)
|
97
102
|
end
|
@@ -517,7 +517,7 @@ module ArelExtensions
|
|
517
517
|
|
518
518
|
def visit_ArelExtensions_Nodes_JsonGet o,collector
|
519
519
|
collector << 'JSON_VALUE('
|
520
|
-
collector = visit o.
|
520
|
+
collector = visit o.dict, collector
|
521
521
|
collector << Arel::Visitors::MySQL::COMMA
|
522
522
|
if o.key.is_a?(Integer)
|
523
523
|
collector << "\"$[#{o.key}]\""
|
@@ -402,10 +402,10 @@ module ArelExtensions
|
|
402
402
|
|
403
403
|
def visit_ArelExtensions_Nodes_Json o,collector
|
404
404
|
return super if !json_supported?
|
405
|
-
case o.
|
405
|
+
case o.dict
|
406
406
|
when Array
|
407
407
|
collector << 'JSON_ARRAY('
|
408
|
-
o.
|
408
|
+
o.dict.each.with_index do |v,i|
|
409
409
|
if i != 0
|
410
410
|
collector << Arel::Visitors::MySQL::COMMA
|
411
411
|
end
|
@@ -414,7 +414,7 @@ module ArelExtensions
|
|
414
414
|
collector << ')'
|
415
415
|
when Hash
|
416
416
|
collector << 'JSON_OBJECT('
|
417
|
-
o.
|
417
|
+
o.dict.each.with_index do |(k,v),i|
|
418
418
|
if i != 0
|
419
419
|
collector << Arel::Visitors::MySQL::COMMA
|
420
420
|
end
|
@@ -424,7 +424,7 @@ module ArelExtensions
|
|
424
424
|
end
|
425
425
|
collector << ')'
|
426
426
|
else
|
427
|
-
collector = visit o.
|
427
|
+
collector = visit o.dict, collector
|
428
428
|
end
|
429
429
|
collector
|
430
430
|
end
|
@@ -443,7 +443,7 @@ module ArelExtensions
|
|
443
443
|
|
444
444
|
def visit_ArelExtensions_Nodes_JsonGet o,collector
|
445
445
|
collector << 'JSON_EXTRACT('
|
446
|
-
collector = visit o.
|
446
|
+
collector = visit o.dict, collector
|
447
447
|
collector << Arel::Visitors::MySQL::COMMA
|
448
448
|
if o.key.is_a?(Integer)
|
449
449
|
collector << "\"$[#{o.key}]\""
|
@@ -456,7 +456,7 @@ module ArelExtensions
|
|
456
456
|
|
457
457
|
def visit_ArelExtensions_Nodes_JsonSet o,collector
|
458
458
|
collector << 'JSON_SET('
|
459
|
-
collector = visit o.
|
459
|
+
collector = visit o.dict, collector
|
460
460
|
collector << Arel::Visitors::MySQL::COMMA
|
461
461
|
if o.key.is_a?(Integer)
|
462
462
|
collector << "\"$[#{o.key}]\""
|
@@ -473,13 +473,13 @@ module ArelExtensions
|
|
473
473
|
return super if !json_supported?
|
474
474
|
if o.as_array
|
475
475
|
collector << 'JSON_ARRAYAGG('
|
476
|
-
collector = visit o.
|
476
|
+
collector = visit o.dict, collector
|
477
477
|
collector << ')'
|
478
478
|
else
|
479
|
-
case o.
|
479
|
+
case o.dict
|
480
480
|
when Hash
|
481
|
-
collector << 'JSON_MERGE_PATCH(' if o.
|
482
|
-
o.
|
481
|
+
collector << 'JSON_MERGE_PATCH(' if o.dict.length > 1
|
482
|
+
o.dict.each.with_index do |(k,v),i|
|
483
483
|
if i != 0
|
484
484
|
collector << Arel::Visitors::MySQL::COMMA
|
485
485
|
end
|
@@ -489,10 +489,10 @@ module ArelExtensions
|
|
489
489
|
collector = visit v, collector
|
490
490
|
collector << ')'
|
491
491
|
end
|
492
|
-
collector << ')' if o.
|
492
|
+
collector << ')' if o.dict.length > 1
|
493
493
|
else
|
494
494
|
collector << 'JSON_OBJECTAGG('
|
495
|
-
collector = visit o.
|
495
|
+
collector = visit o.dict, collector
|
496
496
|
collector << ')'
|
497
497
|
end
|
498
498
|
end
|
@@ -1,70 +1,70 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Visitors
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
4
|
+
Arel::Visitors.send(:remove_const,'Oracle12') if Arel::Visitors.const_defined?('Oracle12')
|
5
|
+
Arel::Visitors.const_set('Oracle12',Class.new(Arel::Visitors::Oracle)).class_eval do
|
6
|
+
def visit_Arel_Nodes_SelectStatement(o, collector)
|
7
|
+
# Oracle does not allow LIMIT clause with select for update
|
8
|
+
if o.limit && o.lock
|
9
|
+
raise ArgumentError, <<-MSG
|
10
|
+
'Combination of limit and lock is not supported.
|
11
|
+
because generated SQL statements
|
12
|
+
`SELECT FOR UPDATE and FETCH FIRST n ROWS` generates ORA-02014.`
|
13
|
+
MSG
|
14
|
+
end
|
15
|
+
super
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
def visit_Arel_Nodes_SelectOptions(o, collector)
|
19
|
+
collector = maybe_visit o.offset, collector
|
20
|
+
collector = maybe_visit o.limit, collector
|
21
|
+
maybe_visit o.lock, collector
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
def visit_Arel_Nodes_Limit(o, collector)
|
25
|
+
collector << "FETCH FIRST "
|
26
|
+
collector = visit o.expr, collector
|
27
|
+
collector << " ROWS ONLY"
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
def visit_Arel_Nodes_Offset(o, collector)
|
31
|
+
collector << "OFFSET "
|
32
|
+
visit o.expr, collector
|
33
|
+
collector << " ROWS"
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
def visit_Arel_Nodes_Except(o, collector)
|
37
|
+
collector << "( "
|
38
|
+
collector = infix_value o, collector, " MINUS "
|
39
|
+
collector << " )"
|
40
|
+
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
42
|
+
def visit_Arel_Nodes_UpdateStatement(o, collector)
|
43
|
+
# Oracle does not allow ORDER BY/LIMIT in UPDATEs.
|
44
|
+
if o.orders.any? && o.limit.nil?
|
45
|
+
# However, there is no harm in silently eating the ORDER BY clause if no LIMIT has been provided,
|
46
|
+
# otherwise let the user deal with the error
|
47
|
+
o = o.dup
|
48
|
+
o.orders = []
|
49
|
+
end
|
50
|
+
super
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
+
def visit_Arel_Nodes_BindParam(o, collector)
|
54
|
+
collector.add_bind(o.value) { |i| ":a#{i}" }
|
55
|
+
end
|
53
56
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
def is_distinct_from(o, collector)
|
58
|
+
collector << "DECODE("
|
59
|
+
collector = visit [o.left, o.right, 0, 1], collector
|
60
|
+
collector << ")"
|
61
|
+
end
|
57
62
|
|
58
|
-
def is_distinct_from(o, collector)
|
59
|
-
collector << "DECODE("
|
60
|
-
collector = visit [o.left, o.right, 0, 1], collector
|
61
|
-
collector << ")"
|
62
|
-
end
|
63
63
|
def visit_ArelExtensions_Nodes_Json o,collector
|
64
|
-
case o.
|
64
|
+
case o.dict
|
65
65
|
when Array
|
66
66
|
collector << 'json_array('
|
67
|
-
o.
|
67
|
+
o.dict.each.with_index do |v,i|
|
68
68
|
if i != 0
|
69
69
|
collector << Arel::Visitors::MySQL::COMMA
|
70
70
|
end
|
@@ -73,7 +73,7 @@ module ArelExtensions
|
|
73
73
|
collector << ')'
|
74
74
|
when Hash
|
75
75
|
collector << 'json__object('
|
76
|
-
o.
|
76
|
+
o.dict.each.with_index do |(k,v),i|
|
77
77
|
if i != 0
|
78
78
|
collector << Arel::Visitors::MySQL::COMMA
|
79
79
|
end
|
@@ -85,19 +85,19 @@ module ArelExtensions
|
|
85
85
|
end
|
86
86
|
collector << ')'
|
87
87
|
when String,Numeric,TrueClass,FalseClass
|
88
|
-
collector = visit Arel::Nodes.build_quoted("#{o.
|
88
|
+
collector = visit Arel::Nodes.build_quoted("#{o.dict}"), collector
|
89
89
|
collector << ' FORMAT JSON'
|
90
90
|
when NilClass
|
91
91
|
collector << %Q['null' FORMAT JSON]
|
92
92
|
when Arel::Attributes::Attribute
|
93
|
-
collector = visit o.
|
93
|
+
collector = visit o.dict.cast('JSON'), collector
|
94
94
|
else
|
95
|
-
collector = visit o.
|
95
|
+
collector = visit o.dict, collector
|
96
96
|
collector << ' FORMAT JSON'
|
97
97
|
end
|
98
98
|
collector
|
99
99
|
end
|
100
100
|
|
101
|
-
|
101
|
+
end
|
102
102
|
end
|
103
103
|
end
|
@@ -405,10 +405,10 @@ module ArelExtensions
|
|
405
405
|
end
|
406
406
|
|
407
407
|
def visit_ArelExtensions_Nodes_Json o,collector
|
408
|
-
case o.
|
408
|
+
case o.dict
|
409
409
|
when Array
|
410
410
|
collector << 'to_jsonb(array['
|
411
|
-
o.
|
411
|
+
o.dict.each.with_index do |v,i|
|
412
412
|
if i != 0
|
413
413
|
collector << Arel::Visitors::MySQL::COMMA
|
414
414
|
end
|
@@ -417,7 +417,7 @@ module ArelExtensions
|
|
417
417
|
collector << '])'
|
418
418
|
when Hash
|
419
419
|
collector << 'jsonb_build_object('
|
420
|
-
o.
|
420
|
+
o.dict.each.with_index do |(k,v),i|
|
421
421
|
if i != 0
|
422
422
|
collector << Arel::Visitors::MySQL::COMMA
|
423
423
|
end
|
@@ -427,14 +427,14 @@ module ArelExtensions
|
|
427
427
|
end
|
428
428
|
collector << ')'
|
429
429
|
when String,Numeric,TrueClass,FalseClass
|
430
|
-
collector = visit Arel::Nodes.build_quoted("#{o.
|
430
|
+
collector = visit Arel::Nodes.build_quoted("#{o.dict}"), collector
|
431
431
|
collector << '::jsonb'
|
432
432
|
when NilClass
|
433
433
|
collector << %Q['null'::jsonb]
|
434
434
|
when Arel::Attributes::Attribute
|
435
|
-
collector = visit o.
|
435
|
+
collector = visit o.dict.cast(:jsonb), collector
|
436
436
|
else
|
437
|
-
collector = visit o.
|
437
|
+
collector = visit o.dict, collector
|
438
438
|
collector << '::jsonb'
|
439
439
|
end
|
440
440
|
collector
|
@@ -451,7 +451,7 @@ module ArelExtensions
|
|
451
451
|
end
|
452
452
|
|
453
453
|
def visit_ArelExtensions_Nodes_JsonGet o,collector
|
454
|
-
collector = visit o.
|
454
|
+
collector = visit o.dict, collector
|
455
455
|
collector << ' -> '
|
456
456
|
collector = visit o.key, collector
|
457
457
|
collector
|
@@ -459,7 +459,7 @@ module ArelExtensions
|
|
459
459
|
|
460
460
|
def visit_ArelExtensions_Nodes_JsonSet o,collector
|
461
461
|
collector << 'jsonb_set('
|
462
|
-
collector = visit o.
|
462
|
+
collector = visit o.dict, collector
|
463
463
|
collector << Arel::Visitors::MySQL::COMMA
|
464
464
|
collector << 'array['
|
465
465
|
collector = visit o.key, collector
|
@@ -474,12 +474,12 @@ module ArelExtensions
|
|
474
474
|
def visit_ArelExtensions_Nodes_JsonGroup o, collector
|
475
475
|
if o.as_array
|
476
476
|
collector << 'jsonb_agg('
|
477
|
-
collector = visit o.
|
477
|
+
collector = visit o.dict, collector
|
478
478
|
collector << ')'
|
479
479
|
else
|
480
|
-
case o.
|
480
|
+
case o.dict
|
481
481
|
when Hash
|
482
|
-
o.
|
482
|
+
o.dict.each.with_index do |(k,v),i|
|
483
483
|
if i != 0
|
484
484
|
collector << ' || '
|
485
485
|
end
|
@@ -491,7 +491,7 @@ module ArelExtensions
|
|
491
491
|
end
|
492
492
|
else
|
493
493
|
collector << 'jsonb_object_agg('
|
494
|
-
collector = visit o.
|
494
|
+
collector = visit o.dict, collector
|
495
495
|
collector << ')'
|
496
496
|
end
|
497
497
|
end
|
@@ -525,41 +525,58 @@ module ArelExtensions
|
|
525
525
|
|
526
526
|
alias_method :old_visit_Arel_Nodes_And, :visit_Arel_Nodes_And
|
527
527
|
def visit_Arel_Nodes_And o, collector
|
528
|
-
|
529
|
-
|
528
|
+
case o.children.length
|
529
|
+
when 0
|
530
|
+
collector << '1=1' # but this should not happen
|
531
|
+
when 1
|
532
|
+
collector = visit o.children[0], collector
|
530
533
|
else
|
534
|
+
collector << '('
|
531
535
|
o.children.each_with_index { |arg, i|
|
532
|
-
if i
|
533
|
-
collector << '('
|
534
|
-
else
|
536
|
+
if i != 0
|
535
537
|
collector << ') AND ('
|
536
538
|
end
|
537
539
|
collector = visit arg, collector
|
538
540
|
}
|
539
541
|
collector << ')'
|
540
|
-
collector
|
541
542
|
end
|
543
|
+
collector
|
542
544
|
end
|
543
545
|
|
544
546
|
def visit_ArelExtensions_Nodes_Or o, collector
|
545
|
-
|
546
|
-
|
547
|
-
|
547
|
+
case o.children.length
|
548
|
+
when 0
|
549
|
+
collector << '0=1' # but this should not happen
|
550
|
+
when 1
|
551
|
+
collector = visit o.children[0], collector
|
552
|
+
else
|
548
553
|
collector << '('
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
554
|
+
o.children.each_with_index { |arg, i|
|
555
|
+
if i != 0
|
556
|
+
collector << ') OR ('
|
557
|
+
end
|
558
|
+
collector = visit arg, collector
|
559
|
+
}
|
560
|
+
collector << ')'
|
561
|
+
end
|
562
|
+
collector
|
563
|
+
end
|
564
|
+
|
565
|
+
alias_method :old_visit_Arel_Nodes_Or, :visit_Arel_Nodes_Or
|
566
|
+
def visit_Arel_Nodes_Or o, collector
|
567
|
+
collector << '('
|
568
|
+
collector = visit o.left, collector
|
569
|
+
collector << ') OR ('
|
570
|
+
collector = visit o.right, collector
|
571
|
+
collector << ')'
|
555
572
|
collector
|
556
573
|
end
|
557
574
|
|
558
575
|
def visit_ArelExtensions_Nodes_Json o,collector
|
559
|
-
case o.
|
576
|
+
case o.dict
|
560
577
|
when Array
|
561
578
|
res = Arel::Nodes.build_quoted('[')
|
562
|
-
o.
|
579
|
+
o.dict.each.with_index do |v,i|
|
563
580
|
if i != 0
|
564
581
|
res += ', '
|
565
582
|
end
|
@@ -573,7 +590,7 @@ module ArelExtensions
|
|
573
590
|
collector = visit res, collector
|
574
591
|
when Hash
|
575
592
|
res = Arel::Nodes.build_quoted('{')
|
576
|
-
o.
|
593
|
+
o.dict.each.with_index do |(k,v),i|
|
577
594
|
if i != 0
|
578
595
|
res += ', '
|
579
596
|
end
|
@@ -587,19 +604,19 @@ module ArelExtensions
|
|
587
604
|
res += '}'
|
588
605
|
collector = visit res, collector
|
589
606
|
else
|
590
|
-
collector = visit o.
|
607
|
+
collector = visit o.dict, collector
|
591
608
|
end
|
592
609
|
collector
|
593
610
|
end
|
594
611
|
|
595
612
|
def visit_ArelExtensions_Nodes_JsonGroup o, collector
|
596
613
|
if o.as_array
|
597
|
-
res = Arel::Nodes.build_quoted('[') + (o.orders ? o.
|
614
|
+
res = Arel::Nodes.build_quoted('[') + (o.orders ? o.dict.group_concat(', ',o.orders) : o.dict.group_concat(', ')) + ']'
|
598
615
|
collector = visit res, collector
|
599
616
|
else
|
600
617
|
res = Arel::Nodes.build_quoted('{')
|
601
|
-
orders = o.orders || o.
|
602
|
-
o.
|
618
|
+
orders = o.orders || o.dict.keys
|
619
|
+
o.dict.each.with_index do |(k,v),i|
|
603
620
|
if i != 0
|
604
621
|
res = res + ', '
|
605
622
|
end
|
@@ -53,7 +53,7 @@ module ArelExtensions
|
|
53
53
|
compile(c =~ '^test$').must_be_like %{REGEXP_LIKE("users"."name", '^test$')}
|
54
54
|
compile(c !~ /\Ate\Dst\Z/).must_be_like %{NOT REGEXP_LIKE("users"."name", '^te[^0-9]st$')}
|
55
55
|
compile(c.imatches('%test%')).must_be_like %{LOWER("users"."name") LIKE LOWER('%test%')}
|
56
|
-
compile(c.imatches_any(['%test%', 't2'])).must_be_like %{(LOWER("users"."name") LIKE LOWER('%test%') OR LOWER("users"."name") LIKE LOWER('t2'))}
|
56
|
+
compile(c.imatches_any(['%test%', 't2'])).must_be_like %{((LOWER("users"."name") LIKE LOWER('%test%')) OR (LOWER("users"."name") LIKE LOWER('t2')))}
|
57
57
|
compile(c.idoes_not_match('%test%')).must_be_like %{LOWER("users"."name") NOT LIKE LOWER('%test%')}
|
58
58
|
end
|
59
59
|
|
@@ -90,7 +90,7 @@ module ArelExtensions
|
|
90
90
|
compile(c =~ /\Atest\Z/).must_be_like %{"users"."name" REGEXP '^test$'}
|
91
91
|
compile(c !~ /\Ate\Dst\Z/).must_be_like %{"users"."name" NOT REGEXP '^te[^0-9]st$'}
|
92
92
|
compile(c.imatches('%test%')).must_be_like %{"users"."name" ILIKE '%test%'}
|
93
|
-
compile(c.imatches_any(['%test%', 't2'])).must_be_like %{("users"."name" ILIKE '%test%' OR "users"."name" ILIKE 't2')}
|
93
|
+
compile(c.imatches_any(['%test%', 't2'])).must_be_like %{(("users"."name" ILIKE '%test%') OR ("users"."name" ILIKE 't2'))}
|
94
94
|
compile(c.idoes_not_match('%test%')).must_be_like %{"users"."name" NOT ILIKE '%test%'}
|
95
95
|
|
96
96
|
compile(c.substring(1)).must_be_like %{SUBSTRING("users"."name", 1)}
|
@@ -140,7 +140,7 @@ module ArelExtensions
|
|
140
140
|
compile(c =~ /\Atest\Z/).must_be_like %{"users"."name" REGEXP '^test$'}
|
141
141
|
compile(c !~ /\Ate\Dst\Z/).must_be_like %{"users"."name" NOT REGEXP '^te[^0-9]st$'}
|
142
142
|
compile(c.imatches('%test%')).must_be_like %{"users"."name" ILIKE '%test%'}
|
143
|
-
compile(c.imatches_any(['%test%', 't2'])).must_be_like %{("users"."name" ILIKE '%test%' OR "users"."name" ILIKE 't2')}
|
143
|
+
compile(c.imatches_any(['%test%', 't2'])).must_be_like %{(("users"."name" ILIKE '%test%') OR ("users"."name" ILIKE 't2'))}
|
144
144
|
compile(c.idoes_not_match('%test%')).must_be_like %{"users"."name" NOT ILIKE '%test%'}
|
145
145
|
end
|
146
146
|
|
@@ -322,9 +322,9 @@ module ArelExtensions
|
|
322
322
|
compile(@table[:id].in([nil]))
|
323
323
|
.must_be_like %{ISNULL("users"."id")}
|
324
324
|
compile(@table[:id].in([nil,1]))
|
325
|
-
.must_be_like %{ISNULL("users"."id") OR "users"."id" = 1}
|
325
|
+
.must_be_like %{(ISNULL("users"."id")) OR ("users"."id" = 1)}
|
326
326
|
compile(@table[:id].in([nil,1,2]))
|
327
|
-
.must_be_like %{ISNULL("users"."id") OR "users"."id" IN (1, 2)}
|
327
|
+
.must_be_like %{(ISNULL("users"."id")) OR ("users"."id" IN (1, 2))}
|
328
328
|
compile(@table[:id].in(1))
|
329
329
|
.must_be_like %{"users"."id" IN (1)}
|
330
330
|
compile(@table[:id].in([1]))
|
@@ -335,9 +335,9 @@ module ArelExtensions
|
|
335
335
|
|
336
336
|
it "should be possible to correctly use a Range on an IN" do
|
337
337
|
compile(@table[:id].in(1..4))
|
338
|
-
.must_be_like %{"users"."id" BETWEEN 1 AND 4}
|
338
|
+
.must_be_like %{"users"."id" BETWEEN (1) AND (4)}
|
339
339
|
compile(@table[:created_at].in(@date .. Date.new(2017, 3, 31))) # @date = Date.new(2016, 3, 31)
|
340
|
-
.must_be_like %{"users"."created_at" BETWEEN '2016-03-31' AND '2017-03-31'}
|
340
|
+
.must_be_like %{"users"."created_at" BETWEEN ('2016-03-31') AND ('2017-03-31')}
|
341
341
|
end
|
342
342
|
|
343
343
|
it "should be possible to add and substract as much as we want" do
|
@@ -378,9 +378,9 @@ module ArelExtensions
|
|
378
378
|
compile((c == 1).and([c == 2, c == 3])).
|
379
379
|
must_be_like %{("users"."id" = 1) AND ("users"."id" = 2) AND ("users"."id" = 3)}
|
380
380
|
compile((c == 1).or(c == 2, c == 3)).
|
381
|
-
must_be_like %{(
|
381
|
+
must_be_like %{("users"."id" = 1) OR ("users"."id" = 2) OR ("users"."id" = 3)}
|
382
382
|
compile((c == 1).or([c == 2, c == 3])).
|
383
|
-
must_be_like %{(
|
383
|
+
must_be_like %{("users"."id" = 1) OR ("users"."id" = 2) OR ("users"."id" = 3)}
|
384
384
|
end
|
385
385
|
|
386
386
|
puts "AREL VERSION : " + Arel::VERSION.to_s
|
@@ -721,7 +721,10 @@ module ArelExtensions
|
|
721
721
|
assert_equal ({"5" => "Lucas", "15" => "Sophie", "23" => "Myung", "25" => "Laure", "Laure"=>25, "Lucas"=>5, "Myung"=>23, "Sophie"=>15}),
|
722
722
|
parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16),Arel.json({@age => @name,@name => @age}).group(false)))
|
723
723
|
assert_equal ([{"5" => "Lucas"},{ "15" => "Sophie"},{ "23" => "Myung"},{ "25" => "Laure"}]),
|
724
|
-
parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16),Arel.json({@age => @name}).group(true,[@age])))
|
724
|
+
parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score),Arel.json({@age => @name}).group(true,[@age])))
|
725
|
+
|
726
|
+
#puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score,Arel.json({@age => @name}).group(true,[@age])).to_sql
|
727
|
+
#puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score,Arel.json({@age => @name}).group(true,[@age])).to_a
|
725
728
|
|
726
729
|
skip "Not Yet Implemented" if $sqlite || ['oracle','mssql'].include?(@env_db)
|
727
730
|
#get
|
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: 1.2.
|
4
|
+
version: 1.2.1
|
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: 2019-04-
|
13
|
+
date: 2019-04-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: arel
|