arel_extensions 2.0.1 → 2.0.4
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 +10 -10
- data/Gemfile +14 -19
- data/README.md +17 -12
- data/Rakefile +23 -23
- data/appveyor.yml +1 -1
- data/arel_extensions.gemspec +2 -2
- data/functions.html +3 -3
- data/gemfiles/rails6.gemfile +30 -0
- data/gemspec_v2/arel_extensions-v2.gemspec +28 -0
- data/generate_gems.sh +13 -0
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/postgresql.sql +21 -21
- data/lib/arel_extensions/boolean_functions.rb +0 -2
- 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 +12 -12
- data/lib/arel_extensions/math.rb +3 -3
- data/lib/arel_extensions/math_functions.rb +10 -5
- data/lib/arel_extensions/nodes/aggregate_function.rb +14 -0
- data/lib/arel_extensions/nodes/case.rb +0 -2
- 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/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/json.rb +28 -30
- data/lib/arel_extensions/nodes/matches.rb +4 -4
- data/lib/arel_extensions/nodes/power.rb +6 -5
- 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.rb +1 -1
- data/lib/arel_extensions/null_functions.rb +2 -2
- data/lib/arel_extensions/predications.rb +16 -17
- data/lib/arel_extensions/string_functions.rb +21 -12
- data/lib/arel_extensions/tasks.rb +5 -5
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/mssql.rb +14 -13
- data/lib/arel_extensions/visitors/mysql.rb +72 -37
- data/lib/arel_extensions/visitors/oracle.rb +12 -11
- data/lib/arel_extensions/visitors/oracle12.rb +1 -1
- data/lib/arel_extensions/visitors/postgresql.rb +77 -31
- data/lib/arel_extensions/visitors/sqlite.rb +54 -40
- data/lib/arel_extensions/visitors/to_sql.rb +50 -31
- data/lib/arel_extensions.rb +20 -1
- data/test/helper.rb +1 -1
- data/test/real_db_test.rb +1 -1
- data/test/support/fake_record.rb +0 -4
- data/test/test_comparators.rb +1 -1
- data/test/visitors/test_bulk_insert_oracle.rb +6 -6
- data/test/visitors/test_bulk_insert_sqlite.rb +6 -6
- data/test/visitors/test_bulk_insert_to_sql.rb +7 -9
- data/test/visitors/test_oracle.rb +1 -0
- data/test/visitors/test_to_sql.rb +15 -1
- data/test/with_ar/all_agnostic_test.rb +54 -32
- data/test/with_ar/insert_agnostic_test.rb +2 -1
- data/test/with_ar/test_bulk_sqlite.rb +2 -2
- data/test/with_ar/test_math_sqlite.rb +3 -3
- data/test/with_ar/test_string_mysql.rb +3 -5
- data/test/with_ar/test_string_sqlite.rb +2 -6
- data/version_v1.rb +3 -0
- data/version_v2.rb +3 -0
- metadata +13 -6
@@ -50,6 +50,7 @@ module ArelExtensions
|
|
50
50
|
compile((c >= 'test').as('new_name')).must_be_like %{("users"."name" >= 'test') AS new_name}
|
51
51
|
compile(c <= @table[:comments]).must_be_like %{"users"."name" <= "users"."comments"}
|
52
52
|
compile(c =~ /\Atest\Z/).must_be_like %{REGEXP_LIKE("users"."name", '^test$')}
|
53
|
+
compile(c =~ /\Atest\z/).must_be_like %{REGEXP_LIKE("users"."name", '^test$')}
|
53
54
|
compile(c =~ '^test$').must_be_like %{REGEXP_LIKE("users"."name", '^test$')}
|
54
55
|
compile(c !~ /\Ate\Dst\Z/).must_be_like %{NOT REGEXP_LIKE("users"."name", '^te[^0-9]st$')}
|
55
56
|
compile(c.imatches('%test%')).must_be_like %{LOWER("users"."name") LIKE LOWER('%test%')}
|
@@ -88,6 +88,7 @@ module ArelExtensions
|
|
88
88
|
compile((c >= 'test').as('new_name')).must_be_like %{("users"."name" >= 'test') AS new_name}
|
89
89
|
compile(c <= @table[:comments]).must_be_like %{"users"."name" <= "users"."comments"}
|
90
90
|
compile(c =~ /\Atest\Z/).must_be_like %{"users"."name" REGEXP '^test$'}
|
91
|
+
compile(c =~ /\Atest\z/).must_be_like %{"users"."name" REGEXP '^test$'}
|
91
92
|
compile(c !~ /\Ate\Dst\Z/).must_be_like %{"users"."name" NOT REGEXP '^te[^0-9]st$'}
|
92
93
|
compile(c.imatches('%test%')).must_be_like %{"users"."name" ILIKE '%test%'}
|
93
94
|
compile(c.imatches_any(['%test%', 't2'])).must_be_like %{(("users"."name" ILIKE '%test%') OR ("users"."name" ILIKE 't2'))}
|
@@ -120,6 +121,10 @@ module ArelExtensions
|
|
120
121
|
compile(@table[:id] < 42).must_match %{"users"."id" < 42}
|
121
122
|
compile(@table[:id] <= 42).must_match %{"users"."id" <= 42}
|
122
123
|
compile((@table[:id] <= 42).as('new_name')).must_match %{("users"."id" <= 42) AS new_name}
|
124
|
+
compile(@table[:id].count.eq 42).must_match %{COUNT("users"."id") = 42}
|
125
|
+
#compile(@table[:id].count == 42).must_match %{COUNT("users"."id") = 42} # TODO
|
126
|
+
#compile(@table[:id].count != 42).must_match %{COUNT("users"."id") != 42}
|
127
|
+
#compile(@table[:id].count >= 42).must_match %{COUNT("users"."id") >= 42}
|
123
128
|
end
|
124
129
|
|
125
130
|
it "should accept comparators on dates" do
|
@@ -328,9 +333,11 @@ module ArelExtensions
|
|
328
333
|
compile(@table[:id].in(1))
|
329
334
|
.must_be_like %{"users"."id" IN (1)}
|
330
335
|
compile(@table[:id].in([1]))
|
331
|
-
.must_be_like %{"users"."id"
|
336
|
+
.must_be_like %{"users"."id" = 1}
|
332
337
|
compile(@table[:id].in([1,2]))
|
333
338
|
.must_be_like %{"users"."id" IN (1, 2)}
|
339
|
+
compile(@table[:id].in([]))
|
340
|
+
.must_be_like %{ISNULL("users"."id")}
|
334
341
|
end
|
335
342
|
|
336
343
|
it "should be possible to correctly use a Range on an IN" do
|
@@ -340,6 +347,13 @@ module ArelExtensions
|
|
340
347
|
.must_be_like %{"users"."created_at" BETWEEN ('2016-03-31') AND ('2017-03-31')}
|
341
348
|
end
|
342
349
|
|
350
|
+
it "should be possible to use a list of values and ranges on an IN" do
|
351
|
+
compile(@table[:id].in [1..10, 20, 30, 40..50])
|
352
|
+
.must_be_like %{(("users"."id" IN (20, 30)) OR ("users"."id" BETWEEN (1) AND (10))) OR ("users"."id" BETWEEN (40) AND (50))}
|
353
|
+
# compile(@table[:created_at].in(@date .. Date.new(2017, 3, 31))) # @date = Date.new(2016, 3, 31)
|
354
|
+
# .must_be_like %{"users"."created_at" BETWEEN ('2016-03-31') AND ('2017-03-31')}
|
355
|
+
end
|
356
|
+
|
343
357
|
it "should be possible to add and substract as much as we want" do
|
344
358
|
c = @table[:name]
|
345
359
|
compile(c.locate('test')+1)
|
@@ -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,27 @@ 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
|
+
assert_equal "LXcXs", t(@lucas, @name.replace(/[ua]/, "X"))
|
294
|
+
assert_equal "LXcXs", t(@lucas, @name.regexp_replace(/[ua]/, "X"))
|
295
|
+
assert_equal "LXcXs", t(@lucas, @name.regexp_replace('[ua]', "X"))
|
285
296
|
end
|
286
297
|
|
287
298
|
def test_replace_once
|
@@ -294,8 +305,8 @@ module ArelExtensions
|
|
294
305
|
skip "Sqlite version can't load extension for soundex" if $sqlite && $load_extension_disabled
|
295
306
|
skip "PostgreSql version can't load extension for soundex" if @env_db == 'postgresql'
|
296
307
|
assert_equal "C540", t(@camille, @name.soundex)
|
297
|
-
assert_equal
|
298
|
-
assert_equal
|
308
|
+
assert_equal 9, User.where(@name.soundex.eq(@name.soundex)).count
|
309
|
+
assert_equal 9 , User.where(@name.soundex == @name.soundex).count
|
299
310
|
end
|
300
311
|
|
301
312
|
def test_change_case
|
@@ -374,13 +385,13 @@ module ArelExtensions
|
|
374
385
|
assert_equal 2, User.where(@age <= 10).count
|
375
386
|
assert_equal 3, User.where(@age > 20).count
|
376
387
|
assert_equal 4, User.where(@age >= 20).count
|
377
|
-
assert_equal
|
388
|
+
assert_equal 2, User.where(@age > 5).where(@age < 20).count
|
378
389
|
end
|
379
390
|
|
380
391
|
def test_date_comparator
|
381
392
|
d = Date.new(2016, 5, 23)
|
382
393
|
assert_equal 0, User.where(@created_at < d).count
|
383
|
-
assert_equal
|
394
|
+
assert_equal 9, User.where(@created_at >= d).count
|
384
395
|
end
|
385
396
|
|
386
397
|
def test_date_duration
|
@@ -389,10 +400,10 @@ module ArelExtensions
|
|
389
400
|
assert_equal 0, User.where(@created_at.year.eq("2012")).count
|
390
401
|
#Month
|
391
402
|
assert_equal 5, t(@camille, @created_at.month).to_i
|
392
|
-
assert_equal
|
403
|
+
assert_equal 9, User.where(@created_at.month.eq("05")).count
|
393
404
|
#Week
|
394
405
|
assert_equal(@env_db == 'mssql' ? 22 : 21, t(@arthur, @created_at.week).to_i)
|
395
|
-
assert_equal
|
406
|
+
assert_equal 9, User.where(@created_at.month.eq("05")).count
|
396
407
|
#Day
|
397
408
|
assert_equal 23, t(@laure, @created_at.day).to_i
|
398
409
|
assert_equal 0, User.where(@created_at.day.eq("05")).count
|
@@ -424,6 +435,7 @@ module ArelExtensions
|
|
424
435
|
end
|
425
436
|
end
|
426
437
|
|
438
|
+
|
427
439
|
skip "not yet implemented" if $sqlite
|
428
440
|
|
429
441
|
date1 = Date.new(2016, 5, 23)
|
@@ -525,7 +537,7 @@ module ArelExtensions
|
|
525
537
|
def test_math_minus
|
526
538
|
d = Date.new(2016, 5, 20)
|
527
539
|
#Datediff
|
528
|
-
assert_equal
|
540
|
+
assert_equal 9, User.where((@created_at - @created_at).eq(0)).count
|
529
541
|
assert_equal 3, @laure.select((@created_at - d).as("res")).first.res.abs.to_i
|
530
542
|
#Substraction
|
531
543
|
assert_equal 0, User.where((@age - 10).eq(50)).count
|
@@ -643,8 +655,8 @@ module ArelExtensions
|
|
643
655
|
end
|
644
656
|
|
645
657
|
def test_subquery_with_order
|
646
|
-
assert_equal
|
647
|
-
assert_equal
|
658
|
+
assert_equal 9, User.where(:name => User.select(:name).order(:name)).count
|
659
|
+
assert_equal 9, User.where(@ut[:name].in(@ut.project(@ut[:name]).order(@ut[:name]))).count
|
648
660
|
if !['mysql'].include?(@env_db) # MySql can't have limit in IN subquery
|
649
661
|
assert_equal 2, User.where(:name => User.select(:name).order(:name).limit(2)).count
|
650
662
|
#assert_equal 6, User.where(:name => User.select(:name).order(:name).offset(2)).count
|
@@ -726,16 +738,21 @@ module ArelExtensions
|
|
726
738
|
def test_stat_functions
|
727
739
|
skip "SQLite doesn't work for most on this functions" if $sqlite
|
728
740
|
#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 (
|
741
|
+
#puts t(User.where(nil), @score.variance(unbiased: true))
|
742
|
+
#puts t(User.where(nil), @score.variance(unbiased: false))
|
743
|
+
#puts t(User.where(nil), @score.std(unbiased: true))
|
744
|
+
#puts t(User.where(nil), @score.std(unbiased: false))
|
745
|
+
|
746
|
+
assert ( 15.43222 - t(User.where(nil), @score.average)).abs < 0.01
|
747
|
+
assert (539.79804 - t(User.where(nil), @score.variance)).abs < 0.01
|
748
|
+
assert (479.82048 - t(User.where(nil), @score.variance(unbiased: false))).abs < 0.01
|
749
|
+
assert ( 23.23355 - t(User.where(nil), @score.std)).abs < 0.01
|
750
|
+
assert ( 21.90480 - t(User.where(nil), @score.std(unbiased: false))).abs < 0.01
|
751
|
+
skip "Not Yet Implemented" if !['postgresql'].include?(@env_db)
|
752
|
+
assert_equal 2, User.select(@score.std(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map(&:res).uniq.length
|
753
|
+
assert_equal 2, User.select(@score.variance(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map(&:res).uniq.length
|
754
|
+
assert_equal 2, User.select(@score.sum(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map(&:res).uniq.length
|
755
|
+
assert_equal 2, User.select(@comments.group_concat(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map(&:res).uniq.length
|
739
756
|
end
|
740
757
|
|
741
758
|
def test_levenshtein_distance
|
@@ -791,6 +808,11 @@ module ArelExtensions
|
|
791
808
|
assert_equal 'ArthurArthur', @arthur.select((@name+@name).as('Na-Me')).first.attributes["Na-Me"]
|
792
809
|
end
|
793
810
|
|
811
|
+
def test_exists_in_subquery
|
812
|
+
assert User.where(User.where(nil).arel.exists).first
|
813
|
+
end
|
814
|
+
|
815
|
+
|
794
816
|
end
|
795
817
|
end
|
796
818
|
end
|
@@ -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
|
@@ -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
|
@@ -45,4 +45,4 @@ module ArelExtensions
|
|
45
45
|
end
|
46
46
|
|
47
47
|
end
|
48
|
-
end
|
48
|
+
end
|
@@ -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
|
@@ -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
|
@@ -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.4
|
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-04-22 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
|
@@ -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
|