arel_extensions 1.4.0 → 2.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -1
- data/.gitignore +6 -7
- data/.rubocop.yml +3 -67
- data/.travis/oracle/download.js +152 -0
- data/.travis/oracle/download.sh +30 -0
- data/.travis/oracle/download_ojdbc.js +116 -0
- data/.travis/oracle/install.sh +34 -0
- data/.travis/setup_accounts.sh +9 -0
- data/.travis/sqlite3/extension-functions.sh +6 -0
- data/.travis.yml +223 -0
- data/Gemfile +28 -2
- data/README.md +90 -239
- data/Rakefile +30 -48
- data/TODO +1 -0
- data/appveyor.yml +22 -60
- data/arel_extensions.gemspec +14 -13
- data/functions.html +3 -3
- data/gemfiles/rails3.gemfile +10 -10
- data/gemfiles/rails4.gemfile +29 -0
- data/gemfiles/rails5_0.gemfile +29 -0
- data/gemfiles/rails5_1_4.gemfile +14 -14
- data/gemfiles/rails5_2.gemfile +14 -16
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/oracle.sql +0 -0
- data/init/postgresql.sql +21 -21
- data/init/sqlite.sql +0 -0
- data/lib/arel_extensions/attributes.rb +3 -15
- data/lib/arel_extensions/boolean_functions.rb +14 -53
- data/lib/arel_extensions/common_sql_functions.rb +17 -16
- data/lib/arel_extensions/comparators.rb +28 -27
- data/lib/arel_extensions/date_duration.rb +13 -17
- data/lib/arel_extensions/insert_manager.rb +15 -18
- data/lib/arel_extensions/math.rb +53 -55
- data/lib/arel_extensions/math_functions.rb +39 -46
- data/lib/arel_extensions/nodes/abs.rb +1 -0
- data/lib/arel_extensions/nodes/blank.rb +2 -1
- data/lib/arel_extensions/nodes/case.rb +19 -20
- data/lib/arel_extensions/nodes/cast.rb +8 -10
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/coalesce.rb +4 -3
- data/lib/arel_extensions/nodes/collate.rb +10 -9
- data/lib/arel_extensions/nodes/concat.rb +18 -9
- data/lib/arel_extensions/nodes/date_diff.rb +26 -42
- data/lib/arel_extensions/nodes/duration.rb +3 -0
- data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
- data/lib/arel_extensions/nodes/floor.rb +1 -1
- data/lib/arel_extensions/nodes/format.rb +8 -35
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
- data/lib/arel_extensions/nodes/function.rb +37 -42
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +39 -52
- data/lib/arel_extensions/nodes/length.rb +0 -5
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
- data/lib/arel_extensions/nodes/locate.rb +2 -1
- data/lib/arel_extensions/nodes/log10.rb +2 -1
- data/lib/arel_extensions/nodes/matches.rb +7 -5
- data/lib/arel_extensions/nodes/md5.rb +1 -0
- data/lib/arel_extensions/nodes/power.rb +5 -5
- data/lib/arel_extensions/nodes/rand.rb +1 -0
- data/lib/arel_extensions/nodes/repeat.rb +5 -3
- data/lib/arel_extensions/nodes/replace.rb +8 -16
- data/lib/arel_extensions/nodes/round.rb +6 -5
- data/lib/arel_extensions/nodes/soundex.rb +15 -15
- data/lib/arel_extensions/nodes/std.rb +21 -18
- data/lib/arel_extensions/nodes/substring.rb +16 -8
- data/lib/arel_extensions/nodes/then.rb +1 -1
- data/lib/arel_extensions/nodes/trim.rb +6 -4
- data/lib/arel_extensions/nodes/union.rb +8 -5
- data/lib/arel_extensions/nodes/union_all.rb +7 -4
- data/lib/arel_extensions/nodes/wday.rb +4 -0
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/null_functions.rb +5 -19
- data/lib/arel_extensions/predications.rb +43 -44
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +7 -5
- data/lib/arel_extensions/string_functions.rb +29 -59
- data/lib/arel_extensions/tasks.rb +6 -6
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
- data/lib/arel_extensions/visitors/mssql.rb +191 -422
- data/lib/arel_extensions/visitors/mysql.rb +212 -350
- data/lib/arel_extensions/visitors/oracle.rb +178 -220
- data/lib/arel_extensions/visitors/oracle12.rb +31 -18
- data/lib/arel_extensions/visitors/postgresql.rb +173 -256
- data/lib/arel_extensions/visitors/sqlite.rb +126 -140
- data/lib/arel_extensions/visitors/to_sql.rb +237 -298
- data/lib/arel_extensions/visitors.rb +62 -83
- data/lib/arel_extensions.rb +31 -224
- data/test/database.yml +7 -15
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +117 -120
- data/test/support/fake_record.rb +3 -9
- data/test/test_comparators.rb +17 -14
- data/test/visitors/test_bulk_insert_oracle.rb +11 -11
- data/test/visitors/test_bulk_insert_sqlite.rb +13 -12
- data/test/visitors/test_bulk_insert_to_sql.rb +13 -11
- data/test/visitors/test_oracle.rb +55 -55
- data/test/visitors/test_to_sql.rb +226 -419
- data/test/with_ar/all_agnostic_test.rb +366 -709
- data/test/with_ar/insert_agnostic_test.rb +21 -27
- data/test/with_ar/test_bulk_sqlite.rb +16 -17
- data/test/with_ar/test_math_sqlite.rb +26 -26
- data/test/with_ar/test_string_mysql.rb +33 -31
- data/test/with_ar/test_string_sqlite.rb +34 -30
- metadata +34 -43
- data/.github/workflows/publish.yml +0 -29
- data/.github/workflows/release.yml +0 -30
- data/.github/workflows/ruby.yml +0 -399
- data/CONTRIBUTING.md +0 -102
- data/NEWS.md +0 -78
- data/bin/build +0 -15
- data/bin/compose +0 -6
- data/bin/publish +0 -8
- data/dev/arelx.dockerfile +0 -44
- data/dev/compose.yaml +0 -71
- data/dev/postgres.dockerfile +0 -5
- data/dev/rbenv +0 -189
- data/gemfiles/rails4_2.gemfile +0 -38
- data/gemfiles/rails5.gemfile +0 -29
- data/gemfiles/rails6.gemfile +0 -33
- data/gemfiles/rails6_1.gemfile +0 -33
- data/gemfiles/rails7.gemfile +0 -33
- data/gemfiles/rails7_1.gemfile +0 -33
- data/gemfiles/rails7_2.gemfile +0 -33
- data/gemspecs/arel_extensions-v1.gemspec +0 -27
- data/gemspecs/arel_extensions-v2.gemspec +0 -27
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/aliases.rb +0 -14
- data/lib/arel_extensions/helpers.rb +0 -62
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- data/lib/arel_extensions/nodes/formatted_date.rb +0 -42
- data/lib/arel_extensions/nodes/rollup.rb +0 -36
- data/lib/arel_extensions/nodes/select.rb +0 -10
- data/lib/arel_extensions/nodes/sum.rb +0 -7
- data/lib/arel_extensions/visitors/convert_format.rb +0 -37
- data/test/arelx_test_helper.rb +0 -74
- data/version_v1.rb +0 -3
- data/version_v2.rb +0 -3
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
module ArelExtensions
|
4
4
|
module VisitorOracle
|
@@ -22,88 +22,88 @@ module ArelExtensions
|
|
22
22
|
|
23
23
|
# Comparators
|
24
24
|
|
25
|
-
it
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
25
|
+
it "should accept comparators on integers" do
|
26
|
+
compile(@table[:id] == 42).must_match %{"users"."id" = 42}
|
27
|
+
compile(@table[:id] == @table[:id]).must_be_like %{"users"."id" = "users"."id"}
|
28
|
+
compile(@table[:id] != 42).must_match %{"users"."id" != 42}
|
29
|
+
compile(@table[:id] > 42).must_match %{"users"."id" > 42}
|
30
|
+
compile(@table[:id] >= 42).must_match %{"users"."id" >= 42}
|
31
|
+
compile(@table[:id] >= @table[:id]).must_be_like %{"users"."id" >= "users"."id"}
|
32
|
+
compile(@table[:id] < 42).must_match %{"users"."id" < 42}
|
33
|
+
compile(@table[:id] <= 42).must_match %{"users"."id" <= 42}
|
34
|
+
compile((@table[:id] <= 42).as('new_name')).must_match %{("users"."id" <= 42) AS new_name}
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it "should accept comparators on dates" do
|
38
38
|
c = @table[:created_at]
|
39
39
|
u = @table[:updated_at]
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
compile(c > @date).must_be_like %{"users"."created_at" > '2016-03-31'}
|
41
|
+
compile(u >= @date).must_be_like %{"users"."updated_at" >= '2016-03-31'}
|
42
|
+
compile(c < u).must_be_like %{"users"."created_at" < "users"."updated_at"}
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it "should accept comparators on strings" do
|
46
46
|
c = @table[:name]
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
_(compile(c.idoes_not_match('%test%'))).must_be_like %{LOWER("users"."name") NOT LIKE LOWER('%test%')}
|
47
|
+
compile(c == 'test').must_be_like %{"users"."name" = 'test'}
|
48
|
+
compile(c != 'test').must_be_like %{"users"."name" != 'test'}
|
49
|
+
compile(c > 'test').must_be_like %{"users"."name" > 'test'}
|
50
|
+
compile((c >= 'test').as('new_name')).must_be_like %{("users"."name" >= 'test') AS new_name}
|
51
|
+
compile(c <= @table[:comments]).must_be_like %{"users"."name" <= "users"."comments"}
|
52
|
+
compile(c =~ /\Atest\Z/).must_be_like %{REGEXP_LIKE("users"."name", '^test$')}
|
53
|
+
compile(c =~ '^test$').must_be_like %{REGEXP_LIKE("users"."name", '^test$')}
|
54
|
+
compile(c !~ /\Ate\Dst\Z/).must_be_like %{NOT REGEXP_LIKE("users"."name", '^te[^0-9]st$')}
|
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')))}
|
57
|
+
compile(c.idoes_not_match('%test%')).must_be_like %{LOWER("users"."name") NOT LIKE LOWER('%test%')}
|
59
58
|
end
|
60
59
|
|
61
60
|
# Maths
|
62
61
|
# DateDiff
|
63
|
-
it
|
64
|
-
|
62
|
+
it "should diff date col and date" do
|
63
|
+
compile(@table[:created_at] - Date.new(2016, 3, 31)).must_match %{"users"."created_at" - TO_DATE('2016-03-31')}
|
65
64
|
end
|
66
65
|
|
67
|
-
it
|
68
|
-
|
66
|
+
it "should diff date col and datetime col" do
|
67
|
+
compile(@table[:created_at] - @table[:updated_at]).must_match %{"users"."created_at" - "users"."updated_at"}
|
69
68
|
end
|
70
69
|
|
71
|
-
it
|
70
|
+
it "should diff date col and datetime col with AS" do
|
72
71
|
sql = compile((@table[:updated_at] - @table[:created_at]).as('new_name'))
|
73
|
-
|
74
|
-
|
72
|
+
# sql.must_be_like %{(TO_DATE("users"."updated_at") - "users"."created_at") * 86400 AS new_name}
|
73
|
+
sql.must_be_like %{("users"."updated_at" - "users"."created_at") * (CASE WHEN (TRUNC("users"."updated_at", 'DDD') = "users"."updated_at") THEN 1 ELSE 86400 END) AS new_name}
|
75
74
|
end
|
76
75
|
|
77
|
-
it
|
78
|
-
d2 = Time.new(2015,
|
79
|
-
d1 = DateTime.new(2015,
|
80
|
-
|
81
|
-
|
76
|
+
it "should diff between time values" do
|
77
|
+
d2 = Time.new(2015,6,1)
|
78
|
+
d1 = DateTime.new(2015,6,2)
|
79
|
+
sql = compile(ArelExtensions::Nodes::DateDiff.new([d1,d2]))
|
80
|
+
sql.must_match("TO_DATE('2015-06-02') - TO_DATE('2015-06-01')")
|
82
81
|
end
|
83
82
|
|
84
|
-
it
|
85
|
-
d1 = DateTime.new(2015,
|
86
|
-
|
87
|
-
|
83
|
+
it "should diff between time values and time col" do
|
84
|
+
d1 = DateTime.new(2015,6,2)
|
85
|
+
sql = compile(ArelExtensions::Nodes::DateDiff.new([d1, @table[:updated_at]]))
|
86
|
+
sql.must_match %{TO_DATE('2015-06-02') - "users"."updated_at"}
|
88
87
|
end
|
89
88
|
|
90
|
-
it
|
89
|
+
it "should accept operators on dates with numbers" do
|
91
90
|
c = @table[:created_at]
|
92
|
-
|
93
|
-
|
91
|
+
compile(c - 42).must_be_like %{DATE_SUB("users"."created_at", 42)}
|
92
|
+
compile(c - @table[:id]).must_be_like %{DATE_SUB("users"."created_at", "users"."id")}
|
94
93
|
end
|
95
94
|
|
96
95
|
# Maths on sums
|
97
|
-
it
|
96
|
+
it "should accept math operators on anything" do
|
98
97
|
c = @table[:name]
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
98
|
+
(c == 'test').to_sql.must_be_like %{"users"."name" = 'test'}
|
99
|
+
(c != 'test').to_sql.must_be_like %{"users"."name" != 'test'}
|
100
|
+
(c > 'test').to_sql.must_be_like %{"users"."name" > 'test'}
|
101
|
+
compile((c >= 'test').as('new_name')).must_be_like %{("users"."name" >= 'test') AS new_name}
|
102
|
+
compile(c <= @table[:comments]).must_be_like %{"users"."name" <= "users"."comments"}
|
103
|
+
compile(c =~ /\Atest\Z/).must_be_like %{REGEXP_LIKE("users"."name", '^test$')}
|
104
|
+
compile(c !~ /\Ate\Dst\Z/).must_be_like %{NOT REGEXP_LIKE("users"."name", '^te[^0-9]st$')}
|
106
105
|
end
|
106
|
+
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|