arel_extensions 2.0.1 → 2.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -4
- data/.travis.yml +59 -91
- data/Gemfile +14 -19
- data/README.md +17 -12
- data/Rakefile +38 -27
- data/appveyor.yml +1 -1
- data/arel_extensions.gemspec +2 -2
- data/functions.html +3 -3
- data/gemfiles/rails4.gemfile +1 -1
- data/gemfiles/rails6.gemfile +30 -0
- data/gemspec_v2/arel_extensions-v2.gemspec +28 -0
- data/generate_gems.sh +14 -0
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/postgresql.sql +21 -21
- data/lib/arel_extensions.rb +63 -19
- data/lib/arel_extensions/attributes.rb +0 -1
- data/lib/arel_extensions/boolean_functions.rb +38 -13
- data/lib/arel_extensions/common_sql_functions.rb +5 -4
- data/lib/arel_extensions/comparators.rb +4 -2
- data/lib/arel_extensions/insert_manager.rb +15 -13
- data/lib/arel_extensions/math.rb +3 -3
- data/lib/arel_extensions/math_functions.rb +10 -5
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/nodes/abs.rb +0 -0
- data/lib/arel_extensions/nodes/aggregate_function.rb +14 -0
- data/lib/arel_extensions/nodes/case.rb +8 -4
- data/lib/arel_extensions/nodes/ceil.rb +0 -0
- data/lib/arel_extensions/nodes/coalesce.rb +2 -2
- data/lib/arel_extensions/nodes/collate.rb +1 -1
- data/lib/arel_extensions/nodes/concat.rb +6 -13
- data/lib/arel_extensions/nodes/date_diff.rb +3 -5
- data/lib/arel_extensions/nodes/duration.rb +0 -2
- data/lib/arel_extensions/nodes/find_in_set.rb +0 -0
- data/lib/arel_extensions/nodes/floor.rb +0 -0
- data/lib/arel_extensions/nodes/format.rb +8 -8
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -23
- data/lib/arel_extensions/nodes/function.rb +2 -0
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +43 -30
- data/lib/arel_extensions/nodes/length.rb +0 -0
- data/lib/arel_extensions/nodes/locate.rb +0 -0
- data/lib/arel_extensions/nodes/matches.rb +4 -4
- data/lib/arel_extensions/nodes/power.rb +6 -5
- data/lib/arel_extensions/nodes/rand.rb +0 -0
- data/lib/arel_extensions/nodes/repeat.rb +2 -2
- data/lib/arel_extensions/nodes/replace.rb +24 -6
- data/lib/arel_extensions/nodes/round.rb +5 -5
- data/lib/arel_extensions/nodes/soundex.rb +16 -15
- data/lib/arel_extensions/nodes/std.rb +19 -21
- data/lib/arel_extensions/nodes/substring.rb +8 -15
- data/lib/arel_extensions/nodes/sum.rb +7 -0
- data/lib/arel_extensions/nodes/trim.rb +3 -3
- data/lib/arel_extensions/nodes/union.rb +2 -3
- data/lib/arel_extensions/nodes/union_all.rb +0 -1
- data/lib/arel_extensions/nodes/wday.rb +0 -0
- data/lib/arel_extensions/null_functions.rb +2 -2
- data/lib/arel_extensions/predications.rb +35 -33
- data/lib/arel_extensions/set_functions.rb +2 -2
- data/lib/arel_extensions/string_functions.rb +34 -12
- data/lib/arel_extensions/tasks.rb +5 -5
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors.rb +1 -1
- data/lib/arel_extensions/visitors/ibm_db.rb +1 -1
- data/lib/arel_extensions/visitors/mssql.rb +14 -13
- data/lib/arel_extensions/visitors/mysql.rb +89 -39
- data/lib/arel_extensions/visitors/oracle.rb +15 -15
- data/lib/arel_extensions/visitors/oracle12.rb +1 -1
- data/lib/arel_extensions/visitors/postgresql.rb +78 -32
- data/lib/arel_extensions/visitors/sqlite.rb +61 -53
- data/lib/arel_extensions/visitors/to_sql.rb +93 -73
- data/test/arelx_test_helper.rb +28 -0
- data/test/real_db_test.rb +1 -1
- data/test/support/fake_record.rb +1 -1
- data/test/test_comparators.rb +9 -8
- data/test/visitors/test_bulk_insert_oracle.rb +8 -7
- data/test/visitors/test_bulk_insert_sqlite.rb +9 -8
- data/test/visitors/test_bulk_insert_to_sql.rb +8 -10
- data/test/visitors/test_oracle.rb +41 -40
- data/test/visitors/test_to_sql.rb +367 -193
- data/test/with_ar/all_agnostic_test.rb +68 -35
- data/test/with_ar/insert_agnostic_test.rb +3 -2
- data/test/with_ar/test_bulk_sqlite.rb +6 -5
- data/test/with_ar/test_math_sqlite.rb +4 -4
- data/test/with_ar/test_string_mysql.rb +4 -6
- data/test/with_ar/test_string_sqlite.rb +3 -7
- data/version_v1.rb +3 -0
- data/version_v2.rb +3 -0
- metadata +14 -7
- data/test/helper.rb +0 -18
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'arelx_test_helper'
|
2
2
|
require 'date'
|
3
3
|
|
4
4
|
module ArelExtensions
|
@@ -68,7 +68,8 @@ module ArelExtensions
|
|
68
68
|
@test = User.where(:id => u.id)
|
69
69
|
u = User.create :age => -42, :name => "Negatif", :comments => '1,22,3,42,2', :created_at => d, :updated_at => d.to_time, :score => 0.17
|
70
70
|
@neg = User.where(:id => u.id)
|
71
|
-
|
71
|
+
u = User.create :age => 15, :name => "Justin", :created_at => d, :score => 11.0
|
72
|
+
@justin = User.where(:id => u.id)
|
72
73
|
|
73
74
|
@age = User.arel_table[:age]
|
74
75
|
@name = User.arel_table[:name]
|
@@ -121,6 +122,7 @@ module ArelExtensions
|
|
121
122
|
assert_equal(-20, t(@camille, @score.ceil)) # -20.16
|
122
123
|
assert_equal(-20, t(@camille, (@score - 0.5).ceil)) # -20.16
|
123
124
|
assert_equal 63, t(@arthur, @age.ceil + 42)
|
125
|
+
assert_equal 11, t(@justin, @score.ceil) # 11.0
|
124
126
|
end
|
125
127
|
|
126
128
|
def test_floor
|
@@ -129,12 +131,14 @@ module ArelExtensions
|
|
129
131
|
assert_equal 1, t(@test, @score.floor) # 1.62
|
130
132
|
assert_equal(-9, t(@test, (@score - 10).floor)) # 1.62
|
131
133
|
assert_equal 42, t(@arthur, @score.floor - 23)
|
134
|
+
assert_equal 11, t(@justin, @score.floor) # 11.0
|
135
|
+
assert_equal(-21, t(@camille, @score.floor)) # # -20.16
|
132
136
|
end
|
133
137
|
|
134
138
|
def test_rand
|
135
139
|
assert 42 != User.select(Arel.rand.as('res')).first.res
|
136
140
|
assert 0 <= User.select(Arel.rand.abs.as('res')).first.res
|
137
|
-
assert_equal
|
141
|
+
assert_equal 9, User.order(Arel.rand).limit(50).count
|
138
142
|
end
|
139
143
|
|
140
144
|
def test_round
|
@@ -147,15 +151,15 @@ module ArelExtensions
|
|
147
151
|
def test_sum
|
148
152
|
if @env_db == 'mssql'
|
149
153
|
skip "SQL Server forces order?" # TODO
|
150
|
-
assert_equal
|
151
|
-
assert_equal
|
152
|
-
assert_equal
|
153
|
-
assert_equal
|
154
|
+
assert_equal 83, User.select((@age.sum + 1).as("res"), User.arel_table[:id].sum).take(50).reorder(@age).first.res
|
155
|
+
assert_equal 164, User.reorder(nil).select((@age.sum + @age.sum).as("res"), User.arel_table[:id].sum).take(50).first.res
|
156
|
+
assert_equal 246, User.reorder(nil).select(((@age * 3).sum).as("res"), User.arel_table[:id].sum).take(50).first.res
|
157
|
+
assert_equal 4234, User.reorder(nil).select(((@age * @age).sum).as("res"), User.arel_table[:id].sum).take(50).first.res
|
154
158
|
else
|
155
|
-
assert_equal
|
156
|
-
assert_equal
|
157
|
-
assert_equal
|
158
|
-
assert_equal
|
159
|
+
assert_equal 83, User.select((@age.sum + 1).as("res")).take(50).first.res
|
160
|
+
assert_equal 164, User.select((@age.sum + @age.sum).as("res")).take(50).first.res
|
161
|
+
assert_equal 246, User.select((@age * 3).sum.as("res")).take(50).first.res
|
162
|
+
assert_equal 4234, User.select(((@age * @age).sum).as("res")).take(50).first.res
|
159
163
|
end
|
160
164
|
end
|
161
165
|
|
@@ -175,6 +179,7 @@ module ArelExtensions
|
|
175
179
|
assert_equal "Sophie,Lucas,Arthur", t(User.where(:name => ['Lucas', 'Sophie','Arthur']), @name.group_concat(',',@name.desc))
|
176
180
|
assert_equal "Lucas,Sophie,Arthur", t(User.where(:name => ['Lucas', 'Sophie','Arthur']), @name.group_concat(',',[@score.asc,@name.asc]))
|
177
181
|
assert_equal "Lucas,Sophie,Arthur", t(User.where(:name => ['Lucas', 'Sophie','Arthur']), @name.group_concat(',',@score.asc,@name.asc))
|
182
|
+
assert_equal "Lucas,Sophie,Arthur", t(User.where(:name => ['Lucas', 'Sophie','Arthur']), @name.group_concat(',',order: [@score.asc,@name.asc]))
|
178
183
|
end
|
179
184
|
|
180
185
|
def test_length
|
@@ -267,21 +272,28 @@ module ArelExtensions
|
|
267
272
|
skip "Sqlite version can't load extension for regexp" if $sqlite && $load_extension_disabled
|
268
273
|
skip "SQL Server does not know about REGEXP without extensions" if @env_db == 'mssql'
|
269
274
|
assert_equal 1, User.where(@name =~ '^M').count
|
270
|
-
assert_equal
|
275
|
+
assert_equal 7, User.where(@name !~ '^L').count
|
271
276
|
assert_equal 1, User.where(@name =~ /^M/).count
|
272
|
-
assert_equal
|
277
|
+
assert_equal 7, User.where(@name !~ /^L/).count
|
273
278
|
end
|
274
279
|
|
275
280
|
def test_imatches
|
276
281
|
#puts User.where(@name.imatches('m%')).to_sql
|
277
282
|
assert_equal 1, User.where(@name.imatches('m%')).count
|
278
283
|
assert_equal 4, User.where(@name.imatches_any(['L%', '%e'])).count
|
279
|
-
assert_equal
|
284
|
+
assert_equal 7, User.where(@name.idoes_not_match('L%')).count
|
280
285
|
end
|
281
286
|
|
282
287
|
def test_replace
|
283
288
|
assert_equal "LucaX", t(@lucas, @name.replace("s", "X"))
|
284
289
|
assert_equal "replace", t(@lucas, @name.replace(@name, "replace"))
|
290
|
+
|
291
|
+
skip "Sqlite does not seem to support regexp_replace" if $sqlite
|
292
|
+
skip "SQL Server does not know about REGEXP without extensions" if @env_db == 'mssql'
|
293
|
+
skip "Travis mysql version does not support REGEXP_REPLACE" if @env_db == 'mysql'
|
294
|
+
assert_equal "LXcXs", t(@lucas, @name.replace(/[ua]/, "X"))
|
295
|
+
assert_equal "LXcXs", t(@lucas, @name.regexp_replace(/[ua]/, "X"))
|
296
|
+
assert_equal "LXcXs", t(@lucas, @name.regexp_replace('[ua]', "X"))
|
285
297
|
end
|
286
298
|
|
287
299
|
def test_replace_once
|
@@ -294,8 +306,8 @@ module ArelExtensions
|
|
294
306
|
skip "Sqlite version can't load extension for soundex" if $sqlite && $load_extension_disabled
|
295
307
|
skip "PostgreSql version can't load extension for soundex" if @env_db == 'postgresql'
|
296
308
|
assert_equal "C540", t(@camille, @name.soundex)
|
297
|
-
assert_equal
|
298
|
-
assert_equal
|
309
|
+
assert_equal 9, User.where(@name.soundex.eq(@name.soundex)).count
|
310
|
+
assert_equal 9 , User.where(@name.soundex == @name.soundex).count
|
299
311
|
end
|
300
312
|
|
301
313
|
def test_change_case
|
@@ -374,13 +386,13 @@ module ArelExtensions
|
|
374
386
|
assert_equal 2, User.where(@age <= 10).count
|
375
387
|
assert_equal 3, User.where(@age > 20).count
|
376
388
|
assert_equal 4, User.where(@age >= 20).count
|
377
|
-
assert_equal
|
389
|
+
assert_equal 2, User.where(@age > 5).where(@age < 20).count
|
378
390
|
end
|
379
391
|
|
380
392
|
def test_date_comparator
|
381
393
|
d = Date.new(2016, 5, 23)
|
382
394
|
assert_equal 0, User.where(@created_at < d).count
|
383
|
-
assert_equal
|
395
|
+
assert_equal 9, User.where(@created_at >= d).count
|
384
396
|
end
|
385
397
|
|
386
398
|
def test_date_duration
|
@@ -389,10 +401,10 @@ module ArelExtensions
|
|
389
401
|
assert_equal 0, User.where(@created_at.year.eq("2012")).count
|
390
402
|
#Month
|
391
403
|
assert_equal 5, t(@camille, @created_at.month).to_i
|
392
|
-
assert_equal
|
404
|
+
assert_equal 9, User.where(@created_at.month.eq("05")).count
|
393
405
|
#Week
|
394
406
|
assert_equal(@env_db == 'mssql' ? 22 : 21, t(@arthur, @created_at.week).to_i)
|
395
|
-
assert_equal
|
407
|
+
assert_equal 9, User.where(@created_at.month.eq("05")).count
|
396
408
|
#Day
|
397
409
|
assert_equal 23, t(@laure, @created_at.day).to_i
|
398
410
|
assert_equal 0, User.where(@created_at.day.eq("05")).count
|
@@ -424,6 +436,7 @@ module ArelExtensions
|
|
424
436
|
end
|
425
437
|
end
|
426
438
|
|
439
|
+
|
427
440
|
skip "not yet implemented" if $sqlite
|
428
441
|
|
429
442
|
date1 = Date.new(2016, 5, 23)
|
@@ -467,15 +480,17 @@ module ArelExtensions
|
|
467
480
|
# TODO; cast types
|
468
481
|
def test_cast_types
|
469
482
|
assert_equal "5", t(@lucas, @age.cast(:string))
|
483
|
+
skip "jdbc adapters does not work properly here (v52 works fine)" if RUBY_PLATFORM =~ /java/i
|
470
484
|
if @env_db == 'mysql' || @env_db == 'postgresql' || @env_db == 'oracle' || @env_db == 'mssql'
|
471
|
-
assert_equal 1, t(@laure,
|
472
|
-
assert_equal 1, t(@laure,
|
485
|
+
assert_equal 1, t(@laure,Arel.when(@duration.cast(:time).cast(:string).eq("12:42:21")).then(1).else(0)) unless @env_db == 'oracle' || @env_db == 'mssql'
|
486
|
+
assert_equal 1, t(@laure,Arel.when(@duration.cast(:time).eq("12:42:21")).then(1).else(0)) unless @env_db == 'oracle'
|
473
487
|
assert_equal "20.16", t(@laure,@score.cast(:string)).gsub(/[0]*\z/,'')
|
474
488
|
assert_equal "20.161", t(@laure,@score.cast(:string)+1).gsub(/[0]*1\z/,'1')
|
475
489
|
assert_equal 21.16, t(@laure,@score.cast(:string).cast(:decimal)+1)
|
476
490
|
assert_equal 21, t(@laure,@score.cast(:string).cast(:int)+1)
|
477
491
|
|
478
492
|
assert_equal String, t(@lucas,@updated_at.cast(:string)).class
|
493
|
+
|
479
494
|
assert_equal Date, t(@lucas,@updated_at.cast(:date)).class unless @env_db == 'oracle' # DateTime
|
480
495
|
assert_equal Time, t(@lucas,@updated_at.cast(:string).cast(:datetime)).class
|
481
496
|
assert_equal Time, t(@lucas,@updated_at.cast(:time)).class
|
@@ -525,7 +540,7 @@ module ArelExtensions
|
|
525
540
|
def test_math_minus
|
526
541
|
d = Date.new(2016, 5, 20)
|
527
542
|
#Datediff
|
528
|
-
assert_equal
|
543
|
+
assert_equal 9, User.where((@created_at - @created_at).eq(0)).count
|
529
544
|
assert_equal 3, @laure.select((@created_at - d).as("res")).first.res.abs.to_i
|
530
545
|
#Substraction
|
531
546
|
assert_equal 0, User.where((@age - 10).eq(50)).count
|
@@ -566,6 +581,7 @@ module ArelExtensions
|
|
566
581
|
# Case clause
|
567
582
|
def test_case
|
568
583
|
assert_equal 4, User.find_by_sql(@ut.project(@score.when(20.16).then(1).else(0).as('score_bin')).to_sql).sum(&:score_bin)
|
584
|
+
assert_equal 4, User.where(@score.when(20.16).then(1).else(0).eq(1)).count
|
569
585
|
assert_equal 2, t(@arthur, @score.when(65.62,1).else(0)+1)
|
570
586
|
assert_equal 0, t(@arthur, @score.when(65.62,1).else(0)-1)
|
571
587
|
assert_equal "11", t(@arthur, @score.when(65.62).then("1").else("0")+"1")
|
@@ -643,8 +659,8 @@ module ArelExtensions
|
|
643
659
|
end
|
644
660
|
|
645
661
|
def test_subquery_with_order
|
646
|
-
assert_equal
|
647
|
-
assert_equal
|
662
|
+
assert_equal 9, User.where(:name => User.select(:name).order(:name)).count
|
663
|
+
assert_equal 9, User.where(@ut[:name].in(@ut.project(@ut[:name]).order(@ut[:name]))).count
|
648
664
|
if !['mysql'].include?(@env_db) # MySql can't have limit in IN subquery
|
649
665
|
assert_equal 2, User.where(:name => User.select(:name).order(:name).limit(2)).count
|
650
666
|
#assert_equal 6, User.where(:name => User.select(:name).order(:name).offset(2)).count
|
@@ -712,6 +728,13 @@ module ArelExtensions
|
|
712
728
|
#assert_equal true , @test.where(@age.not_in([nil,1,2])).blank?
|
713
729
|
end
|
714
730
|
|
731
|
+
def test_in_on_grouping
|
732
|
+
skip "We should modify the visitor of IN to make it work" if $sqlite || @env_db == 'mssql'
|
733
|
+
assert_equal 2 , User.where(Arel.tuple(@name,@age).in(Arel.tuple('Myung',23),Arel.tuple('Arthur',21))).count
|
734
|
+
assert_equal 1 , User.where(Arel.tuple(@name,@age).in(Arel.tuple('Myung',23))).count
|
735
|
+
assert_equal 0 , User.where(Arel.tuple(@name,@age).in([])).count
|
736
|
+
end
|
737
|
+
|
715
738
|
def test_alias_shortened
|
716
739
|
if ['postgresql','oracle'].include?(@env_db)
|
717
740
|
new_alias = Arel.shorten('azerty' * 15)
|
@@ -726,16 +749,21 @@ module ArelExtensions
|
|
726
749
|
def test_stat_functions
|
727
750
|
skip "SQLite doesn't work for most on this functions" if $sqlite
|
728
751
|
#puts t(User.where(nil), @score.average)
|
729
|
-
#puts t(User.where(nil), @score.variance(true))
|
730
|
-
#puts t(User.where(nil), @score.variance(false))
|
731
|
-
#puts t(User.where(nil), @score.std(true))
|
732
|
-
#puts t(User.where(nil), @score.std(false))
|
733
|
-
|
734
|
-
assert ( 15.
|
735
|
-
assert (
|
736
|
-
assert (
|
737
|
-
assert (
|
738
|
-
assert (
|
752
|
+
#puts t(User.where(nil), @score.variance(unbiased: true))
|
753
|
+
#puts t(User.where(nil), @score.variance(unbiased: false))
|
754
|
+
#puts t(User.where(nil), @score.std(unbiased: true))
|
755
|
+
#puts t(User.where(nil), @score.std(unbiased: false))
|
756
|
+
|
757
|
+
assert ( 15.43222 - t(User.where(nil), @score.average)).abs < 0.01
|
758
|
+
assert (539.79804 - t(User.where(nil), @score.variance)).abs < 0.01
|
759
|
+
assert (479.82048 - t(User.where(nil), @score.variance(unbiased: false))).abs < 0.01
|
760
|
+
assert ( 23.23355 - t(User.where(nil), @score.std)).abs < 0.01
|
761
|
+
assert ( 21.90480 - t(User.where(nil), @score.std(unbiased: false))).abs < 0.01
|
762
|
+
skip "Not Yet Implemented" #if !['postgresql'].include?(@env_db)
|
763
|
+
assert_equal 2, User.select(@score.std(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e| e['res']}.uniq.length
|
764
|
+
assert_equal 2, User.select(@score.variance(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e|e['res']}.uniq.length
|
765
|
+
assert_equal 2, User.select(@score.sum(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e|e['res']}.uniq.length
|
766
|
+
assert_equal 2, User.select(@comments.group_concat(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e|e['res']}.uniq.length
|
739
767
|
end
|
740
768
|
|
741
769
|
def test_levenshtein_distance
|
@@ -791,6 +819,11 @@ module ArelExtensions
|
|
791
819
|
assert_equal 'ArthurArthur', @arthur.select((@name+@name).as('Na-Me')).first.attributes["Na-Me"]
|
792
820
|
end
|
793
821
|
|
822
|
+
def test_exists_in_subquery
|
823
|
+
assert User.where(User.where(nil).arel.exists).first
|
824
|
+
end
|
825
|
+
|
826
|
+
|
794
827
|
end
|
795
828
|
end
|
796
829
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'arelx_test_helper'
|
2
2
|
require 'date'
|
3
3
|
|
4
4
|
module ArelExtensions
|
@@ -23,7 +23,7 @@ module ArelExtensions
|
|
23
23
|
@cnx.execute(sql) rescue $stderr << "can't create functions\n"
|
24
24
|
end
|
25
25
|
end
|
26
|
-
@cnx.drop_table(:user_tests) rescue nil
|
26
|
+
@cnx.drop_table(:user_tests) rescue nil
|
27
27
|
@cnx.create_table :user_tests do |t|
|
28
28
|
t.column :age, :integer
|
29
29
|
t.column :name, :string
|
@@ -77,6 +77,7 @@ END;])
|
|
77
77
|
insert_manager.bulk_insert(@cols2, @data2)
|
78
78
|
@cnx.execute(insert_manager.to_sql)
|
79
79
|
assert_equal 4, User.count, "insertions failed"
|
80
|
+
|
80
81
|
end
|
81
82
|
|
82
83
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'arelx_test_helper'
|
2
2
|
|
3
3
|
module ArelExtensions
|
4
4
|
module WthAr
|
@@ -12,7 +12,7 @@ module ArelExtensions
|
|
12
12
|
@cnx = ActiveRecord::Base.connection
|
13
13
|
Arel::Table.engine = ActiveRecord::Base
|
14
14
|
@cnx.drop_table(:users) rescue nil
|
15
|
-
@cnx.drop_table(:products) rescue nil
|
15
|
+
@cnx.drop_table(:products) rescue nil
|
16
16
|
@cnx.create_table :users do |t|
|
17
17
|
t.column :age, :integer
|
18
18
|
t.column :name, :string
|
@@ -38,11 +38,12 @@ module ArelExtensions
|
|
38
38
|
it "should import large set of data" do
|
39
39
|
insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new().into(@table) : Arel::InsertManager.new(ActiveRecord::Base).into(@table)
|
40
40
|
insert_manager.bulk_insert(@cols, @data)
|
41
|
-
|
42
|
-
|
41
|
+
_(insert_manager.to_sql)
|
42
|
+
.must_be_like %Q[INSERT INTO "users" ("id", "name", "comments", "created_at")
|
43
|
+
SELECT 23 AS 'id', 'nom1' AS 'name', 'sdfdsfdsfsdf' AS 'comments', '2016-01-01' AS 'created_at' UNION ALL SELECT 25, 'nom2', 'sdfdsfdsfsdf', '2016-01-01']
|
43
44
|
end
|
44
45
|
|
45
46
|
end
|
46
47
|
|
47
48
|
end
|
48
|
-
end
|
49
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'arelx_test_helper'
|
2
2
|
|
3
3
|
module ArelExtensions
|
4
4
|
module WthAr
|
@@ -11,8 +11,8 @@ module ArelExtensions
|
|
11
11
|
ActiveRecord::Base.default_timezone = :utc
|
12
12
|
Arel::Table.engine = ActiveRecord::Base
|
13
13
|
@cnx = ActiveRecord::Base.connection
|
14
|
-
@cnx.drop_table(:users) rescue nil
|
15
|
-
@cnx.drop_table(:products) rescue nil
|
14
|
+
@cnx.drop_table(:users) rescue nil
|
15
|
+
@cnx.drop_table(:products) rescue nil
|
16
16
|
@cnx.create_table :users do |t|
|
17
17
|
t.column :age, :integer
|
18
18
|
t.column :name, :string
|
@@ -61,4 +61,4 @@ module ArelExtensions
|
|
61
61
|
end
|
62
62
|
|
63
63
|
end
|
64
|
-
end
|
64
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'arelx_test_helper'
|
2
2
|
require 'date'
|
3
3
|
|
4
4
|
module ArelExtensions
|
@@ -10,7 +10,7 @@ module ArelExtensions
|
|
10
10
|
ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
|
11
11
|
ActiveRecord::Base.establish_connection(ENV['DB'] || (RUBY_PLATFORM == 'java' ? :"jdbc-mysql" : :mysql))
|
12
12
|
ActiveRecord::Base.default_timezone = :utc
|
13
|
-
begin
|
13
|
+
begin
|
14
14
|
@cnx = ActiveRecord::Base.connection
|
15
15
|
rescue => e
|
16
16
|
puts "\n#{e.inspect}"
|
@@ -19,7 +19,7 @@ module ArelExtensions
|
|
19
19
|
end
|
20
20
|
Arel::Table.engine = ActiveRecord::Base
|
21
21
|
@cnx.drop_table(:users) rescue nil
|
22
|
-
@cnx.drop_table(:products) rescue nil
|
22
|
+
@cnx.drop_table(:products) rescue nil
|
23
23
|
@cnx.create_table :users do |t|
|
24
24
|
t.column :age, :integer
|
25
25
|
t.column :name, :string
|
@@ -67,11 +67,9 @@ module ArelExtensions
|
|
67
67
|
# Replace
|
68
68
|
assert_equal "LucaX", User.where(:id => @lucas).select(@name.replace("s","X").as("res")).first.res
|
69
69
|
assert_equal "replace", User.where(:id => @lucas).select(@name.replace(@name,"replace").as("res")).first.res
|
70
|
-
|
71
|
-
#
|
72
70
|
end
|
73
71
|
|
74
72
|
end
|
75
73
|
|
76
74
|
end
|
77
|
-
end
|
75
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'arelx_test_helper'
|
2
2
|
require 'date'
|
3
3
|
|
4
4
|
module ArelExtensions
|
@@ -12,7 +12,7 @@ module ArelExtensions
|
|
12
12
|
ActiveRecord::Base.default_timezone = :utc
|
13
13
|
@cnx = ActiveRecord::Base.connection
|
14
14
|
Arel::Table.engine = ActiveRecord::Base
|
15
|
-
@cnx.drop_table(:users) rescue nil
|
15
|
+
@cnx.drop_table(:users) rescue nil
|
16
16
|
@cnx.create_table :users do |t|
|
17
17
|
t.column :age, :integer
|
18
18
|
t.column :name, :string
|
@@ -57,16 +57,12 @@ module ArelExtensions
|
|
57
57
|
assert_equal 1, User.where((User.arel_table[:age] + "1").eq(6)).count
|
58
58
|
assert_equal 1, User.where((User.arel_table[:age] + User.arel_table[:age]).eq(10)).count
|
59
59
|
|
60
|
-
|
61
|
-
|
62
60
|
# Replace
|
63
61
|
assert_equal "LucaX", User.where(:id => @lucas).select(@name.replace("s","X").as("res")).first.res
|
64
62
|
assert_equal "replace", User.where(:id => @lucas).select(@name.replace(@name,"replace").as("res")).first.res
|
65
|
-
|
66
|
-
#
|
67
63
|
end
|
68
64
|
|
69
65
|
end
|
70
66
|
|
71
67
|
end
|
72
|
-
end
|
68
|
+
end
|
data/version_v1.rb
ADDED
data/version_v2.rb
ADDED
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.11
|
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: 2020-
|
13
|
+
date: 2020-09-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 6.0
|
21
|
+
version: '6.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 6.0
|
28
|
+
version: '6.0'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: minitest
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,14 +60,14 @@ dependencies:
|
|
60
60
|
requirements:
|
61
61
|
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version:
|
63
|
+
version: 12.3.3
|
64
64
|
type: :development
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
68
|
- - "~>"
|
69
69
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
70
|
+
version: 12.3.3
|
71
71
|
description: Adds new features to Arel
|
72
72
|
email:
|
73
73
|
- yann.azoury@faveod.com
|
@@ -104,6 +104,9 @@ files:
|
|
104
104
|
- gemfiles/rails5_0.gemfile
|
105
105
|
- gemfiles/rails5_1_4.gemfile
|
106
106
|
- gemfiles/rails5_2.gemfile
|
107
|
+
- gemfiles/rails6.gemfile
|
108
|
+
- gemspec_v2/arel_extensions-v2.gemspec
|
109
|
+
- generate_gems.sh
|
107
110
|
- init/mssql.sql
|
108
111
|
- init/mysql.sql
|
109
112
|
- init/oracle.sql
|
@@ -120,6 +123,7 @@ files:
|
|
120
123
|
- lib/arel_extensions/math_functions.rb
|
121
124
|
- lib/arel_extensions/nodes.rb
|
122
125
|
- lib/arel_extensions/nodes/abs.rb
|
126
|
+
- lib/arel_extensions/nodes/aggregate_function.rb
|
123
127
|
- lib/arel_extensions/nodes/blank.rb
|
124
128
|
- lib/arel_extensions/nodes/case.rb
|
125
129
|
- lib/arel_extensions/nodes/cast.rb
|
@@ -151,6 +155,7 @@ files:
|
|
151
155
|
- lib/arel_extensions/nodes/soundex.rb
|
152
156
|
- lib/arel_extensions/nodes/std.rb
|
153
157
|
- lib/arel_extensions/nodes/substring.rb
|
158
|
+
- lib/arel_extensions/nodes/sum.rb
|
154
159
|
- lib/arel_extensions/nodes/then.rb
|
155
160
|
- lib/arel_extensions/nodes/trim.rb
|
156
161
|
- lib/arel_extensions/nodes/union.rb
|
@@ -172,8 +177,8 @@ files:
|
|
172
177
|
- lib/arel_extensions/visitors/postgresql.rb
|
173
178
|
- lib/arel_extensions/visitors/sqlite.rb
|
174
179
|
- lib/arel_extensions/visitors/to_sql.rb
|
180
|
+
- test/arelx_test_helper.rb
|
175
181
|
- test/database.yml
|
176
|
-
- test/helper.rb
|
177
182
|
- test/real_db_test.rb
|
178
183
|
- test/support/alter_system_user_password.sql
|
179
184
|
- test/support/create_oracle_enhanced_users.sql
|
@@ -190,6 +195,8 @@ files:
|
|
190
195
|
- test/with_ar/test_math_sqlite.rb
|
191
196
|
- test/with_ar/test_string_mysql.rb
|
192
197
|
- test/with_ar/test_string_sqlite.rb
|
198
|
+
- version_v1.rb
|
199
|
+
- version_v2.rb
|
193
200
|
homepage: https://github.com/Faveod/arel-extensions
|
194
201
|
licenses:
|
195
202
|
- MIT
|