arel_extensions 1.5.3 → 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 -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 +25 -24
- data/init/sqlite.sql +0 -0
- data/lib/arel_extensions/attributes.rb +3 -7
- 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 -29
- 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 -48
- 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 +36 -82
- 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 +192 -423
- data/lib/arel_extensions/visitors/mysql.rb +212 -354
- data/lib/arel_extensions/visitors/oracle.rb +178 -221
- data/lib/arel_extensions/visitors/oracle12.rb +31 -18
- data/lib/arel_extensions/visitors/postgresql.rb +173 -257
- data/lib/arel_extensions/visitors/sqlite.rb +126 -140
- data/lib/arel_extensions/visitors/to_sql.rb +237 -299
- data/lib/arel_extensions/visitors.rb +62 -83
- data/lib/arel_extensions.rb +31 -226
- 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 -721
- 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 +37 -47
- data/.github/workflows/publish.yml +0 -30
- data/.github/workflows/release.yml +0 -30
- data/.github/workflows/ruby.yml +0 -403
- data/CONTRIBUTING.md +0 -102
- data/NEWS.md +0 -109
- 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 -34
- data/gemfiles/rails6_1.gemfile +0 -42
- data/gemfiles/rails7.gemfile +0 -42
- data/gemfiles/rails7_1.gemfile +0 -41
- data/gemfiles/rails7_2.gemfile +0 -41
- 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/lib/arel_extensions/warning.rb +0 -42
- data/test/arelx_test_helper.rb +0 -92
- data/version_v1.rb +0 -3
- data/version_v2.rb +0 -3
|
@@ -2,25 +2,27 @@ module ArelExtensions
|
|
|
2
2
|
module Nodes
|
|
3
3
|
class Trim < Function
|
|
4
4
|
RETURN_TYPE = :string
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
def initialize expr
|
|
7
7
|
tab = expr.map { |arg|
|
|
8
8
|
convert_to_node(arg)
|
|
9
9
|
}
|
|
10
|
-
super(tab)
|
|
10
|
+
return super(tab)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def +(other)
|
|
14
|
-
ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
|
14
|
+
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
|
15
15
|
end
|
|
16
|
+
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
class Ltrim < Trim
|
|
19
|
-
|
|
20
|
+
RETURN_TYPE = :string
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
class Rtrim < Trim
|
|
23
24
|
RETURN_TYPE = :string
|
|
24
25
|
end
|
|
26
|
+
|
|
25
27
|
end
|
|
26
28
|
end
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
module ArelExtensions
|
|
2
2
|
module Nodes
|
|
3
3
|
class Union < Arel::Nodes::Union
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
def initialize left,right
|
|
6
|
+
return super(left,right)
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
def +(other)
|
|
9
|
-
ArelExtensions::Nodes::Union.new(self,
|
|
10
|
+
return ArelExtensions::Nodes::Union.new(self,other)
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
def union(other)
|
|
13
|
-
ArelExtensions::Nodes::UnionAll.new(self,
|
|
14
|
+
return ArelExtensions::Nodes::UnionAll.new(self,other)
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def as other
|
|
17
|
-
Arel::Nodes::TableAlias.new Arel.
|
|
18
|
+
Arel::Nodes::TableAlias.new Arel::Nodes::Grouping.new(self), Arel::Nodes::SqlLiteral.new(other.to_s)
|
|
18
19
|
end
|
|
19
20
|
end
|
|
21
|
+
|
|
20
22
|
end
|
|
21
23
|
end
|
|
24
|
+
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
module ArelExtensions
|
|
2
2
|
module Nodes
|
|
3
3
|
class UnionAll < Arel::Nodes::UnionAll
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
def initialize left,right
|
|
6
|
+
return super(left,right)
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
def union_all(other)
|
|
9
|
-
ArelExtensions::Nodes::UnionAll.new(self,
|
|
10
|
+
return ArelExtensions::Nodes::UnionAll.new(self,other)
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
def as other
|
|
13
|
-
Arel::Nodes::TableAlias.new Arel.
|
|
14
|
+
Arel::Nodes::TableAlias.new Arel::Nodes::Grouping.new(self), Arel::Nodes::SqlLiteral.new(other.to_s)
|
|
14
15
|
end
|
|
15
16
|
end
|
|
17
|
+
|
|
16
18
|
end
|
|
17
19
|
end
|
|
20
|
+
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
require 'arel_extensions/nodes/function'
|
|
2
|
-
|
|
2
|
+
|
|
@@ -4,36 +4,22 @@ require 'arel_extensions/nodes/is_null'
|
|
|
4
4
|
module ArelExtensions
|
|
5
5
|
module NullFunctions
|
|
6
6
|
|
|
7
|
-
#
|
|
8
|
-
def if_present
|
|
9
|
-
Arel.when(self.cast(:string).present).then(self)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# ISNULL function lets you return an alternative value when an expression is NULL.
|
|
7
|
+
#ISNULL function lets you return an alternative value when an expression is NULL.
|
|
13
8
|
def is_null
|
|
14
9
|
ArelExtensions::Nodes::IsNull.new [self]
|
|
15
10
|
end
|
|
16
|
-
|
|
17
|
-
#
|
|
11
|
+
|
|
12
|
+
#ISNOTNULL function lets you return an alternative value when an expression is NOT NULL.
|
|
18
13
|
def is_not_null
|
|
19
14
|
ArelExtensions::Nodes::IsNotNull.new [self]
|
|
20
15
|
end
|
|
21
|
-
|
|
16
|
+
|
|
22
17
|
# returns the first non-null expr in the expression list. You must specify at least two expressions.
|
|
23
|
-
#
|
|
18
|
+
#If all occurrences of expr evaluate to null, then the function returns null.
|
|
24
19
|
def coalesce *args
|
|
25
20
|
args.unshift(self)
|
|
26
21
|
ArelExtensions::Nodes::Coalesce.new args
|
|
27
22
|
end
|
|
28
23
|
|
|
29
|
-
def coalesce_blank *args
|
|
30
|
-
res = Arel.when(self.cast(:string).present).then(self)
|
|
31
|
-
args[0...-1].each do |a|
|
|
32
|
-
val = a.is_a?(Arel::Nodes::Node) ? a : Arel.quoted(a)
|
|
33
|
-
res = res.when(val.present).then(a)
|
|
34
|
-
end
|
|
35
|
-
res = res.else(args[-1])
|
|
36
|
-
res
|
|
37
|
-
end
|
|
38
24
|
end
|
|
39
25
|
end
|
|
@@ -1,78 +1,76 @@
|
|
|
1
1
|
module ArelExtensions
|
|
2
2
|
module Predications
|
|
3
|
-
def when right, expression
|
|
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
|
|
7
|
+
def matches(other, escape=nil,case_sensitive= nil)
|
|
8
8
|
if Arel::VERSION.to_i < 7
|
|
9
|
-
Arel::Nodes::Matches.new(self, Arel.
|
|
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
19
|
def cast right
|
|
20
|
-
ArelExtensions::Nodes::Cast.new([self,
|
|
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
26
|
self.between(other)
|
|
28
|
-
when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
|
|
29
|
-
Arel::Nodes::In.new(self, quoted_node(other))
|
|
30
27
|
when Enumerable
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
42
41
|
when nil
|
|
43
42
|
self.is_null
|
|
44
43
|
when Arel::SelectManager
|
|
45
44
|
Arel::Nodes::In.new(self, other.ast)
|
|
46
45
|
else
|
|
47
|
-
Arel::Nodes::In.new(self,
|
|
46
|
+
Arel::Nodes::In.new(self,quoted_node(other))
|
|
48
47
|
end
|
|
49
48
|
end
|
|
50
49
|
|
|
51
|
-
def not_in(
|
|
52
|
-
other = other.first if other.length <= 1
|
|
50
|
+
def not_in(other) #In should handle nil element in the Array
|
|
53
51
|
case other
|
|
54
52
|
when Range
|
|
55
53
|
Arel::Nodes::Not.new(self.between(other))
|
|
56
|
-
when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
|
|
57
|
-
Arel::Nodes::NotIn.new(self, quoted_node(other))
|
|
58
54
|
when Enumerable
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
|
70
68
|
when nil
|
|
71
69
|
self.is_not_null
|
|
72
70
|
when Arel::SelectManager
|
|
73
71
|
Arel::Nodes::NotIn.new(self, other.ast)
|
|
74
72
|
else
|
|
75
|
-
Arel::Nodes::NotIn.new(self,
|
|
73
|
+
Arel::Nodes::NotIn.new(self,quoted_node(other))
|
|
76
74
|
end
|
|
77
75
|
end
|
|
78
76
|
|
|
@@ -81,20 +79,21 @@ module ArelExtensions
|
|
|
81
79
|
when Arel::Attributes::Attribute, Arel::Nodes::Node, Integer
|
|
82
80
|
object
|
|
83
81
|
when DateTime
|
|
84
|
-
Arel.
|
|
82
|
+
Arel::Nodes.build_quoted(object, self)
|
|
85
83
|
when Time
|
|
86
|
-
Arel.
|
|
84
|
+
Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
|
|
87
85
|
when String
|
|
88
|
-
Arel.
|
|
86
|
+
Arel::Nodes.build_quoted(object)
|
|
89
87
|
when Date
|
|
90
|
-
Arel.
|
|
88
|
+
Arel::Nodes.build_quoted(object.to_s, self)
|
|
91
89
|
when NilClass
|
|
92
90
|
Arel.sql('NULL')
|
|
93
91
|
when ActiveSupport::Duration
|
|
94
92
|
object.to_i
|
|
95
93
|
else
|
|
96
|
-
raise(ArgumentError, "#{object.class}
|
|
94
|
+
raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
|
|
97
95
|
end
|
|
98
96
|
end
|
|
97
|
+
|
|
99
98
|
end
|
|
100
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,4 +1,4 @@
|
|
|
1
|
-
require 'arel_extensions/nodes/concat' #
|
|
1
|
+
require 'arel_extensions/nodes/concat' #if Arel::VERSION.to_i < 7
|
|
2
2
|
require 'arel_extensions/nodes/length'
|
|
3
3
|
require 'arel_extensions/nodes/locate'
|
|
4
4
|
require 'arel_extensions/nodes/substring'
|
|
@@ -19,29 +19,19 @@ require 'arel_extensions/nodes/md5'
|
|
|
19
19
|
|
|
20
20
|
module ArelExtensions
|
|
21
21
|
module StringFunctions
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
#*FindInSet function .......
|
|
23
24
|
def &(other)
|
|
24
|
-
ArelExtensions::Nodes::FindInSet.new [
|
|
25
|
-
Arel.quoted(other.is_a?(Integer) ? other.to_s : other),
|
|
26
|
-
self,
|
|
27
|
-
]
|
|
25
|
+
ArelExtensions::Nodes::FindInSet.new [other, self]
|
|
28
26
|
end
|
|
29
27
|
|
|
30
|
-
#
|
|
28
|
+
#LENGTH function returns the length of the value in a text field.
|
|
31
29
|
def length
|
|
32
|
-
ArelExtensions::Nodes::Length.new self
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def byte_length
|
|
36
|
-
ArelExtensions::Nodes::Length.new self, true
|
|
30
|
+
ArelExtensions::Nodes::Length.new [self]
|
|
37
31
|
end
|
|
38
32
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# LOCATE function returns the first starting position of a string in another string.
|
|
44
|
-
# If string1 or string2 is NULL then it returns NULL. If string1 not found in string2 then it returns 0.
|
|
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.
|
|
45
35
|
def locate val
|
|
46
36
|
ArelExtensions::Nodes::Locate.new [self, val]
|
|
47
37
|
end
|
|
@@ -50,31 +40,18 @@ module ArelExtensions
|
|
|
50
40
|
ArelExtensions::Nodes::Substring.new [self, start, len]
|
|
51
41
|
end
|
|
52
42
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
# Return the result to `self.send(start)` if it's a [String|Symbol]. The
|
|
57
|
-
# assumption is that you're trying to reach an [Arel::Table]'s
|
|
58
|
-
# [Arel::Attribute].
|
|
59
|
-
#
|
|
60
|
-
# @note `ind` should be an [Integer|NilClass] if `start` is an [Integer].
|
|
61
|
-
# It's ignored in all other cases.
|
|
62
|
-
def [](start, end_ = nil)
|
|
63
|
-
if start.is_a?(String) || start.is_a?(Symbol)
|
|
64
|
-
self.send(start)
|
|
65
|
-
elsif start.is_a?(Range)
|
|
43
|
+
def [](start, ind = nil)
|
|
44
|
+
start += 1 if start.is_a?(Integer)
|
|
45
|
+
if start.is_a?(Range)
|
|
66
46
|
ArelExtensions::Nodes::Substring.new [self, start.begin + 1, start.end - start.begin + 1]
|
|
67
|
-
elsif start.is_a?(Integer) && !
|
|
68
|
-
ArelExtensions::Nodes::Substring.new [self, start
|
|
69
|
-
elsif start.is_a?(Integer)
|
|
70
|
-
start += 1
|
|
71
|
-
ArelExtensions::Nodes::Substring.new [self, start, end_ - start + 1]
|
|
47
|
+
elsif start.is_a?(Integer) && !ind
|
|
48
|
+
ArelExtensions::Nodes::Substring.new [self, start, 1]
|
|
72
49
|
else
|
|
73
|
-
|
|
50
|
+
ArelExtensions::Nodes::Substring.new [self, start, ind - start + 1]
|
|
74
51
|
end
|
|
75
52
|
end
|
|
76
53
|
|
|
77
|
-
#
|
|
54
|
+
#SOUNDEX function returns a character string containing the phonetic representation of char.
|
|
78
55
|
def soundex
|
|
79
56
|
ArelExtensions::Nodes::Soundex.new [self]
|
|
80
57
|
end
|
|
@@ -87,19 +64,6 @@ module ArelExtensions
|
|
|
87
64
|
grouping_any :imatches, others, escape
|
|
88
65
|
end
|
|
89
66
|
|
|
90
|
-
# def grouping_any method, others, *extra
|
|
91
|
-
# puts "*******************"
|
|
92
|
-
# puts method
|
|
93
|
-
# puts others.inspect
|
|
94
|
-
# puts extra.inspect
|
|
95
|
-
# puts "-------------------"
|
|
96
|
-
# res = super(method,others,*extra)
|
|
97
|
-
# puts res.to_sql
|
|
98
|
-
# puts res.inspect
|
|
99
|
-
# puts "*******************"
|
|
100
|
-
# res
|
|
101
|
-
# end
|
|
102
|
-
|
|
103
67
|
def imatches_all others, escape = nil
|
|
104
68
|
grouping_all :imatches, others, escape, escape
|
|
105
69
|
end
|
|
@@ -117,62 +81,53 @@ module ArelExtensions
|
|
|
117
81
|
end
|
|
118
82
|
|
|
119
83
|
def ai_matches other # accent insensitive & case sensitive
|
|
120
|
-
ArelExtensions::Nodes::AiMatches.new(self,
|
|
84
|
+
ArelExtensions::Nodes::AiMatches.new(self,other)
|
|
121
85
|
end
|
|
122
86
|
|
|
123
87
|
def ai_imatches other # accent insensitive & case insensitive
|
|
124
|
-
ArelExtensions::Nodes::AiIMatches.new(self,
|
|
88
|
+
ArelExtensions::Nodes::AiIMatches.new(self,other)
|
|
125
89
|
end
|
|
126
90
|
|
|
127
91
|
def smatches other # accent sensitive & case sensitive
|
|
128
|
-
ArelExtensions::Nodes::SMatches.new(self,
|
|
92
|
+
ArelExtensions::Nodes::SMatches.new(self,other)
|
|
129
93
|
end
|
|
130
94
|
|
|
131
|
-
def ai_collate
|
|
132
|
-
ArelExtensions::Nodes::Collate.new(self,
|
|
95
|
+
def ai_collate
|
|
96
|
+
ArelExtensions::Nodes::Collate.new(self,nil,true,false)
|
|
133
97
|
end
|
|
134
98
|
|
|
135
99
|
def ci_collate
|
|
136
|
-
ArelExtensions::Nodes::Collate.new(self,
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
def collate ai = false, ci = false, option = nil
|
|
140
|
-
ArelExtensions::Nodes::Collate.new(self, option, ai, ci)
|
|
100
|
+
ArelExtensions::Nodes::Collate.new(self,nil,false,true)
|
|
141
101
|
end
|
|
142
102
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if pattern.is_a? Regexp
|
|
146
|
-
ArelExtensions::Nodes::RegexpReplace.new self, pattern, substitute
|
|
147
|
-
else
|
|
148
|
-
ArelExtensions::Nodes::Replace.new self, pattern, substitute
|
|
149
|
-
end
|
|
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
|
-
|
|
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]
|
|
154
110
|
end
|
|
155
|
-
|
|
111
|
+
|
|
156
112
|
def concat other
|
|
157
113
|
ArelExtensions::Nodes::Concat.new [self, other]
|
|
158
114
|
end
|
|
159
115
|
|
|
160
|
-
#
|
|
161
|
-
def group_concat
|
|
162
|
-
if orders.present?
|
|
163
|
-
deprecated 'Use the kwarg `order` instead.', what: 'orders'
|
|
164
|
-
end
|
|
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
|
|
165
118
|
order_tabs = [orders].flatten.map{ |o|
|
|
166
119
|
if o.is_a?(Arel::Nodes::Ascending) || o.is_a?(Arel::Nodes::Descending)
|
|
167
120
|
o
|
|
168
121
|
elsif o.respond_to?(:asc)
|
|
169
122
|
o.asc
|
|
123
|
+
else
|
|
124
|
+
nil
|
|
170
125
|
end
|
|
171
126
|
}.compact
|
|
172
|
-
ArelExtensions::Nodes::GroupConcat.new
|
|
127
|
+
ArelExtensions::Nodes::GroupConcat.new [self, sep, order_tabs]
|
|
173
128
|
end
|
|
174
129
|
|
|
175
|
-
#
|
|
130
|
+
#Function returns a string after removing left, right or the both prefixes or suffixes int argument
|
|
176
131
|
def trim other = ' '
|
|
177
132
|
ArelExtensions::Nodes::Trim.new [self, other]
|
|
178
133
|
end
|
|
@@ -200,12 +155,11 @@ module ArelExtensions
|
|
|
200
155
|
def not_blank
|
|
201
156
|
ArelExtensions::Nodes::NotBlank.new [self]
|
|
202
157
|
end
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
def repeat other = 1
|
|
158
|
+
|
|
159
|
+
def repeat other = 1
|
|
206
160
|
ArelExtensions::Nodes::Repeat.new [self, other]
|
|
207
161
|
end
|
|
208
|
-
|
|
162
|
+
|
|
209
163
|
def levenshtein_distance other
|
|
210
164
|
ArelExtensions::Nodes::LevenshteinDistance.new [self, other]
|
|
211
165
|
end
|
|
@@ -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
|