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
data/appveyor.yml
CHANGED
data/arel_extensions.gemspec
CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
|
23
|
-
s.add_dependency('activerecord', '>= 6.0
|
23
|
+
s.add_dependency('activerecord', '>= 6.0')
|
24
24
|
|
25
25
|
s.add_development_dependency('minitest', '~> 5.9')
|
26
26
|
s.add_development_dependency('rdoc', '~> 4.0')
|
27
|
-
s.add_development_dependency('rake', '~>
|
27
|
+
s.add_development_dependency('rake', '~> 12.3.3')
|
28
28
|
end
|
data/functions.html
CHANGED
@@ -55,7 +55,7 @@
|
|
55
55
|
<td class="tg-yw4l">CEIL<br>column.ceil</td>
|
56
56
|
<td class="ok">✔</td>
|
57
57
|
<td class="ok">✔</td>
|
58
|
-
<td class="tg-j6lv">CASE +
|
58
|
+
<td class="tg-j6lv">CASE + CAST</td>
|
59
59
|
<td class="ok">✔</td>
|
60
60
|
<td class="tg-j6lv">CEILING()</td>
|
61
61
|
<td class="tg-j6lv">CEILING()</td>
|
@@ -64,7 +64,7 @@
|
|
64
64
|
<td class="tg-yw4l">FLOOR<br>column.floor</td>
|
65
65
|
<td class="ok">✔</td>
|
66
66
|
<td class="ok">✔</td>
|
67
|
-
<td class="tg-j6lv">CASE +
|
67
|
+
<td class="tg-j6lv">CASE + CAST</td>
|
68
68
|
<td class="ok">✔</td>
|
69
69
|
<td class="ok">✔</td>
|
70
70
|
<td class="ok">✔</td>
|
@@ -379,7 +379,7 @@
|
|
379
379
|
<td class="ok">✔</td>
|
380
380
|
<td class="ok">✔</td>
|
381
381
|
<td class="ok">✔</td>
|
382
|
-
</tr>
|
382
|
+
</tr>
|
383
383
|
<tr>
|
384
384
|
<th class="bulk_insert" rowspan="1"><div>Set<br/> Operators</div></th>
|
385
385
|
<td class="tg-yw4l">UNION ( + )<br/>query + query</td>
|
data/gemfiles/rails4.gemfile
CHANGED
@@ -18,7 +18,7 @@ group :development, :test do
|
|
18
18
|
gem 'activerecord-oracle_enhanced-adapter', '~> 1.6.0' if ENV.has_key? 'ORACLE_HOME'
|
19
19
|
|
20
20
|
# for JRuby
|
21
|
-
gem 'activerecord-jdbc-adapter',
|
21
|
+
gem 'activerecord-jdbc-adapter', '~> 1.3' ,:platforms => :jruby
|
22
22
|
gem "jdbc-sqlite3", :platforms => :jruby
|
23
23
|
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
24
24
|
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
|
@@ -0,0 +1,30 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gem 'rails', '~> 6.0.0'
|
4
|
+
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem 'activesupport', '~> 6.0.0'
|
8
|
+
gem 'activemodel', '~> 6.0.0'
|
9
|
+
gem 'activerecord', '~> 6.0.0'
|
10
|
+
|
11
|
+
gem "sqlite3", '~> 1.4', :platforms => [:mri, :mswin, :mingw]
|
12
|
+
gem "mysql2", '0.5.2', :platforms => [:mri, :mswin, :mingw]
|
13
|
+
gem "pg",'< 1.0.0', :platforms => [:mri, :mingw]
|
14
|
+
|
15
|
+
gem "tiny_tds", :platforms => [:mri, :mingw] if RUBY_PLATFORM =~ /windows/
|
16
|
+
gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw]
|
17
|
+
|
18
|
+
gem 'ruby-oci8', :platforms => [:mri, :mswin, :mingw] if ENV.has_key? 'ORACLE_HOME'
|
19
|
+
gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0' if ENV.has_key? 'ORACLE_HOME'
|
20
|
+
|
21
|
+
# for JRuby
|
22
|
+
gem 'activerecord-jdbc-adapter', :platforms => :jruby
|
23
|
+
gem "jdbc-sqlite3", :platforms => :jruby
|
24
|
+
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
25
|
+
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
|
26
|
+
gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
|
27
|
+
gem "activerecord-jdbcmssql-adapter", :platforms => :jruby
|
28
|
+
end
|
29
|
+
|
30
|
+
gemspec :path => "../gemspec_v2/"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "arel_extensions/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "arel_extensions"
|
6
|
+
s.version = ArelExtensions::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Yann Azoury", "Félix Bellanger", "Julien Delporte"]
|
9
|
+
s.email = ["yann.azoury@faveod.com", "felix.bellanger@faveod.com", "julien.delporte@faveod.com"]
|
10
|
+
s.homepage = "https://github.com/Faveod/arel-extensions"
|
11
|
+
s.description = "Adds new features to Arel"
|
12
|
+
s.summary = "Extending Arel"
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.rdoc_options = ["--main", "README.md"]
|
16
|
+
s.extra_rdoc_files = ["MIT-LICENSE.txt", "README.md", 'functions.html']
|
17
|
+
|
18
|
+
# Manifest
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_dependency('activerecord', '>= 6.0')
|
24
|
+
|
25
|
+
s.add_development_dependency('minitest', '~> 5.9')
|
26
|
+
s.add_development_dependency('rdoc', '~> 4.0')
|
27
|
+
s.add_development_dependency('rake', '~> 12.3.3')
|
28
|
+
end
|
data/generate_gems.sh
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
gem uninstall arel_extensions
|
3
|
+
|
4
|
+
# VERSION ~> 1
|
5
|
+
cp ./version_v1.rb lib/arel_extensions/version.rb
|
6
|
+
gem build ./arel_extensions.gemspec
|
7
|
+
|
8
|
+
# VERSION ~> 2
|
9
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
10
|
+
mv ./arel_extensions.gemspec ./arel_extensions.gemspec.bck
|
11
|
+
cp ./gemspec_v2/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
12
|
+
gem build ./arel_extensions.gemspec
|
13
|
+
cp ./version_v1.rb lib/arel_extensions/version.rb
|
14
|
+
cp ./arel_extensions.gemspec.bck ./arel_extensions.gemspec
|
data/init/mssql.sql
CHANGED
@@ -83,7 +83,7 @@ BEGIN
|
|
83
83
|
END
|
84
84
|
SELECT @cv1 = @cv0, @i = @i + 1
|
85
85
|
END
|
86
|
-
RETURN @c
|
86
|
+
RETURN @c
|
87
87
|
END
|
88
88
|
GO
|
89
89
|
|
@@ -94,9 +94,9 @@ GO
|
|
94
94
|
--RETURNS TABLE
|
95
95
|
--AS
|
96
96
|
--BEGIN
|
97
|
-
-- RETURN ( SELECT [Value] FROM
|
98
|
-
-- (
|
99
|
-
-- SELECT
|
97
|
+
-- RETURN ( SELECT [Value] FROM
|
98
|
+
-- (
|
99
|
+
-- SELECT
|
100
100
|
-- [Value] = LTRIM(RTRIM(SUBSTRING(@List, [Number],
|
101
101
|
-- CHARINDEX(@Delim, @List + @Delim, [Number]) - [Number])))
|
102
102
|
-- FROM (SELECT Number = ROW_NUMBER() OVER (ORDER BY name)
|
data/init/mysql.sql
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
DELIMITER $$
|
2
2
|
|
3
3
|
DROP FUNCTION IF EXISTS levenshtein_distance; $$
|
4
|
-
CREATE FUNCTION levenshtein_distance( s1 VARCHAR(255), s2 VARCHAR(255) )
|
5
|
-
RETURNS INT
|
6
|
-
DETERMINISTIC
|
7
|
-
BEGIN
|
8
|
-
DECLARE s1_len, s2_len, i, j, c, c_temp, cost INT;
|
9
|
-
DECLARE s1_char CHAR;
|
10
|
-
-- max strlen=255
|
11
|
-
DECLARE cv0, cv1 VARBINARY(256);
|
4
|
+
CREATE FUNCTION levenshtein_distance( s1 VARCHAR(255), s2 VARCHAR(255) )
|
5
|
+
RETURNS INT
|
6
|
+
DETERMINISTIC
|
7
|
+
BEGIN
|
8
|
+
DECLARE s1_len, s2_len, i, j, c, c_temp, cost INT;
|
9
|
+
DECLARE s1_char CHAR;
|
10
|
+
-- max strlen=255
|
11
|
+
DECLARE cv0, cv1 VARBINARY(256);
|
12
12
|
SET s1 = IFNULL(s1,''), s2 = IFNULL(s2,'');
|
13
|
-
SET s1_len = CHAR_LENGTH(IFNULL(s1,'')), s2_len = CHAR_LENGTH(IFNULL(s2,'')), cv1 = 0x00, j = 1, i = 1, c = 0;
|
14
|
-
IF s1_len = 0 THEN
|
15
|
-
RETURN s2_len;
|
16
|
-
ELSEIF s2_len = 0 THEN
|
17
|
-
RETURN s1_len;
|
18
|
-
ELSEIF s1 = s2 THEN
|
13
|
+
SET s1_len = CHAR_LENGTH(IFNULL(s1,'')), s2_len = CHAR_LENGTH(IFNULL(s2,'')), cv1 = 0x00, j = 1, i = 1, c = 0;
|
14
|
+
IF s1_len = 0 THEN
|
15
|
+
RETURN s2_len;
|
16
|
+
ELSEIF s2_len = 0 THEN
|
17
|
+
RETURN s1_len;
|
18
|
+
ELSEIF s1 = s2 THEN
|
19
19
|
RETURN 0;
|
20
|
-
ELSE
|
21
|
-
WHILE j <= s2_len DO
|
22
|
-
SET cv1 = CONCAT(cv1, UNHEX(HEX(j))), j = j + 1;
|
23
|
-
END WHILE;
|
24
|
-
WHILE i <= s1_len DO
|
25
|
-
SET s1_char = SUBSTRING(s1, i, 1), c = i, cv0 = UNHEX(HEX(i)), j = 1;
|
26
|
-
WHILE j <= s2_len DO
|
27
|
-
SET c = c + 1;
|
28
|
-
IF s1_char = SUBSTRING(s2, j, 1) THEN
|
29
|
-
SET cost = 0; ELSE SET cost = 1;
|
30
|
-
END IF;
|
31
|
-
SET c_temp = CONV(HEX(SUBSTRING(cv1, j, 1)), 16, 10) + cost;
|
32
|
-
IF c > c_temp THEN SET c = c_temp; END IF;
|
33
|
-
SET c_temp = CONV(HEX(SUBSTRING(cv1, j+1, 1)), 16, 10) + 1;
|
34
|
-
IF c > c_temp THEN
|
35
|
-
SET c = c_temp;
|
36
|
-
END IF;
|
37
|
-
SET cv0 = CONCAT(cv0, UNHEX(HEX(c))), j = j + 1;
|
38
|
-
END WHILE;
|
39
|
-
SET cv1 = cv0, i = i + 1;
|
40
|
-
END WHILE;
|
41
|
-
END IF;
|
42
|
-
RETURN c;
|
20
|
+
ELSE
|
21
|
+
WHILE j <= s2_len DO
|
22
|
+
SET cv1 = CONCAT(cv1, UNHEX(HEX(j))), j = j + 1;
|
23
|
+
END WHILE;
|
24
|
+
WHILE i <= s1_len DO
|
25
|
+
SET s1_char = SUBSTRING(s1, i, 1), c = i, cv0 = UNHEX(HEX(i)), j = 1;
|
26
|
+
WHILE j <= s2_len DO
|
27
|
+
SET c = c + 1;
|
28
|
+
IF s1_char = SUBSTRING(s2, j, 1) THEN
|
29
|
+
SET cost = 0; ELSE SET cost = 1;
|
30
|
+
END IF;
|
31
|
+
SET c_temp = CONV(HEX(SUBSTRING(cv1, j, 1)), 16, 10) + cost;
|
32
|
+
IF c > c_temp THEN SET c = c_temp; END IF;
|
33
|
+
SET c_temp = CONV(HEX(SUBSTRING(cv1, j+1, 1)), 16, 10) + 1;
|
34
|
+
IF c > c_temp THEN
|
35
|
+
SET c = c_temp;
|
36
|
+
END IF;
|
37
|
+
SET cv0 = CONCAT(cv0, UNHEX(HEX(c))), j = j + 1;
|
38
|
+
END WHILE;
|
39
|
+
SET cv1 = cv0, i = i + 1;
|
40
|
+
END WHILE;
|
41
|
+
END IF;
|
42
|
+
RETURN c;
|
43
43
|
END;$$
|
44
|
-
|
44
|
+
|
45
45
|
DELIMITER ;
|
data/init/postgresql.sql
CHANGED
@@ -4,17 +4,17 @@ CREATE OR REPLACE FUNCTION public.find_in_set(n INTEGER, s TEXT)
|
|
4
4
|
AS $function$
|
5
5
|
SELECT * FROM (
|
6
6
|
select int4(z.row_number) from (
|
7
|
-
select row_number() over(), y.x
|
7
|
+
select row_number() over(), y.x
|
8
8
|
from (select unnest(('{' || $2 || '}')::int[]) as x) as y
|
9
9
|
) as z
|
10
10
|
where z.x = $1
|
11
|
-
UNION ALL
|
11
|
+
UNION ALL
|
12
12
|
SELECT 0) z
|
13
13
|
LIMIT 1
|
14
14
|
$function$
|
15
15
|
;
|
16
16
|
|
17
|
-
CREATE OR REPLACE FUNCTION public.levenshtein_distance(s text, t text)
|
17
|
+
CREATE OR REPLACE FUNCTION public.levenshtein_distance(s text, t text)
|
18
18
|
RETURNS integer AS $$
|
19
19
|
DECLARE i integer;
|
20
20
|
DECLARE j integer;
|
@@ -48,58 +48,58 @@ BEGIN
|
|
48
48
|
d[i*(n+1)+j] := LEAST(d[(i-1)*(n+1)+j]+1, d[i*(n+1)+j-1]+1, d[(i-1)*(n+1)+j-1]+c);
|
49
49
|
END LOOP;
|
50
50
|
END LOOP;
|
51
|
-
|
52
|
-
return d[m*(n+1)+n];
|
51
|
+
|
52
|
+
return d[m*(n+1)+n];
|
53
53
|
END;
|
54
54
|
$$ LANGUAGE plpgsql IMMUTABLE;
|
55
55
|
|
56
|
-
CREATE OR REPLACE FUNCTION public.DateDiff(units VARCHAR(30), start_t TIMESTAMP, end_t TIMESTAMP)
|
56
|
+
CREATE OR REPLACE FUNCTION public.DateDiff(units VARCHAR(30), start_t TIMESTAMP, end_t TIMESTAMP)
|
57
57
|
RETURNS INT AS $$
|
58
58
|
DECLARE
|
59
|
-
diff_interval INTERVAL;
|
59
|
+
diff_interval INTERVAL;
|
60
60
|
diff INT = 0;
|
61
61
|
years_diff INT = 0;
|
62
62
|
BEGIN
|
63
63
|
IF units IN ('yy', 'yyyy', 'year', 'mm', 'm', 'month') THEN
|
64
64
|
years_diff = DATE_PART('year', end_t) - DATE_PART('year', start_t);
|
65
|
-
|
65
|
+
|
66
66
|
IF units IN ('yy', 'yyyy', 'year') THEN
|
67
67
|
-- SQL Server does not count full years passed (only difference between year parts)
|
68
68
|
RETURN years_diff;
|
69
69
|
ELSE
|
70
70
|
-- If end month is less than start month it will subtracted
|
71
|
-
RETURN years_diff * 12 + (DATE_PART('month', end_t) - DATE_PART('month', start_t));
|
71
|
+
RETURN years_diff * 12 + (DATE_PART('month', end_t) - DATE_PART('month', start_t));
|
72
72
|
END IF;
|
73
73
|
END IF;
|
74
|
-
|
75
|
-
-- Minus operator returns interval 'DDD days HH:MI:SS'
|
74
|
+
|
75
|
+
-- Minus operator returns interval 'DDD days HH:MI:SS'
|
76
76
|
diff_interval = end_t - start_t;
|
77
|
-
|
77
|
+
|
78
78
|
diff = diff + DATE_PART('day', diff_interval);
|
79
|
-
|
79
|
+
|
80
80
|
IF units IN ('wk', 'ww', 'week') THEN
|
81
81
|
diff = diff/7;
|
82
82
|
RETURN diff;
|
83
83
|
END IF;
|
84
|
-
|
84
|
+
|
85
85
|
IF units IN ('dd', 'd', 'day') THEN
|
86
86
|
RETURN diff;
|
87
87
|
END IF;
|
88
|
-
|
89
|
-
diff = diff * 24 + DATE_PART('hour', diff_interval);
|
90
|
-
|
88
|
+
|
89
|
+
diff = diff * 24 + DATE_PART('hour', diff_interval);
|
90
|
+
|
91
91
|
IF units IN ('hh', 'hour') THEN
|
92
92
|
RETURN diff;
|
93
93
|
END IF;
|
94
|
-
|
94
|
+
|
95
95
|
diff = diff * 60 + DATE_PART('minute', diff_interval);
|
96
|
-
|
96
|
+
|
97
97
|
IF units IN ('mi', 'n', 'minute') THEN
|
98
98
|
RETURN diff;
|
99
99
|
END IF;
|
100
|
-
|
100
|
+
|
101
101
|
diff = diff * 60 + DATE_PART('second', diff_interval);
|
102
|
-
|
102
|
+
|
103
103
|
RETURN diff;
|
104
104
|
END;
|
105
105
|
$$ LANGUAGE plpgsql;
|
data/lib/arel_extensions.rb
CHANGED
@@ -7,35 +7,37 @@ require 'arel_extensions/railtie' if defined?(Rails::Railtie)
|
|
7
7
|
# Count|NamedFunction < Function < Arel::Nodes::Node
|
8
8
|
|
9
9
|
# pure Arel internals improvements
|
10
|
-
Arel::Nodes::Binary
|
10
|
+
class Arel::Nodes::Binary
|
11
11
|
include Arel::AliasPredication
|
12
12
|
include Arel::Expressions
|
13
13
|
end
|
14
14
|
|
15
|
-
Arel::Nodes::Casted
|
15
|
+
class Arel::Nodes::Casted
|
16
16
|
include Arel::AliasPredication
|
17
|
+
|
18
|
+
# They forget to define hash.
|
19
|
+
def hash
|
20
|
+
[self.class, self.val, self.attribute].hash
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
19
|
-
Arel::Nodes::Unary
|
24
|
+
class Arel::Nodes::Unary
|
20
25
|
include Arel::Math
|
21
26
|
include Arel::AliasPredication
|
22
27
|
include Arel::Expressions
|
23
28
|
end
|
24
29
|
|
25
|
-
Arel::Nodes::Grouping
|
26
|
-
include Arel::Math
|
27
|
-
include Arel::AliasPredication
|
30
|
+
class Arel::Nodes::Grouping
|
28
31
|
include Arel::OrderPredications
|
29
|
-
include Arel::Expressions
|
30
32
|
end
|
31
33
|
|
32
|
-
Arel::Nodes::Function
|
34
|
+
class Arel::Nodes::Function
|
33
35
|
include Arel::Math
|
34
36
|
include Arel::Expressions
|
35
37
|
end
|
36
38
|
|
37
|
-
if Arel::VERSION >= "7.1.0"
|
38
|
-
Arel::Nodes::Case
|
39
|
+
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("7.1.0")
|
40
|
+
class Arel::Nodes::Case
|
39
41
|
include Arel::Math
|
40
42
|
include Arel::Expressions
|
41
43
|
end
|
@@ -93,14 +95,26 @@ module Arel
|
|
93
95
|
ArelExtensions::Nodes::Duration.new(s.to_s+'i',expr)
|
94
96
|
end
|
95
97
|
|
98
|
+
def self.true
|
99
|
+
Arel::Nodes::Equality.new(1,1)
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.false
|
103
|
+
Arel::Nodes::Equality.new(1,0)
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.tuple *v
|
107
|
+
tmp = Arel::Nodes::Grouping.new(nil)
|
108
|
+
Arel::Nodes::Grouping.new(v.map{|e| tmp.convert_to_node(e)})
|
109
|
+
end
|
96
110
|
end
|
97
111
|
|
98
|
-
Arel::Attributes::Attribute
|
112
|
+
class Arel::Attributes::Attribute
|
99
113
|
include Arel::Math
|
100
114
|
include ArelExtensions::Attributes
|
101
115
|
end
|
102
116
|
|
103
|
-
Arel::Nodes::Function
|
117
|
+
class Arel::Nodes::Function
|
104
118
|
include ArelExtensions::Math
|
105
119
|
include ArelExtensions::Comparators
|
106
120
|
include ArelExtensions::DateDuration
|
@@ -109,9 +123,24 @@ Arel::Nodes::Function.class_eval do
|
|
109
123
|
include ArelExtensions::BooleanFunctions
|
110
124
|
include ArelExtensions::NullFunctions
|
111
125
|
include ArelExtensions::Predications
|
126
|
+
|
127
|
+
alias_method :old_as, :as
|
128
|
+
def as other
|
129
|
+
Arel::Nodes::As.new(self, Arel.sql(other))
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
class Arel::Nodes::Grouping
|
134
|
+
include ArelExtensions::Math
|
135
|
+
include ArelExtensions::Comparators
|
136
|
+
include ArelExtensions::DateDuration
|
137
|
+
include ArelExtensions::MathFunctions
|
138
|
+
include ArelExtensions::NullFunctions
|
139
|
+
include ArelExtensions::StringFunctions
|
140
|
+
include ArelExtensions::Predications
|
112
141
|
end
|
113
142
|
|
114
|
-
Arel::Nodes::Unary
|
143
|
+
class Arel::Nodes::Unary
|
115
144
|
include ArelExtensions::Math
|
116
145
|
include ArelExtensions::Attributes
|
117
146
|
include ArelExtensions::MathFunctions
|
@@ -119,7 +148,7 @@ Arel::Nodes::Unary.class_eval do
|
|
119
148
|
include ArelExtensions::Predications
|
120
149
|
end
|
121
150
|
|
122
|
-
Arel::Nodes::Binary
|
151
|
+
class Arel::Nodes::Binary
|
123
152
|
include ArelExtensions::Math
|
124
153
|
include ArelExtensions::Attributes
|
125
154
|
include ArelExtensions::MathFunctions
|
@@ -128,25 +157,40 @@ Arel::Nodes::Binary.class_eval do
|
|
128
157
|
include ArelExtensions::Predications
|
129
158
|
end
|
130
159
|
|
131
|
-
Arel::Nodes::Equality
|
160
|
+
class Arel::Nodes::Equality
|
132
161
|
include ArelExtensions::Comparators
|
133
162
|
include ArelExtensions::DateDuration
|
134
163
|
include ArelExtensions::MathFunctions
|
135
164
|
include ArelExtensions::StringFunctions
|
136
165
|
end
|
137
166
|
|
138
|
-
|
139
|
-
Arel::InsertManager.class_eval do
|
167
|
+
class Arel::InsertManager
|
140
168
|
include ArelExtensions::InsertManager
|
141
169
|
end
|
142
170
|
|
143
|
-
Arel::SelectManager
|
171
|
+
class Arel::SelectManager
|
144
172
|
include ArelExtensions::SetFunctions
|
145
173
|
include ArelExtensions::Nodes
|
146
174
|
end
|
147
175
|
|
148
|
-
Arel::Nodes::As
|
176
|
+
class Arel::Nodes::As
|
149
177
|
include ArelExtensions::Nodes
|
150
178
|
end
|
151
179
|
|
180
|
+
class Arel::Table
|
181
|
+
alias_method :old_alias, :alias
|
182
|
+
def alias(name = "#{self.name}_2")
|
183
|
+
name.blank? ? self : Arel::Nodes::TableAlias.new(self,name)
|
184
|
+
end
|
185
|
+
end
|
152
186
|
|
187
|
+
class Arel::Nodes::TableAlias
|
188
|
+
def method_missing(*args)
|
189
|
+
met = args.shift.to_sym
|
190
|
+
if self.relation.respond_to?(met)
|
191
|
+
self.relation.send(met,args)
|
192
|
+
else
|
193
|
+
super(met,*args)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|