arel_extensions 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +15 -8
- data/arel_extensions.gemspec +2 -2
- data/functions.html +21 -8
- data/gemfiles/rails3.gemfile +3 -3
- data/gemfiles/rails4.gemfile +1 -2
- data/gemfiles/rails5.gemfile +2 -2
- data/lib/arel_extensions/math.rb +6 -4
- data/lib/arel_extensions/nodes/coalesce.rb +7 -15
- data/lib/arel_extensions/nodes/concat.rb +5 -20
- data/lib/arel_extensions/nodes/date_diff.rb +1 -1
- data/lib/arel_extensions/nodes/function.rb +21 -1
- data/lib/arel_extensions/nodes/locate.rb +3 -18
- data/lib/arel_extensions/nodes/ltrim.rb +8 -18
- data/lib/arel_extensions/nodes/rtrim.rb +8 -19
- data/lib/arel_extensions/nodes/trim.rb +8 -16
- data/lib/arel_extensions/nodes.rb +3 -2
- data/lib/arel_extensions/null_functions.rb +2 -2
- data/lib/arel_extensions/string_functions.rb +3 -3
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/postgresql.rb +77 -155
- data/lib/arel_extensions/visitors/sqlite.rb +0 -84
- data/lib/arel_extensions/visitors/to_sql.rb +51 -0
- data/test/database.yml +6 -2
- data/test/real_db_test.rb +14 -17
- data/test/visitors/test_bulk_insert_oracle.rb +5 -1
- data/test/visitors/test_bulk_insert_sqlite.rb +5 -1
- data/test/visitors/test_bulk_insert_to_sql.rb +5 -1
- data/test/visitors/test_oracle.rb +5 -1
- data/test/visitors/test_to_sql.rb +5 -1
- data/test/with_ar/test_math_sqlite.rb +10 -7
- data/test/with_ar/test_string_mysql.rb +9 -10
- data/test/with_ar/test_string_postgresql.rb +81 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc58508a314b8bc3f5f4eb4aa704c4cba75783f6
|
4
|
+
data.tar.gz: a347453b0960efb17862dbb15e7433efa81cdc05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9aab7c24f6cd74293a52b5064764a9cbbffcc5d208140ddfab546ddc985f1435fb6ccbe7418e86e32c03c844670567dc03d16474077d52cd3acea1d5169bcc63
|
7
|
+
data.tar.gz: c74789a394dabfd3a8061a174a270312a7eacd3e46e0decd8089b2b4043eda970c65406adc22a60f9278345c4a063c58d1e1ef3450113ebac506ecbddac99dc9
|
data/.travis.yml
CHANGED
@@ -2,13 +2,14 @@ language: ruby
|
|
2
2
|
sudo: false
|
3
3
|
cache: bundler
|
4
4
|
before_install:
|
5
|
+
- gem install bundler
|
5
6
|
# - sudo apt-get update -qq
|
6
7
|
# - sudo apt-get install -qq sqlite3
|
7
8
|
#addons:
|
8
9
|
# mariadb: '10.0'
|
9
10
|
gemfile:
|
10
|
-
- gemfiles/rails3.gemfile
|
11
11
|
- gemfiles/rails4.gemfile
|
12
|
+
# - gemfiles/rails3.gemfile
|
12
13
|
- gemfiles/rails5.gemfile
|
13
14
|
services:
|
14
15
|
- mysql
|
@@ -20,18 +21,18 @@ script:
|
|
20
21
|
- "bundle exec rake test"
|
21
22
|
# - "bundle exec rake test:sqlite3"
|
22
23
|
- "gem build arel_extensions.gemspec"
|
23
|
-
|
24
|
+
- "bundle exec ruby test/real_db_test.rb"
|
24
25
|
env:
|
25
26
|
global:
|
26
27
|
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
27
28
|
rvm:
|
28
|
-
- rbx-2
|
29
|
-
- jruby-9.0.5.0
|
30
|
-
- jruby-head
|
31
29
|
- 2.0.0
|
32
30
|
- 2.1
|
33
31
|
- 2.2.5
|
34
32
|
- 2.3.1
|
33
|
+
- rbx-2
|
34
|
+
- jruby-9.0.5.0
|
35
|
+
- jruby-head
|
35
36
|
- ruby-head
|
36
37
|
jdk:
|
37
38
|
- openjdk7
|
@@ -65,14 +66,20 @@ matrix:
|
|
65
66
|
jdk: openjdk7
|
66
67
|
- rvm: ruby-head
|
67
68
|
jdk: oraclejdk7
|
69
|
+
- rvm: 2.0.0
|
70
|
+
gemfile: gemfiles/rails5.gemfile
|
71
|
+
- rvm: 2.1
|
72
|
+
gemfile: gemfiles/rails5.gemfile
|
73
|
+
- rvm: rbx-2
|
74
|
+
gemfile: gemfiles/rails5.gemfile
|
68
75
|
allow_failures:
|
69
76
|
# - rvm: jruby-9.0.5.0
|
70
77
|
# - rvm: jruby-head
|
71
78
|
- rvm: ruby-head
|
72
79
|
gemfile: gemfiles/rails4.gemfile
|
73
|
-
- rvm: ruby-head
|
74
|
-
gemfile: gemfiles/rails3.gemfile
|
80
|
+
# - rvm: ruby-head
|
81
|
+
# gemfile: gemfiles/rails3.gemfile
|
75
82
|
# - rvm: jruby-head
|
76
|
-
bundler_args: --jobs
|
83
|
+
bundler_args: --jobs 3 --retry 2
|
77
84
|
notifications:
|
78
85
|
email: false
|
data/arel_extensions.gemspec
CHANGED
@@ -4,7 +4,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "arel_extensions"
|
7
|
-
s.version = '0.8.
|
7
|
+
s.version = '0.8.3'
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Yann Azoury", "Mathilde Pechdimaldjian", "Félix Bellanger"]
|
10
10
|
s.email = ["yann.azoury@faveod.com", "mathilde.pechdimaldjian@gmail.com", "felix.bellanger@faveod.com"]
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
|
24
|
-
s.add_dependency('arel')
|
24
|
+
s.add_dependency('arel', '>= 6.0')
|
25
25
|
|
26
26
|
s.add_development_dependency('minitest', '~> 5.9')
|
27
27
|
s.add_development_dependency('rdoc', '~> 4.0')
|
data/functions.html
CHANGED
@@ -5,8 +5,9 @@
|
|
5
5
|
<title>Arel Extensions Features</title>
|
6
6
|
<style type="text/css">
|
7
7
|
.tg {border-collapse:collapse;border-spacing:0;}
|
8
|
+
.tg th { font-weight:bold; }
|
8
9
|
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
|
9
|
-
.tg th{font-family:Arial, sans-serif;font-size:14px;
|
10
|
+
.tg th{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
|
10
11
|
.tg .tg-baqh{text-align:center;vertical-align:top}
|
11
12
|
.tg .tg-3oug{background-color:#fd6864;text-align:center;vertical-align:top}
|
12
13
|
.tg .tg-by3v{font-weight:bold;font-size:14px;text-align:center}
|
@@ -36,8 +37,9 @@
|
|
36
37
|
<th class="tg-pjz5">DB2</th>
|
37
38
|
</tr>
|
38
39
|
</thead>
|
40
|
+
<tbody>
|
39
41
|
<tr>
|
40
|
-
<
|
42
|
+
<th class="tg-82sq" rowspan="6"><br><br><br><br><br><br><br>Math<br>functions</th>
|
41
43
|
<td class="tg-yw4l">ABS<br>column.abs<br></td>
|
42
44
|
<td class="tg-baqh">✔</td>
|
43
45
|
<td class="tg-baqh">✔</td>
|
@@ -92,7 +94,7 @@
|
|
92
94
|
<td class="tg-baqh">✔</td>
|
93
95
|
</tr>
|
94
96
|
<tr>
|
95
|
-
<
|
97
|
+
<th class="tg-ffjm" rowspan="11"><br><br><br><br><br><br><br><br><br>String <br>functions</th>
|
96
98
|
<td class="tg-yw4l">CONCAT<br>column + "string"</td>
|
97
99
|
<td class="tg-baqh">✔</td>
|
98
100
|
<td class="tg-baqh">✔</td>
|
@@ -192,7 +194,7 @@
|
|
192
194
|
<td class="tg-j6lv">TRIM()</td>
|
193
195
|
</tr>
|
194
196
|
<tr>
|
195
|
-
<
|
197
|
+
<th class="tg-4rp9" rowspan="6"><br><br><br><br><br><br><br>Date <br>functions<br></th>
|
196
198
|
<td class="tg-yw4l">DATEADD<br>column + 2.year<br></td>
|
197
199
|
<td class="tg-j6lv">DATE_ADD()<br></td>
|
198
200
|
<td class="tg-baqh">✔</td>
|
@@ -247,7 +249,7 @@
|
|
247
249
|
<td class="tg-baqh">✔</td>
|
248
250
|
</tr>
|
249
251
|
<tr>
|
250
|
-
<
|
252
|
+
<th class="tg-72dn" rowspan="8"><br><br><br><br><br><br>Comparators<br>functions<br></th>
|
251
253
|
<td class="tg-yw4l">COALESCE<br>column.coalesce(var)</td>
|
252
254
|
<td class="tg-baqh">✔</td>
|
253
255
|
<td class="tg-baqh">✔</td>
|
@@ -320,7 +322,7 @@
|
|
320
322
|
<td class="tg-baqh">✔</td>
|
321
323
|
</tr>
|
322
324
|
<tr>
|
323
|
-
<
|
325
|
+
<th class="tg-9hbo" rowspan="2">Boolean <br>functions</th>
|
324
326
|
<td class="tg-yw4l">OR ( ⋁ )<br>column.eq(var) ⋁ column.eq(var)</td>
|
325
327
|
<td class="tg-baqh">✔</td>
|
326
328
|
<td class="tg-baqh">✔</td>
|
@@ -338,7 +340,18 @@
|
|
338
340
|
<td class="tg-baqh">✔</td>
|
339
341
|
<td class="tg-baqh">✔</td>
|
340
342
|
</tr>
|
343
|
+
<tr>
|
344
|
+
<th class="bulk_insert">Bulk Insert</th>
|
345
|
+
<td class="tg-yw4l">insert_manager.bulk_insert(@cols, @data)</td>
|
346
|
+
<td class="tg-baqh">✔</td>
|
347
|
+
<td class="tg-baqh">✔</td>
|
348
|
+
<td class="tg-baqh">✔</td>
|
349
|
+
<td class="tg-baqh">✔</td>
|
350
|
+
<td class="tg-baqh">✔</td>
|
351
|
+
<td class="tg-baqh">✔</td>
|
352
|
+
</tr>
|
353
|
+
</tbody>
|
341
354
|
</table>
|
342
|
-
|
355
|
+
|
343
356
|
</body>
|
344
|
-
</html>
|
357
|
+
</html>
|
data/gemfiles/rails3.gemfile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
gem 'arel', '~> 3.0'
|
3
|
+
gem 'arel', '~> 3.0' # too old...
|
4
4
|
|
5
5
|
group :development, :test do
|
6
6
|
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
7
7
|
gem "mysql2", :platform => [:ruby, :mswin, :mingw]
|
8
|
+
gem "activerecord-mysql2-adapter", :platform => [:ruby, :mswin, :mingw]
|
9
|
+
gem "pg", :platform => [:ruby, :mswin, :mingw]
|
8
10
|
# for JRuby
|
9
11
|
gem "jdbc-sqlite3", :platform => :jruby
|
10
12
|
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
|
@@ -13,8 +15,6 @@ group :development, :test do
|
|
13
15
|
gem 'activesupport', '~> 3.2'
|
14
16
|
gem 'activemodel', '~> 3.2'
|
15
17
|
gem 'activerecord', '~> 3.2'
|
16
|
-
gem 'rdoc'
|
17
|
-
gem 'rake'
|
18
18
|
end
|
19
19
|
|
20
20
|
gemspec :path => "../"
|
data/gemfiles/rails4.gemfile
CHANGED
@@ -5,6 +5,7 @@ gem 'arel', '~> 6.0'
|
|
5
5
|
group :development, :test do
|
6
6
|
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
7
7
|
gem "mysql2", :platform => [:ruby, :mswin, :mingw]
|
8
|
+
gem "pg", :platform => [:ruby, :mswin, :mingw]
|
8
9
|
# for JRuby
|
9
10
|
gem "jdbc-sqlite3", :platform => :jruby
|
10
11
|
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
|
@@ -13,8 +14,6 @@ group :development, :test do
|
|
13
14
|
gem 'activesupport', '~> 4.0'
|
14
15
|
gem 'activemodel', '~> 4.0'
|
15
16
|
gem 'activerecord', '~> 4.0'
|
16
|
-
gem 'rdoc'
|
17
|
-
gem 'rake', '~> 11'
|
18
17
|
end
|
19
18
|
|
20
19
|
gemspec :path => "../"
|
data/gemfiles/rails5.gemfile
CHANGED
@@ -5,6 +5,8 @@ gem 'arel', '~> 7.0'
|
|
5
5
|
group :development, :test do
|
6
6
|
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
7
7
|
gem "mysql2", :platform => [:ruby, :mswin, :mingw]
|
8
|
+
gem "pg", :platform => [:ruby, :mswin, :mingw]
|
9
|
+
|
8
10
|
# for JRuby
|
9
11
|
gem "jdbc-sqlite3", :platform => :jruby
|
10
12
|
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
|
@@ -14,8 +16,6 @@ group :development, :test do
|
|
14
16
|
gem 'activesupport', '~> 5'
|
15
17
|
gem 'activemodel', '~> 5'
|
16
18
|
gem 'activerecord', '~> 5'
|
17
|
-
gem 'rdoc'
|
18
|
-
gem 'rake'
|
19
19
|
end
|
20
20
|
|
21
21
|
gemspec :path => "../"
|
data/lib/arel_extensions/math.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
require 'arel_extensions/nodes'
|
2
|
+
require 'arel_extensions/nodes/concat'
|
3
|
+
|
1
4
|
module ArelExtensions
|
2
5
|
module Math
|
3
6
|
#function + between
|
4
7
|
#String and others (convert in string) allows you to concatenate 2 or more strings together.
|
5
8
|
#Date and integer adds or subtracts a specified time interval from a date.
|
6
9
|
def +(other)
|
7
|
-
|
8
|
-
arg = self.relation.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s].type
|
10
|
+
arg = Arel::Table.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s].type
|
9
11
|
if arg == :integer || arg == :decimal || arg == :float
|
10
12
|
if other.is_a?(String)
|
11
13
|
other = other.to_i
|
@@ -21,11 +23,11 @@ module ArelExtensions
|
|
21
23
|
#function returns the time between two dates
|
22
24
|
#function returns the susbration between two int
|
23
25
|
def -(other)
|
24
|
-
arg =
|
26
|
+
arg = Arel::Table.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s].type
|
25
27
|
if (arg == :date || arg == :datetime)
|
26
28
|
case other
|
27
29
|
when Arel::Attributes::Attribute
|
28
|
-
arg2 =
|
30
|
+
arg2 = Arel::Table.engine.connection.schema_cache.columns_hash(other.relation.table_name)[other.name.to_s].type
|
29
31
|
if arg2 == :date || arg2 == :datetime
|
30
32
|
ArelExtensions::Nodes::DateDiff.new self, other
|
31
33
|
else
|
@@ -1,22 +1,14 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
|
-
class Coalesce <
|
4
|
-
include Arel::AliasPredication
|
3
|
+
class Coalesce < Function
|
5
4
|
|
6
|
-
def initialize
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def left
|
12
|
-
@expressions.first
|
5
|
+
def initialize expr
|
6
|
+
tab = expr.map { |arg|
|
7
|
+
convert_to_node(arg)
|
8
|
+
}
|
9
|
+
return super(tab)
|
13
10
|
end
|
14
|
-
|
15
|
-
def other
|
16
|
-
@expressions.delete_at(0)
|
17
|
-
@expressions
|
18
|
-
end
|
19
|
-
|
11
|
+
|
20
12
|
end
|
21
13
|
end
|
22
14
|
end
|
@@ -1,31 +1,16 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class Concat < Function
|
4
|
-
include ArelExtensions::Math
|
5
4
|
|
6
5
|
def initialize expr
|
7
|
-
tab = expr.map
|
8
|
-
|
9
|
-
|
6
|
+
tab = expr.map { |arg|
|
7
|
+
convert_to_node(arg)
|
8
|
+
}
|
10
9
|
return super(tab)
|
11
10
|
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
case object
|
16
|
-
when Arel::Attributes::Attribute, Arel::Nodes::Node, Fixnum
|
17
|
-
object
|
18
|
-
when DateTime, Time
|
19
|
-
Arel::Nodes.build_quoted(Date.new(object.year, object.month, object.day), self)
|
20
|
-
when String
|
21
|
-
Arel::Nodes.build_quoted(object)
|
22
|
-
when Date
|
23
|
-
Arel::Nodes.build_quoted(object, self)
|
24
|
-
when ActiveSupport::Duration
|
25
|
-
object.to_i
|
26
|
-
else
|
27
|
-
raise(ArgumentError, "#{object.class} can not be converted to Date")
|
28
|
-
end
|
12
|
+
def +(other)
|
13
|
+
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
29
14
|
end
|
30
15
|
|
31
16
|
end
|
@@ -38,7 +38,7 @@ module ArelExtensions
|
|
38
38
|
|
39
39
|
def initialize expr
|
40
40
|
col = expr.first
|
41
|
-
@date_type =
|
41
|
+
@date_type = Arel::Table.engine.connection.schema_cache.columns_hash(col.relation.table_name)[col.name.to_s].type
|
42
42
|
tab = expr.map do |arg|
|
43
43
|
convert(arg)
|
44
44
|
end
|
@@ -18,7 +18,27 @@ module ArelExtensions
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def right
|
21
|
-
@expressions
|
21
|
+
@expressions[1]
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
def convert_to_node(object)
|
26
|
+
case object
|
27
|
+
when Arel::Attributes::Attribute, Arel::Nodes::Node, Fixnum, Integer
|
28
|
+
object
|
29
|
+
when DateTime, Time
|
30
|
+
Arel::Nodes.build_quoted(Date.new(object.year, object.month, object.day), self)
|
31
|
+
when String
|
32
|
+
Arel::Nodes.build_quoted(object)
|
33
|
+
when Date
|
34
|
+
Arel::Nodes.build_quoted(object, self)
|
35
|
+
when NilClass
|
36
|
+
Arel.sql('NULL')
|
37
|
+
when ActiveSupport::Duration
|
38
|
+
object.to_i
|
39
|
+
else
|
40
|
+
raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
|
41
|
+
end
|
22
42
|
end
|
23
43
|
|
24
44
|
end
|
@@ -1,31 +1,16 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class Locate < Function
|
4
|
-
include ArelExtensions::Math
|
5
4
|
|
6
5
|
def initialize expr
|
7
6
|
tab = expr.map do |arg|
|
8
|
-
|
7
|
+
convert_to_node(arg)
|
9
8
|
end
|
10
9
|
return super(tab)
|
11
10
|
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
case object
|
16
|
-
when Arel::Attributes::Attribute, Arel::Nodes::Node, Fixnum
|
17
|
-
object
|
18
|
-
when DateTime, Time
|
19
|
-
Arel::Nodes.build_quoted(Date.new(object.year, object.month, object.day), self)
|
20
|
-
when String
|
21
|
-
Arel::Nodes.build_quoted(object)
|
22
|
-
when Date
|
23
|
-
Arel::Nodes.build_quoted(object, self)
|
24
|
-
when ActiveSupport::Duration
|
25
|
-
object.to_i
|
26
|
-
else
|
27
|
-
raise(ArgumentError, "#{object.class} can not be converted to Date")
|
28
|
-
end
|
12
|
+
def +(other)
|
13
|
+
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
29
14
|
end
|
30
15
|
|
31
16
|
end
|
@@ -1,26 +1,16 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
|
-
class Ltrim <
|
3
|
+
class Ltrim < Function
|
4
4
|
|
5
|
-
def initialize
|
6
|
-
tab =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
super(tab, aliaz)
|
11
|
-
end
|
12
|
-
|
13
|
-
def left
|
14
|
-
@expressions.first
|
5
|
+
def initialize expr
|
6
|
+
tab = expr.map { |arg|
|
7
|
+
convert_to_node(arg)
|
8
|
+
}
|
9
|
+
return super(tab)
|
15
10
|
end
|
16
11
|
|
17
|
-
def
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
def as other
|
23
|
-
Arel::Nodes::As.new self, Arel::Nodes::SqlLiteral.new(other)
|
12
|
+
def +(other)
|
13
|
+
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
24
14
|
end
|
25
15
|
|
26
16
|
end
|
@@ -1,29 +1,18 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
|
-
class Rtrim <
|
3
|
+
class Rtrim < Function
|
4
4
|
|
5
|
-
def initialize
|
6
|
-
tab =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
super(tab, aliaz)
|
11
|
-
end
|
12
|
-
|
13
|
-
def left
|
14
|
-
@expressions.first
|
5
|
+
def initialize expr
|
6
|
+
tab = expr.map { |arg|
|
7
|
+
convert_to_node(arg)
|
8
|
+
}
|
9
|
+
return super(tab)
|
15
10
|
end
|
16
11
|
|
17
|
-
def
|
18
|
-
|
12
|
+
def +(other)
|
13
|
+
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
19
14
|
end
|
20
15
|
|
21
|
-
|
22
|
-
def as other
|
23
|
-
Arel::Nodes::As.new self, Arel::Nodes::SqlLiteral.new(other)
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
16
|
end
|
28
17
|
end
|
29
18
|
end
|
@@ -1,26 +1,18 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
|
-
class Trim <
|
3
|
+
class Trim < Function
|
4
4
|
|
5
|
-
def initialize
|
6
|
-
tab =
|
7
|
-
|
8
|
-
|
9
|
-
super(tab
|
5
|
+
def initialize expr
|
6
|
+
tab = expr.map { |arg|
|
7
|
+
convert_to_node(arg)
|
8
|
+
}
|
9
|
+
return super(tab)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def +(other)
|
13
|
+
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
14
14
|
end
|
15
15
|
|
16
|
-
def right
|
17
|
-
@expressions[1]
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
def as other
|
22
|
-
Arel::Nodes::As.new self, Arel::Nodes::SqlLiteral.new(other)
|
23
|
-
end
|
24
16
|
end
|
25
17
|
end
|
26
18
|
end
|
@@ -19,9 +19,10 @@ require 'arel_extensions/nodes/trim'
|
|
19
19
|
require 'arel_extensions/nodes/ltrim'
|
20
20
|
require 'arel_extensions/nodes/rtrim'
|
21
21
|
|
22
|
-
|
23
|
-
require 'arel_extensions/nodes/coalesce'
|
22
|
+
# Date functions
|
24
23
|
require 'arel_extensions/nodes/date_diff'
|
25
24
|
require 'arel_extensions/nodes/duration'
|
25
|
+
|
26
|
+
require 'arel_extensions/nodes/coalesce'
|
26
27
|
require 'arel_extensions/nodes/isnull'
|
27
28
|
require 'arel_extensions/nodes/wday'
|
@@ -7,10 +7,10 @@ module ArelExtensions
|
|
7
7
|
end
|
8
8
|
# returns the first non-null expr in the expression list. You must specify at least two expressions.
|
9
9
|
#If all occurrences of expr evaluate to null, then the function returns null.
|
10
|
-
def coalesce
|
10
|
+
def coalesce *args
|
11
11
|
args.unshift(self)
|
12
12
|
ArelExtensions::Nodes::Coalesce.new args
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
16
|
-
end
|
16
|
+
end
|
@@ -53,15 +53,15 @@ module ArelExtensions
|
|
53
53
|
|
54
54
|
#Function returns a string after removing left, right or the both prefixes or suffixes int argument
|
55
55
|
def trim other
|
56
|
-
ArelExtensions::Nodes::Trim.new self,other
|
56
|
+
ArelExtensions::Nodes::Trim.new [self, other]
|
57
57
|
end
|
58
58
|
|
59
59
|
def ltrim other
|
60
|
-
ArelExtensions::Nodes::Ltrim.new self,other
|
60
|
+
ArelExtensions::Nodes::Ltrim.new [self, other]
|
61
61
|
end
|
62
62
|
|
63
63
|
def rtrim other
|
64
|
-
ArelExtensions::Nodes::Rtrim.new self, other
|
64
|
+
ArelExtensions::Nodes::Rtrim.new [self, other]
|
65
65
|
end
|
66
66
|
|
67
67
|
end
|