arel_extensions 1.7.0 → 2.0.0.rc3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -1
- data/.gitignore +6 -8
- data/.rubocop.yml +4 -194
- 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 +89 -265
- data/Rakefile +30 -50
- data/TODO +1 -0
- data/appveyor.yml +22 -60
- data/arel_extensions.gemspec +17 -14
- data/functions.html +3 -3
- data/gemfiles/rails3.gemfile +20 -0
- data/gemfiles/rails4.gemfile +29 -0
- data/gemfiles/rails5_0.gemfile +29 -0
- data/gemfiles/rails5_1_4.gemfile +17 -19
- data/gemfiles/rails5_2.gemfile +17 -26
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/oracle.sql +0 -0
- data/init/postgresql.sql +25 -24
- data/init/sqlite.sql +0 -0
- data/lib/arel_extensions/attributes.rb +3 -9
- data/lib/arel_extensions/boolean_functions.rb +16 -57
- data/lib/arel_extensions/common_sql_functions.rb +20 -21
- data/lib/arel_extensions/comparators.rb +28 -31
- data/lib/arel_extensions/date_duration.rb +13 -19
- data/lib/arel_extensions/insert_manager.rb +15 -22
- data/lib/arel_extensions/math.rb +70 -68
- data/lib/arel_extensions/math_functions.rb +52 -57
- data/lib/arel_extensions/nodes/abs.rb +1 -0
- data/lib/arel_extensions/nodes/blank.rb +5 -6
- data/lib/arel_extensions/nodes/case.rb +27 -31
- data/lib/arel_extensions/nodes/cast.rb +12 -12
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/coalesce.rb +5 -4
- data/lib/arel_extensions/nodes/collate.rb +10 -9
- data/lib/arel_extensions/nodes/concat.rb +22 -13
- data/lib/arel_extensions/nodes/date_diff.rb +70 -77
- data/lib/arel_extensions/nodes/duration.rb +5 -2
- 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 +39 -50
- data/lib/arel_extensions/nodes/is_null.rb +0 -2
- data/lib/arel_extensions/nodes/json.rb +47 -72
- data/lib/arel_extensions/nodes/length.rb +0 -5
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +2 -2
- data/lib/arel_extensions/nodes/locate.rb +3 -2
- data/lib/arel_extensions/nodes/log10.rb +2 -1
- data/lib/arel_extensions/nodes/matches.rb +8 -6
- 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 +3 -2
- data/lib/arel_extensions/nodes/repeat.rb +6 -4
- data/lib/arel_extensions/nodes/replace.rb +8 -16
- data/lib/arel_extensions/nodes/round.rb +7 -6
- 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 -58
- data/lib/arel_extensions/nodes/then.rb +2 -2
- data/lib/arel_extensions/nodes/trim.rb +7 -5
- data/lib/arel_extensions/nodes/union.rb +9 -6
- data/lib/arel_extensions/nodes/union_all.rb +8 -5
- data/lib/arel_extensions/nodes/wday.rb +6 -2
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/null_functions.rb +6 -18
- data/lib/arel_extensions/predications.rb +49 -54
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +7 -5
- data/lib/arel_extensions/string_functions.rb +55 -110
- data/lib/arel_extensions/tasks.rb +6 -6
- data/lib/arel_extensions/version.rb +1 -3
- data/lib/arel_extensions/visitors/ibm_db.rb +36 -29
- data/lib/arel_extensions/visitors/mssql.rb +248 -493
- data/lib/arel_extensions/visitors/mysql.rb +244 -420
- data/lib/arel_extensions/visitors/oracle.rb +258 -311
- data/lib/arel_extensions/visitors/oracle12.rb +34 -20
- data/lib/arel_extensions/visitors/postgresql.rb +239 -350
- data/lib/arel_extensions/visitors/sqlite.rb +169 -191
- data/lib/arel_extensions/visitors/to_sql.rb +299 -371
- data/lib/arel_extensions/visitors.rb +62 -83
- data/lib/arel_extensions.rb +32 -243
- data/test/database.yml +10 -20
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +120 -123
- data/test/support/fake_record.rb +3 -11
- data/test/test_comparators.rb +17 -14
- data/test/visitors/test_bulk_insert_oracle.rb +12 -12
- data/test/visitors/test_bulk_insert_sqlite.rb +14 -13
- 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 +375 -912
- data/test/with_ar/insert_agnostic_test.rb +22 -28
- data/test/with_ar/test_bulk_sqlite.rb +17 -18
- data/test/with_ar/test_math_sqlite.rb +27 -27
- data/test/with_ar/test_string_mysql.rb +34 -32
- data/test/with_ar/test_string_sqlite.rb +35 -31
- metadata +64 -50
- data/.github/workflows/publish.yml +0 -30
- data/.github/workflows/release.yml +0 -30
- data/.github/workflows/ruby.yml +0 -452
- data/CONTRIBUTING.md +0 -102
- data/Makefile +0 -48
- data/NEWS.md +0 -131
- data/bin/build +0 -15
- data/bin/publish +0 -8
- data/dev/arelx.dockerfile +0 -41
- data/dev/compose.yaml +0 -69
- data/dev/postgres.dockerfile +0 -5
- data/dev/rbenv +0 -189
- data/gemfiles/rails5.gemfile +0 -36
- data/gemfiles/rails6.gemfile +0 -40
- data/gemfiles/rails6_1.gemfile +0 -48
- data/gemfiles/rails7.gemfile +0 -48
- data/gemfiles/rails7_1.gemfile +0 -48
- data/gemfiles/rails7_2.gemfile +0 -47
- data/gemfiles/rails8.gemfile +0 -40
- data/gemfiles/rails8_1.gemfile +0 -41
- data/gemspecs/arel_extensions-v1.gemspec +0 -25
- data/gemspecs/arel_extensions-v2.gemspec +0 -25
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/aliases.rb +0 -14
- data/lib/arel_extensions/constants.rb +0 -13
- data/lib/arel_extensions/helpers.rb +0 -61
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- data/lib/arel_extensions/nodes/byte_size.rb +0 -11
- data/lib/arel_extensions/nodes/char_length.rb +0 -11
- 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/lib/arel_extensions/warning.rb +0 -42
- data/test/arelx_test_helper.rb +0 -94
- data/test/config_loader.rb +0 -9
- data/version_v1.rb +0 -5
- data/version_v2.rb +0 -5
|
@@ -3,35 +3,23 @@ require 'arel_extensions/nodes/is_null'
|
|
|
3
3
|
|
|
4
4
|
module ArelExtensions
|
|
5
5
|
module NullFunctions
|
|
6
|
-
# if_present returns nil if the the value is nil or blank
|
|
7
|
-
def if_present
|
|
8
|
-
Arel.when(cast(:string).present).then(self)
|
|
9
|
-
end
|
|
10
6
|
|
|
11
|
-
#
|
|
7
|
+
#ISNULL function lets you return an alternative value when an expression is NULL.
|
|
12
8
|
def is_null
|
|
13
9
|
ArelExtensions::Nodes::IsNull.new [self]
|
|
14
10
|
end
|
|
15
|
-
|
|
16
|
-
#
|
|
11
|
+
|
|
12
|
+
#ISNOTNULL function lets you return an alternative value when an expression is NOT NULL.
|
|
17
13
|
def is_not_null
|
|
18
14
|
ArelExtensions::Nodes::IsNotNull.new [self]
|
|
19
15
|
end
|
|
20
|
-
|
|
16
|
+
|
|
21
17
|
# returns the first non-null expr in the expression list. You must specify at least two expressions.
|
|
22
|
-
#
|
|
23
|
-
def coalesce
|
|
18
|
+
#If all occurrences of expr evaluate to null, then the function returns null.
|
|
19
|
+
def coalesce *args
|
|
24
20
|
args.unshift(self)
|
|
25
21
|
ArelExtensions::Nodes::Coalesce.new args
|
|
26
22
|
end
|
|
27
23
|
|
|
28
|
-
def coalesce_blank(*args)
|
|
29
|
-
res = Arel.when(cast(:string).present).then(self)
|
|
30
|
-
args[0...-1].each do |a|
|
|
31
|
-
val = a.is_a?(Arel::Nodes::Node) ? a : Arel.quoted(a)
|
|
32
|
-
res = res.when(val.present).then(a)
|
|
33
|
-
end
|
|
34
|
-
res.else(args[-1])
|
|
35
|
-
end
|
|
36
24
|
end
|
|
37
25
|
end
|
|
@@ -1,80 +1,76 @@
|
|
|
1
1
|
module ArelExtensions
|
|
2
2
|
module Predications
|
|
3
|
-
def when
|
|
4
|
-
ArelExtensions::Nodes::Case.new(self).when(right,
|
|
3
|
+
def when right, expression=nil
|
|
4
|
+
ArelExtensions::Nodes::Case.new(self).when(right,expression)
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
def matches(other, escape
|
|
8
|
-
if
|
|
9
|
-
Arel::Nodes::Matches.new(self, Arel.
|
|
7
|
+
def matches(other, escape=nil,case_sensitive= nil)
|
|
8
|
+
if Arel::VERSION.to_i < 7
|
|
9
|
+
Arel::Nodes::Matches.new(self, Arel::Nodes.build_quoted(other), escape)
|
|
10
10
|
else
|
|
11
|
-
Arel::Nodes::Matches.new(self, Arel.
|
|
11
|
+
Arel::Nodes::Matches.new(self, Arel::Nodes.build_quoted(other), escape, case_sensitive)
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def imatches(other, escape
|
|
15
|
+
def imatches(other, escape=nil)
|
|
16
16
|
ArelExtensions::Nodes::IMatches.new(self, other, escape)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def cast
|
|
20
|
-
ArelExtensions::Nodes::Cast.new([self,
|
|
19
|
+
def cast right
|
|
20
|
+
ArelExtensions::Nodes::Cast.new([self,right])
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
def in(
|
|
24
|
-
other = other.first if other.length <= 1
|
|
23
|
+
def in(other) #In should handle nil element in the Array
|
|
25
24
|
case other
|
|
26
25
|
when Range
|
|
27
|
-
between(other)
|
|
28
|
-
when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
|
|
29
|
-
Arel::Nodes::In.new(self, quoted_node(other))
|
|
26
|
+
self.between(other)
|
|
30
27
|
when Enumerable
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
28
|
+
if other.include?(nil)
|
|
29
|
+
other.delete(nil)
|
|
30
|
+
case other.length
|
|
31
|
+
when 0
|
|
32
|
+
self.is_null
|
|
33
|
+
when 1
|
|
34
|
+
self.is_null.or(self==other[0])
|
|
35
|
+
else
|
|
36
|
+
self.is_null.or(Arel::Nodes::In.new(self,quoted_array(other)))
|
|
37
|
+
end
|
|
38
|
+
else
|
|
39
|
+
Arel::Nodes::In.new(self,quoted_array(other))
|
|
40
|
+
end
|
|
43
41
|
when nil
|
|
44
|
-
is_null
|
|
42
|
+
self.is_null
|
|
45
43
|
when Arel::SelectManager
|
|
46
44
|
Arel::Nodes::In.new(self, other.ast)
|
|
47
45
|
else
|
|
48
|
-
Arel::Nodes::In.new(self,
|
|
46
|
+
Arel::Nodes::In.new(self,quoted_node(other))
|
|
49
47
|
end
|
|
50
48
|
end
|
|
51
49
|
|
|
52
|
-
def not_in(
|
|
53
|
-
other = other.first if other.length <= 1
|
|
50
|
+
def not_in(other) #In should handle nil element in the Array
|
|
54
51
|
case other
|
|
55
52
|
when Range
|
|
56
|
-
Arel::Nodes::Not.new(between(other))
|
|
57
|
-
when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
|
|
58
|
-
Arel::Nodes::NotIn.new(self, quoted_node(other))
|
|
53
|
+
Arel::Nodes::Not.new(self.between(other))
|
|
59
54
|
when Enumerable
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
55
|
+
if other.include?(nil)
|
|
56
|
+
other.delete(nil)
|
|
57
|
+
case other.length
|
|
58
|
+
when 0
|
|
59
|
+
self.is_not_null
|
|
60
|
+
when 1
|
|
61
|
+
self.is_not_null.and(self!=other[0])
|
|
62
|
+
else
|
|
63
|
+
self.is_not_null.and(Arel::Nodes::NotIn.new(self,quoted_array(other)))
|
|
64
|
+
end
|
|
65
|
+
else
|
|
66
|
+
Arel::Nodes::NotIn.new(self,quoted_array(other))
|
|
67
|
+
end
|
|
72
68
|
when nil
|
|
73
|
-
is_not_null
|
|
69
|
+
self.is_not_null
|
|
74
70
|
when Arel::SelectManager
|
|
75
71
|
Arel::Nodes::NotIn.new(self, other.ast)
|
|
76
72
|
else
|
|
77
|
-
Arel::Nodes::NotIn.new(self,
|
|
73
|
+
Arel::Nodes::NotIn.new(self,quoted_node(other))
|
|
78
74
|
end
|
|
79
75
|
end
|
|
80
76
|
|
|
@@ -83,22 +79,21 @@ module ArelExtensions
|
|
|
83
79
|
when Arel::Attributes::Attribute, Arel::Nodes::Node, Integer
|
|
84
80
|
object
|
|
85
81
|
when DateTime
|
|
86
|
-
Arel.
|
|
82
|
+
Arel::Nodes.build_quoted(object, self)
|
|
87
83
|
when Time
|
|
88
|
-
Arel.
|
|
84
|
+
Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
|
|
89
85
|
when String
|
|
90
|
-
Arel.
|
|
91
|
-
when TrueClass, FalseClass
|
|
92
|
-
Arel.quoted(object)
|
|
86
|
+
Arel::Nodes.build_quoted(object)
|
|
93
87
|
when Date
|
|
94
|
-
Arel.
|
|
88
|
+
Arel::Nodes.build_quoted(object.to_s, self)
|
|
95
89
|
when NilClass
|
|
96
90
|
Arel.sql('NULL')
|
|
97
91
|
when ActiveSupport::Duration
|
|
98
92
|
object.to_i
|
|
99
93
|
else
|
|
100
|
-
raise(ArgumentError, "#{object.class}
|
|
94
|
+
raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
|
|
101
95
|
end
|
|
102
96
|
end
|
|
97
|
+
|
|
103
98
|
end
|
|
104
99
|
end
|
|
@@ -3,28 +3,30 @@ require 'arel_extensions/nodes/union_all'
|
|
|
3
3
|
|
|
4
4
|
module ArelExtensions
|
|
5
5
|
module SetFunctions
|
|
6
|
+
|
|
6
7
|
def +(other)
|
|
7
|
-
ArelExtensions::Nodes::Union.new(self,
|
|
8
|
+
ArelExtensions::Nodes::Union.new(self,other)
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def union(other)
|
|
11
|
-
ArelExtensions::Nodes::Union.new(self,
|
|
12
|
+
ArelExtensions::Nodes::Union.new(self,other)
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def union_all(other)
|
|
15
|
-
ArelExtensions::Nodes::UnionAll.new(self,
|
|
16
|
+
ArelExtensions::Nodes::UnionAll.new(self,other)
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def uniq
|
|
19
20
|
self
|
|
20
21
|
end
|
|
22
|
+
|
|
21
23
|
end
|
|
22
24
|
end
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
Arel::Nodes::Union.class_eval do
|
|
25
27
|
include ArelExtensions::SetFunctions
|
|
26
28
|
end
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
Arel::Nodes::UnionAll.class_eval do
|
|
29
31
|
include ArelExtensions::SetFunctions
|
|
30
32
|
end
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
require 'arel_extensions/nodes/
|
|
2
|
-
require 'arel_extensions/nodes/char_length'
|
|
3
|
-
require 'arel_extensions/nodes/concat' # if Arel::VERSION.to_i < 7
|
|
1
|
+
require 'arel_extensions/nodes/concat' #if Arel::VERSION.to_i < 7
|
|
4
2
|
require 'arel_extensions/nodes/length'
|
|
5
3
|
require 'arel_extensions/nodes/locate'
|
|
6
4
|
require 'arel_extensions/nodes/substring'
|
|
@@ -18,179 +16,127 @@ require 'arel_extensions/nodes/collate'
|
|
|
18
16
|
require 'arel_extensions/nodes/levenshtein_distance'
|
|
19
17
|
require 'arel_extensions/nodes/md5'
|
|
20
18
|
|
|
19
|
+
|
|
21
20
|
module ArelExtensions
|
|
22
21
|
module StringFunctions
|
|
23
|
-
include ArelExtensions::Warning
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
#*FindInSet function .......
|
|
26
24
|
def &(other)
|
|
27
|
-
ArelExtensions::Nodes::FindInSet.new [
|
|
28
|
-
Arel.quoted(other.is_a?(Integer) ? other.to_s : other),
|
|
29
|
-
self
|
|
30
|
-
]
|
|
25
|
+
ArelExtensions::Nodes::FindInSet.new [other, self]
|
|
31
26
|
end
|
|
32
27
|
|
|
33
|
-
#
|
|
28
|
+
#LENGTH function returns the length of the value in a text field.
|
|
34
29
|
def length
|
|
35
|
-
|
|
36
|
-
ArelExtensions::Nodes::Length.new self, true
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def byte_length
|
|
40
|
-
deprecated "Use `byte_size` instead. `byte_length` relies on the vendor's `LEN/LENGTH` implementation and it's not portable"
|
|
41
|
-
ArelExtensions::Nodes::Length.new self, true
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def byte_size
|
|
45
|
-
ArelExtensions::Nodes::ByteSize.new self
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def char_length
|
|
49
|
-
ArelExtensions::Nodes::CharLength.new self
|
|
30
|
+
ArelExtensions::Nodes::Length.new [self]
|
|
50
31
|
end
|
|
51
32
|
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
def locate
|
|
33
|
+
#LOCATE function returns the first starting position of a string in another string.
|
|
34
|
+
#If string1 or string2 is NULL then it returns NULL. If string1 not found in string2 then it returns 0.
|
|
35
|
+
def locate val
|
|
55
36
|
ArelExtensions::Nodes::Locate.new [self, val]
|
|
56
37
|
end
|
|
57
38
|
|
|
58
|
-
def substring
|
|
39
|
+
def substring start, len = nil
|
|
59
40
|
ArelExtensions::Nodes::Substring.new [self, start, len]
|
|
60
41
|
end
|
|
61
42
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
#
|
|
69
|
-
# @note `ind` should be an [Integer|NilClass] if `start` is an [Integer].
|
|
70
|
-
# It's ignored in all other cases.
|
|
71
|
-
def [](start, end_ = nil)
|
|
72
|
-
if start.is_a?(String) || start.is_a?(Symbol)
|
|
73
|
-
send(start)
|
|
74
|
-
elsif start.is_a?(Range)
|
|
75
|
-
ArelExtensions::Nodes::Substring.new [self, start]
|
|
76
|
-
elsif start.is_a?(Integer) && !end_
|
|
77
|
-
ArelExtensions::Nodes::Substring.new [self, start + 1, 1]
|
|
78
|
-
elsif start.is_a?(Integer)
|
|
79
|
-
start += 1
|
|
80
|
-
ArelExtensions::Nodes::Substring.new [self, start, end_ - start + 1]
|
|
43
|
+
def [](start, ind = nil)
|
|
44
|
+
start += 1 if start.is_a?(Integer)
|
|
45
|
+
if start.is_a?(Range)
|
|
46
|
+
ArelExtensions::Nodes::Substring.new [self, start.begin + 1, start.end - start.begin + 1]
|
|
47
|
+
elsif start.is_a?(Integer) && !ind
|
|
48
|
+
ArelExtensions::Nodes::Substring.new [self, start, 1]
|
|
81
49
|
else
|
|
82
|
-
|
|
50
|
+
ArelExtensions::Nodes::Substring.new [self, start, ind - start + 1]
|
|
83
51
|
end
|
|
84
52
|
end
|
|
85
53
|
|
|
86
|
-
#
|
|
54
|
+
#SOUNDEX function returns a character string containing the phonetic representation of char.
|
|
87
55
|
def soundex
|
|
88
56
|
ArelExtensions::Nodes::Soundex.new [self]
|
|
89
57
|
end
|
|
90
58
|
|
|
91
|
-
def imatches
|
|
59
|
+
def imatches others, escape = nil
|
|
92
60
|
ArelExtensions::Nodes::IMatches.new self, others, escape
|
|
93
61
|
end
|
|
94
62
|
|
|
95
|
-
def imatches_any
|
|
63
|
+
def imatches_any others, escape = nil
|
|
96
64
|
grouping_any :imatches, others, escape
|
|
97
65
|
end
|
|
98
66
|
|
|
99
|
-
|
|
100
|
-
# puts "*******************"
|
|
101
|
-
# puts method
|
|
102
|
-
# puts others.inspect
|
|
103
|
-
# puts extra.inspect
|
|
104
|
-
# puts "-------------------"
|
|
105
|
-
# res = super(method,others,*extra)
|
|
106
|
-
# puts res.to_sql
|
|
107
|
-
# puts res.inspect
|
|
108
|
-
# puts "*******************"
|
|
109
|
-
# res
|
|
110
|
-
# end
|
|
111
|
-
|
|
112
|
-
def imatches_all(others, escape = nil)
|
|
67
|
+
def imatches_all others, escape = nil
|
|
113
68
|
grouping_all :imatches, others, escape, escape
|
|
114
69
|
end
|
|
115
70
|
|
|
116
|
-
def idoes_not_match
|
|
71
|
+
def idoes_not_match others, escape = nil
|
|
117
72
|
ArelExtensions::Nodes::IDoesNotMatch.new self, others, escape
|
|
118
73
|
end
|
|
119
74
|
|
|
120
|
-
def idoes_not_match_any
|
|
75
|
+
def idoes_not_match_any others, escape = nil
|
|
121
76
|
grouping_any :idoes_not_match, others, escape
|
|
122
77
|
end
|
|
123
78
|
|
|
124
|
-
def idoes_not_match_all
|
|
79
|
+
def idoes_not_match_all others, escape = nil
|
|
125
80
|
grouping_all :idoes_not_match, others, escape
|
|
126
81
|
end
|
|
127
82
|
|
|
128
|
-
def ai_matches
|
|
129
|
-
ArelExtensions::Nodes::AiMatches.new(self,
|
|
83
|
+
def ai_matches other # accent insensitive & case sensitive
|
|
84
|
+
ArelExtensions::Nodes::AiMatches.new(self,other)
|
|
130
85
|
end
|
|
131
86
|
|
|
132
|
-
def ai_imatches
|
|
133
|
-
ArelExtensions::Nodes::AiIMatches.new(self,
|
|
87
|
+
def ai_imatches other # accent insensitive & case insensitive
|
|
88
|
+
ArelExtensions::Nodes::AiIMatches.new(self,other)
|
|
134
89
|
end
|
|
135
90
|
|
|
136
|
-
def smatches
|
|
137
|
-
ArelExtensions::Nodes::SMatches.new(self,
|
|
91
|
+
def smatches other # accent sensitive & case sensitive
|
|
92
|
+
ArelExtensions::Nodes::SMatches.new(self,other)
|
|
138
93
|
end
|
|
139
94
|
|
|
140
|
-
def ai_collate
|
|
141
|
-
ArelExtensions::Nodes::Collate.new(self,
|
|
95
|
+
def ai_collate
|
|
96
|
+
ArelExtensions::Nodes::Collate.new(self,nil,true,false)
|
|
142
97
|
end
|
|
143
98
|
|
|
144
99
|
def ci_collate
|
|
145
|
-
ArelExtensions::Nodes::Collate.new(self,
|
|
100
|
+
ArelExtensions::Nodes::Collate.new(self,nil,false,true)
|
|
146
101
|
end
|
|
147
102
|
|
|
148
|
-
def collate
|
|
149
|
-
ArelExtensions::Nodes::Collate.new(self,
|
|
103
|
+
def collate ai=false,ci=false, option=nil
|
|
104
|
+
ArelExtensions::Nodes::Collate.new(self,option,ai,ci)
|
|
150
105
|
end
|
|
151
106
|
|
|
152
|
-
#
|
|
153
|
-
def replace
|
|
154
|
-
|
|
155
|
-
ArelExtensions::Nodes::RegexpReplace.new self, pattern, substitute
|
|
156
|
-
else
|
|
157
|
-
ArelExtensions::Nodes::Replace.new self, pattern, substitute
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def regexp_replace(pattern, substitute)
|
|
162
|
-
ArelExtensions::Nodes::RegexpReplace.new self, pattern, substitute
|
|
107
|
+
#REPLACE function replaces a sequence of characters in a string with another set of characters, not case-sensitive.
|
|
108
|
+
def replace left, right
|
|
109
|
+
ArelExtensions::Nodes::Replace.new [self, left, right]
|
|
163
110
|
end
|
|
164
|
-
|
|
165
|
-
def concat
|
|
111
|
+
|
|
112
|
+
def concat other
|
|
166
113
|
ArelExtensions::Nodes::Concat.new [self, other]
|
|
167
114
|
end
|
|
168
115
|
|
|
169
|
-
#
|
|
170
|
-
def group_concat
|
|
171
|
-
|
|
172
|
-
deprecated 'Use the kwarg `order` instead.', what: 'orders'
|
|
173
|
-
end
|
|
174
|
-
order_tabs = [orders].flatten.map { |o|
|
|
116
|
+
#concat elements of a group, separated by sep and ordered by a list of Ascending or Descending
|
|
117
|
+
def group_concat sep = nil, *orders
|
|
118
|
+
order_tabs = [orders].flatten.map{ |o|
|
|
175
119
|
if o.is_a?(Arel::Nodes::Ascending) || o.is_a?(Arel::Nodes::Descending)
|
|
176
120
|
o
|
|
177
121
|
elsif o.respond_to?(:asc)
|
|
178
122
|
o.asc
|
|
123
|
+
else
|
|
124
|
+
nil
|
|
179
125
|
end
|
|
180
126
|
}.compact
|
|
181
|
-
ArelExtensions::Nodes::GroupConcat.new
|
|
127
|
+
ArelExtensions::Nodes::GroupConcat.new [self, sep, order_tabs]
|
|
182
128
|
end
|
|
183
129
|
|
|
184
|
-
#
|
|
185
|
-
def trim
|
|
130
|
+
#Function returns a string after removing left, right or the both prefixes or suffixes int argument
|
|
131
|
+
def trim other = ' '
|
|
186
132
|
ArelExtensions::Nodes::Trim.new [self, other]
|
|
187
133
|
end
|
|
188
134
|
|
|
189
|
-
def ltrim
|
|
135
|
+
def ltrim other = ' '
|
|
190
136
|
ArelExtensions::Nodes::Ltrim.new [self, other]
|
|
191
137
|
end
|
|
192
138
|
|
|
193
|
-
def rtrim
|
|
139
|
+
def rtrim other = ' '
|
|
194
140
|
ArelExtensions::Nodes::Rtrim.new [self, other]
|
|
195
141
|
end
|
|
196
142
|
|
|
@@ -209,17 +155,16 @@ module ArelExtensions
|
|
|
209
155
|
def not_blank
|
|
210
156
|
ArelExtensions::Nodes::NotBlank.new [self]
|
|
211
157
|
end
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
def repeat(other = 1)
|
|
158
|
+
|
|
159
|
+
def repeat other = 1
|
|
215
160
|
ArelExtensions::Nodes::Repeat.new [self, other]
|
|
216
161
|
end
|
|
217
|
-
|
|
218
|
-
def levenshtein_distance
|
|
162
|
+
|
|
163
|
+
def levenshtein_distance other
|
|
219
164
|
ArelExtensions::Nodes::LevenshteinDistance.new [self, other]
|
|
220
165
|
end
|
|
221
166
|
|
|
222
|
-
def edit_distance
|
|
167
|
+
def edit_distance other
|
|
223
168
|
ArelExtensions::Nodes::LevenshteinDistance.new [self, other]
|
|
224
169
|
end
|
|
225
170
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
namespace :arel_extensions do
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
(RUBY_PLATFORM == 'java' ?
|
|
2
|
+
desc 'Install DB functions into current DB'
|
|
3
|
+
task :install_functions => :environment do
|
|
4
|
+
@env_db = if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx") || (RUBY_PLATFORM == 'java')) # not supported
|
|
5
|
+
(RUBY_PLATFORM == 'java' ? "jdbc-sqlite" : 'sqlite')
|
|
6
6
|
else
|
|
7
7
|
ENV['DB'] || ActiveRecord::Base.connection.adapter_name
|
|
8
8
|
end
|
|
9
|
-
ActiveRecord::Base.establish_connection(Rails.env
|
|
9
|
+
ActiveRecord::Base.establish_connection(Rails.env)
|
|
10
10
|
CommonSqlFunctions.new(ActiveRecord::Base.connection).add_sql_functions(@env_db)
|
|
11
|
-
|
|
11
|
+
end
|
|
12
12
|
end
|
|
@@ -1,69 +1,76 @@
|
|
|
1
1
|
module ArelExtensions
|
|
2
2
|
module Visitors
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Arel::Visitors::IBM_DB.class_eval do
|
|
4
|
+
|
|
5
|
+
def visit_ArelExtensions_Nodes_Ceil o, collector
|
|
6
|
+
collector << "CEILING("
|
|
6
7
|
collector = visit o.expr, collector
|
|
7
|
-
collector <<
|
|
8
|
+
collector << ")"
|
|
8
9
|
collector
|
|
9
10
|
end
|
|
10
11
|
|
|
11
|
-
def visit_ArelExtensions_Nodes_Trim
|
|
12
|
-
collector <<
|
|
12
|
+
def visit_ArelExtensions_Nodes_Trim o, collector
|
|
13
|
+
collector << "LTRIM(RTRIM("
|
|
13
14
|
o.expressions.each_with_index { |arg, i|
|
|
14
|
-
collector << COMMA
|
|
15
|
+
collector << Arel::Visitors::IBM_DB::COMMA unless i == 0
|
|
15
16
|
collector = visit arg, collector
|
|
16
17
|
}
|
|
17
|
-
collector <<
|
|
18
|
+
collector << "))"
|
|
18
19
|
collector
|
|
19
20
|
end
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
def visit_ArelExtensions_Nodes_DateDiff o, collector
|
|
24
|
+
collector << "DAY("
|
|
23
25
|
collector = visit o.left, collector
|
|
24
|
-
collector <<
|
|
26
|
+
collector << ","
|
|
25
27
|
if o.right.is_a?(Arel::Attributes::Attribute)
|
|
26
28
|
collector = visit o.right, collector
|
|
27
29
|
else
|
|
28
30
|
collector << "'#{o.right}'"
|
|
29
31
|
end
|
|
30
|
-
collector <<
|
|
32
|
+
collector << ")"
|
|
31
33
|
collector
|
|
32
34
|
end
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
|
|
37
|
+
def visit_ArelExtensions_Nodes_Duration o, collector
|
|
38
|
+
#visit left for period
|
|
39
|
+
if o.left == "d"
|
|
40
|
+
collector << "DAY("
|
|
41
|
+
elsif o.left == "m"
|
|
42
|
+
collector << "MONTH("
|
|
43
|
+
elsif o.left == "w"
|
|
44
|
+
collector << "WEEK"
|
|
45
|
+
elsif o.left == "y"
|
|
46
|
+
collector << "YEAR("
|
|
44
47
|
end
|
|
45
|
-
#
|
|
48
|
+
#visit right
|
|
46
49
|
if o.right.is_a?(Arel::Attributes::Attribute)
|
|
47
50
|
collector = visit o.right, collector
|
|
48
51
|
else
|
|
49
52
|
collector << "'#{o.right}'"
|
|
50
53
|
end
|
|
51
|
-
collector <<
|
|
54
|
+
collector << ")"
|
|
52
55
|
collector
|
|
53
56
|
end
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
|
|
59
|
+
def visit_ArelExtensions_Nodes_IsNull o, collector
|
|
60
|
+
collector << "COALESCE("
|
|
57
61
|
collector = visit o.left, collector
|
|
58
|
-
collector <<
|
|
59
|
-
if
|
|
62
|
+
collector << ","
|
|
63
|
+
if(o.right.is_a?(Arel::Attributes::Attribute))
|
|
60
64
|
collector = visit o.right, collector
|
|
61
65
|
else
|
|
62
66
|
collector << "'#{o.right}'"
|
|
63
67
|
end
|
|
64
|
-
collector <<
|
|
68
|
+
collector << ")"
|
|
65
69
|
collector
|
|
66
70
|
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
67
74
|
end
|
|
68
75
|
end
|
|
69
76
|
end
|