arel_extensions 1.3.4 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +2 -1
  3. data/.rubocop.yml +4 -31
  4. data/.travis/oracle/download.js +152 -0
  5. data/.travis/oracle/download.sh +30 -0
  6. data/.travis/oracle/download_ojdbc.js +116 -0
  7. data/.travis/oracle/install.sh +34 -0
  8. data/.travis/setup_accounts.sh +9 -0
  9. data/.travis/sqlite3/extension-functions.sh +6 -0
  10. data/.travis.yml +223 -0
  11. data/Gemfile +21 -16
  12. data/README.md +14 -125
  13. data/Rakefile +30 -41
  14. data/TODO +1 -0
  15. data/appveyor.yml +44 -0
  16. data/arel_extensions.gemspec +14 -14
  17. data/functions.html +3 -3
  18. data/gemfiles/rails3.gemfile +10 -10
  19. data/gemfiles/rails4.gemfile +14 -14
  20. data/gemfiles/rails5_0.gemfile +14 -14
  21. data/gemfiles/rails5_1_4.gemfile +14 -14
  22. data/gemfiles/rails5_2.gemfile +14 -15
  23. data/init/mssql.sql +4 -4
  24. data/init/mysql.sql +38 -38
  25. data/init/oracle.sql +0 -0
  26. data/init/postgresql.sql +21 -21
  27. data/init/sqlite.sql +0 -0
  28. data/lib/arel_extensions/attributes.rb +3 -4
  29. data/lib/arel_extensions/boolean_functions.rb +14 -53
  30. data/lib/arel_extensions/common_sql_functions.rb +16 -15
  31. data/lib/arel_extensions/comparators.rb +28 -27
  32. data/lib/arel_extensions/date_duration.rb +14 -13
  33. data/lib/arel_extensions/insert_manager.rb +15 -18
  34. data/lib/arel_extensions/math.rb +44 -31
  35. data/lib/arel_extensions/math_functions.rb +39 -46
  36. data/lib/arel_extensions/nodes/abs.rb +1 -0
  37. data/lib/arel_extensions/nodes/blank.rb +2 -1
  38. data/lib/arel_extensions/nodes/case.rb +16 -16
  39. data/lib/arel_extensions/nodes/cast.rb +6 -8
  40. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  41. data/lib/arel_extensions/nodes/coalesce.rb +3 -2
  42. data/lib/arel_extensions/nodes/collate.rb +10 -9
  43. data/lib/arel_extensions/nodes/concat.rb +18 -9
  44. data/lib/arel_extensions/nodes/date_diff.rb +22 -38
  45. data/lib/arel_extensions/nodes/duration.rb +3 -0
  46. data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
  47. data/lib/arel_extensions/nodes/floor.rb +1 -1
  48. data/lib/arel_extensions/nodes/format.rb +8 -35
  49. data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
  50. data/lib/arel_extensions/nodes/function.rb +37 -42
  51. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  52. data/lib/arel_extensions/nodes/json.rb +39 -48
  53. data/lib/arel_extensions/nodes/length.rb +0 -5
  54. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  55. data/lib/arel_extensions/nodes/locate.rb +1 -0
  56. data/lib/arel_extensions/nodes/log10.rb +2 -1
  57. data/lib/arel_extensions/nodes/matches.rb +7 -5
  58. data/lib/arel_extensions/nodes/md5.rb +1 -0
  59. data/lib/arel_extensions/nodes/power.rb +5 -5
  60. data/lib/arel_extensions/nodes/rand.rb +1 -0
  61. data/lib/arel_extensions/nodes/repeat.rb +4 -2
  62. data/lib/arel_extensions/nodes/replace.rb +8 -16
  63. data/lib/arel_extensions/nodes/round.rb +6 -5
  64. data/lib/arel_extensions/nodes/soundex.rb +15 -15
  65. data/lib/arel_extensions/nodes/std.rb +21 -18
  66. data/lib/arel_extensions/nodes/substring.rb +16 -8
  67. data/lib/arel_extensions/nodes/trim.rb +5 -3
  68. data/lib/arel_extensions/nodes/union.rb +8 -5
  69. data/lib/arel_extensions/nodes/union_all.rb +7 -4
  70. data/lib/arel_extensions/nodes/wday.rb +4 -0
  71. data/lib/arel_extensions/nodes.rb +1 -1
  72. data/lib/arel_extensions/null_functions.rb +7 -5
  73. data/lib/arel_extensions/predications.rb +43 -44
  74. data/lib/arel_extensions/railtie.rb +5 -5
  75. data/lib/arel_extensions/set_functions.rb +7 -5
  76. data/lib/arel_extensions/string_functions.rb +29 -58
  77. data/lib/arel_extensions/tasks.rb +6 -6
  78. data/lib/arel_extensions/version.rb +1 -1
  79. data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
  80. data/lib/arel_extensions/visitors/mssql.rb +184 -269
  81. data/lib/arel_extensions/visitors/mysql.rb +206 -271
  82. data/lib/arel_extensions/visitors/oracle.rb +175 -191
  83. data/lib/arel_extensions/visitors/oracle12.rb +31 -18
  84. data/lib/arel_extensions/visitors/postgresql.rb +170 -244
  85. data/lib/arel_extensions/visitors/sqlite.rb +124 -138
  86. data/lib/arel_extensions/visitors/to_sql.rb +237 -269
  87. data/lib/arel_extensions/visitors.rb +59 -75
  88. data/lib/arel_extensions.rb +31 -149
  89. data/test/database.yml +7 -15
  90. data/test/helper.rb +18 -0
  91. data/test/real_db_test.rb +113 -102
  92. data/test/support/fake_record.rb +3 -3
  93. data/test/test_comparators.rb +17 -14
  94. data/test/visitors/test_bulk_insert_oracle.rb +10 -10
  95. data/test/visitors/test_bulk_insert_sqlite.rb +12 -11
  96. data/test/visitors/test_bulk_insert_to_sql.rb +12 -10
  97. data/test/visitors/test_oracle.rb +55 -55
  98. data/test/visitors/test_to_sql.rb +226 -419
  99. data/test/with_ar/all_agnostic_test.rb +357 -567
  100. data/test/with_ar/insert_agnostic_test.rb +19 -25
  101. data/test/with_ar/test_bulk_sqlite.rb +15 -16
  102. data/test/with_ar/test_math_sqlite.rb +26 -26
  103. data/test/with_ar/test_string_mysql.rb +33 -31
  104. data/test/with_ar/test_string_sqlite.rb +34 -30
  105. metadata +23 -29
  106. data/.github/workflows/ruby.yml +0 -389
  107. data/gemfiles/rails6.gemfile +0 -29
  108. data/gemfiles/rails6_1.gemfile +0 -29
  109. data/gemfiles/rails7.gemfile +0 -22
  110. data/gemspecs/arel_extensions-v1.gemspec +0 -28
  111. data/gemspecs/arel_extensions-v2.gemspec +0 -28
  112. data/generate_gems.sh +0 -15
  113. data/lib/arel_extensions/aliases.rb +0 -14
  114. data/lib/arel_extensions/helpers.rb +0 -51
  115. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
  116. data/lib/arel_extensions/nodes/sum.rb +0 -7
  117. data/lib/arel_extensions/visitors/convert_format.rb +0 -37
  118. data/test/arelx_test_helper.rb +0 -71
  119. data/version_v1.rb +0 -3
  120. data/version_v2.rb +0 -3
@@ -11,9 +11,9 @@ require 'arel_extensions/nodes/union_all'
11
11
 
12
12
  module ArelExtensions
13
13
  module Math
14
- # function + between
15
- # String and others (convert in string) allows you to concatenate 2 or more strings together.
16
- # Date and integer adds or subtracts a specified time interval from a date.
14
+ #function + between
15
+ #String and others (convert in string) allows you to concatenate 2 or more strings together.
16
+ #Date and integer adds or subtracts a specified time interval from a date.
17
17
  def +(other)
18
18
  case self
19
19
  when Arel::Nodes::Quoted
@@ -22,33 +22,37 @@ module ArelExtensions
22
22
  if self.expr.left.is_a?(String) || self.expr.right.is_a?(String)
23
23
  return self.concat(other)
24
24
  else
25
- return Arel.grouping(Arel::Nodes::Addition.new self, other)
25
+ return Arel::Nodes::Grouping.new(Arel::Nodes::Addition.new self, other)
26
26
  end
27
- when ArelExtensions::Nodes::Function, ArelExtensions::Nodes::Case
27
+ when ArelExtensions::Nodes::Function,ArelExtensions::Nodes::Case
28
28
  return case self.return_type
29
29
  when :string, :text
30
30
  self.concat(other)
31
31
  when :integer, :decimal, :float, :number, :int
32
- Arel.grouping(Arel::Nodes::Addition.new self, other)
32
+ Arel::Nodes::Grouping.new(Arel::Nodes::Addition.new self, other)
33
33
  when :date, :datetime
34
34
  ArelExtensions::Nodes::DateAdd.new [self, other]
35
35
  else
36
36
  self.concat(other)
37
37
  end
38
- when Arel::Nodes::Function
39
- Arel.grouping(Arel::Nodes::Addition.new self, other)
38
+ when Arel::Nodes::Function
39
+ Arel::Nodes::Grouping.new(Arel::Nodes::Addition.new self, other)
40
40
  else
41
- col = Arel.column_of(self.relation.table_name, self.name.to_s) if self.respond_to?(:relation)
42
- if (!col) # if the column doesn't exist in the database
43
- Arel.grouping(Arel::Nodes::Addition.new(self, Arel.quoted(other)))
41
+ begin
42
+ col = Arel::Table.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s]
43
+ rescue Exception
44
+ col = nil
45
+ end
46
+ if (!col) #if the column doesn't exist in the database
47
+ Arel::Nodes::Grouping.new(Arel::Nodes::Addition.new(self, other))
44
48
  else
45
49
  arg = col.type
46
50
  if arg == :integer || (!arg)
47
51
  other = other.to_i if other.is_a?(String)
48
- Arel.grouping(Arel::Nodes::Addition.new self, Arel.quoted(other))
52
+ Arel::Nodes::Grouping.new(Arel::Nodes::Addition.new self, other)
49
53
  elsif arg == :decimal || arg == :float
50
54
  other = Arel.sql(other) if other.is_a?(String) # Arel should accept Float & BigDecimal!
51
- Arel.grouping(Arel::Nodes::Addition.new self, Arel.quoted(other))
55
+ Arel::Nodes::Grouping.new(Arel::Nodes::Addition.new self, other)
52
56
  elsif arg == :datetime || arg == :date
53
57
  ArelExtensions::Nodes::DateAdd.new [self, other]
54
58
  elsif arg == :string || arg == :text
@@ -58,40 +62,48 @@ module ArelExtensions
58
62
  end
59
63
  end
60
64
 
61
- # function returns the time between two dates
62
- # function returns the substraction between two ints
65
+ #function returns the time between two dates
66
+ #function returns the substraction between two ints
63
67
  def -(other)
64
68
  case self
65
69
  when Arel::Nodes::Grouping
66
70
  if self.expr.left.is_a?(Date) || self.expr.left.is_a?(DateTime)
67
- Arel.grouping(ArelExtensions::Nodes::DateSub.new [self, Arel.quoted(other)])
71
+ Arel::Nodes::Grouping.new(ArelExtensions::Nodes::DateSub.new [self, other])
68
72
  else
69
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other)))
73
+ Arel::Nodes::Grouping.new(Arel::Nodes::Subtraction.new(self, other))
70
74
  end
71
75
  when ArelExtensions::Nodes::Function, ArelExtensions::Nodes::Case
72
76
  case self.return_type
73
77
  when :string, :text # ???
74
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other))) # ??
78
+ Arel::Nodes::Grouping.new(Arel::Nodes::Subtraction.new(self, other)) # ??
75
79
  when :integer, :decimal, :float, :number
76
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other)))
80
+ Arel::Nodes::Grouping.new(Arel::Nodes::Subtraction.new(self, other))
77
81
  when :date, :datetime
78
- ArelExtensions::Nodes::DateSub.new [self, Arel.quoted(other)]
82
+ ArelExtensions::Nodes::DateSub.new [self, other]
79
83
  else
80
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other)))
84
+ Arel::Nodes::Grouping.new(Arel::Nodes::Subtraction.new(self, other))
81
85
  end
82
86
  when Arel::Nodes::Function
83
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other)))
87
+ Arel::Nodes::Grouping.new(Arel::Nodes::Subtraction.new(self, other))
84
88
  else
85
- col = Arel.column_of(self.relation.table_name, self.name.to_s)
86
- if (!col) # if the column doesn't exist in the database
87
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other)))
89
+ begin
90
+ col = Arel::Table.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s]
91
+ rescue Exception
92
+ col = nil
93
+ end
94
+ if (!col) #if the column doesn't exist in the database
95
+ Arel::Nodes::Grouping.new(Arel::Nodes::Subtraction.new(self, other))
88
96
  else
89
97
  arg = col.type
90
98
  if (arg == :date || arg == :datetime)
91
99
  case other
92
100
  when Arel::Attributes::Attribute
93
- col2 = Arel.column_of(other.relation.table_name, other.name.to_s)
94
- if (!col2) # if the column doesn't exist in the database
101
+ begin
102
+ col2 = Arel::Table.engine.connection.schema_cache.columns_hash(other.relation.table_name)[other.name.to_s]
103
+ rescue Exception
104
+ col2 = nil
105
+ end
106
+ if (!col2) #if the column doesn't exist in the database
95
107
  ArelExtensions::Nodes::DateSub.new [self, other]
96
108
  else
97
109
  arg2 = col2.type
@@ -103,7 +115,7 @@ module ArelExtensions
103
115
  end
104
116
  when Arel::Nodes::Node, DateTime, Time, String, Date
105
117
  ArelExtensions::Nodes::DateDiff.new [self, other]
106
- when ArelExtensions::Nodes::Duration, Integer
118
+ when ArelExtensions::Nodes::Duration, Integer
107
119
  ArelExtensions::Nodes::DateSub.new [self, other]
108
120
  else # ActiveSupport::Duration
109
121
  ArelExtensions::Nodes::DateAdd.new [self, -other]
@@ -111,15 +123,16 @@ module ArelExtensions
111
123
  else
112
124
  case other
113
125
  when Integer, Float, BigDecimal
114
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.sql(other.to_s)))
126
+ Arel::Nodes::Grouping.new(Arel::Nodes::Subtraction.new(self, Arel.sql(other.to_s)))
115
127
  when String
116
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.sql(other)))
128
+ Arel::Nodes::Grouping.new(Arel::Nodes::Subtraction.new(self, Arel.sql(other)))
117
129
  else
118
- Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.quoted(other)))
130
+ Arel::Nodes::Grouping.new(Arel::Nodes::Subtraction.new(self, other))
119
131
  end
120
132
  end
121
133
  end
122
134
  end
123
135
  end
136
+
124
137
  end
125
138
  end
@@ -7,15 +7,15 @@ require 'arel_extensions/nodes/formatted_number'
7
7
  require 'arel_extensions/nodes/log10'
8
8
  require 'arel_extensions/nodes/power'
9
9
  require 'arel_extensions/nodes/std'
10
- require 'arel_extensions/nodes/sum'
11
10
 
12
11
  module ArelExtensions
13
12
  module MathFunctions
13
+
14
14
  # Arel does not handle Decimal literal properly
15
15
  def * other
16
16
  case other
17
17
  when Float, BigDecimal
18
- super(Arel.quoted(other))
18
+ super(Arel::Nodes.build_quoted(other))
19
19
  else
20
20
  super(other)
21
21
  end
@@ -25,7 +25,7 @@ module ArelExtensions
25
25
  def / other
26
26
  case other
27
27
  when Float, BigDecimal
28
- super(Arel.quoted(other))
28
+ super(Arel::Nodes.build_quoted(other))
29
29
  else
30
30
  super(other)
31
31
  end
@@ -33,86 +33,79 @@ module ArelExtensions
33
33
 
34
34
  # Abs function returns the absolute value of a number passed as argument #
35
35
  def abs
36
- ArelExtensions::Nodes::Abs.new [self]
36
+ ArelExtensions::Nodes::Abs.new [self]
37
37
  end
38
38
 
39
39
  # will rounded up any positive or negative decimal value within the function upwards #
40
40
  def ceil
41
- ArelExtensions::Nodes::Ceil.new [self]
41
+ ArelExtensions::Nodes::Ceil.new [self]
42
42
  end
43
43
 
44
44
  # function rounded up any positive or negative decimal value down to the next least integer
45
45
  def floor
46
- ArelExtensions::Nodes::Floor.new [self]
46
+ ArelExtensions::Nodes::Floor.new [self]
47
47
  end
48
48
 
49
- # function gives the base 10 log
49
+ # function gives the base 10 log
50
50
  def log10
51
- ArelExtensions::Nodes::Log10.new [self]
51
+ ArelExtensions::Nodes::Log10.new [self]
52
52
  end
53
53
 
54
54
  # function gives the power of a number
55
55
  def pow exposant = 0
56
- ArelExtensions::Nodes::Power.new [self, exposant]
56
+ ArelExtensions::Nodes::Power.new [self,exposant]
57
57
  end
58
58
 
59
59
  # function gives the power of a number
60
60
  def power exposant = 0
61
- ArelExtensions::Nodes::Power.new [self, exposant]
61
+ ArelExtensions::Nodes::Power.new [self,exposant]
62
62
  end
63
63
 
64
64
  # Aggregate Functions
65
- def std opts = {unbiased: true}
66
- ArelExtensions::Nodes::Std.new self, **opts
67
- end
68
-
69
- def variance opts = {unbiased: true}
70
- ArelExtensions::Nodes::Variance.new self, **opts
65
+ def std unbiased = true
66
+ ArelExtensions::Nodes::Std.new [self,unbiased]
71
67
  end
72
68
 
73
- def sum opts = {unbiased: true}
74
- if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('9.0.0')
75
- Arel::Nodes::Sum.new [self]
76
- else
77
- ArelExtensions::Nodes::Sum.new self, **opts
78
- end
69
+ def variance unbiased = true
70
+ ArelExtensions::Nodes::Variance.new [self,unbiased]
79
71
  end
80
72
 
81
- # function that can be invoked to produce random numbers between 0 and 1
82
- # def rand seed = nil
83
- # ArelExtensions::Nodes::Rand.new [seed]
84
- # end
85
- alias_method(:random, :rand) rescue nil
73
+ #function that can be invoked to produce random numbers between 0 and 1
74
+ # def rand seed = nil
75
+ # ArelExtensions::Nodes::Rand.new [seed]
76
+ # end
77
+ alias_method :random, :rand
86
78
 
87
- # function is used to round a numeric field to the number of decimals specified
79
+ #function is used to round a numeric field to the number of decimals specified
88
80
  def round precision = nil
89
- if precision
90
- ArelExtensions::Nodes::Round.new [self, precision]
91
- else
92
- ArelExtensions::Nodes::Round.new [self]
93
- end
81
+ if precision
82
+ ArelExtensions::Nodes::Round.new [self, precision]
83
+ else
84
+ ArelExtensions::Nodes::Round.new [self]
85
+ end
94
86
  end
95
87
 
96
88
  # function returning a number at a specific format
97
- def format_number format_string, locale = nil
89
+ def format_number format_string, locale=nil
98
90
  begin
99
- sprintf(format_string, 0) # this line is to get the right error message if the format_string is not correct
91
+ sprintf(format_string,0) # this line is to get the right error message if the format_string is not correct
100
92
  m = /^(.*)%([ #+\-0]*)([1-9][0-9]+|[1-9]?)[.]?([0-9]*)([a-zA-Z])(.*)$/.match(format_string)
101
93
  opts = {
102
- prefix: m[1],
103
- flags: m[2].split(//).uniq.join,
104
- width: m[3].to_i,
105
- precision: m[4] != '' ? m[4].to_i : 6,
106
- type: m[5],
107
- suffix: m[6],
108
- locale: locale,
109
- original_string: format_string
94
+ :prefix => m[1],
95
+ :flags => m[2].split(//).uniq.join,
96
+ :width => m[3].to_i,
97
+ :precision => m[4] != '' ? m[4].to_i : 6,
98
+ :type => m[5],
99
+ :suffix => m[6],
100
+ :locale => locale,
101
+ :original_string => format_string
110
102
  }
111
- # opts = {locale: 'fr_FR', type: "e"/"f"/"d", prefix: "$ ", suffix: " %", flags: " +-#0", width: 5, precision: 6}
112
- ArelExtensions::Nodes::FormattedNumber.new [self, opts]
103
+ # opts = {:locale => 'fr_FR', :type => "e"/"f"/"d", :prefix => "$ ", :suffix => " %", :flags => " +-#0", :width => 5, :precision => 6}
104
+ ArelExtensions::Nodes::FormattedNumber.new [self,opts]
113
105
  rescue Exception
114
- Arel.quoted('Wrong Format')
106
+ Arel::Nodes.build_quoted('Wrong Format')
115
107
  end
116
108
  end
109
+
117
110
  end
118
111
  end
@@ -2,6 +2,7 @@ module ArelExtensions
2
2
  module Nodes
3
3
  class Abs < Function
4
4
  RETURN_TYPE = :number
5
+
5
6
  end
6
7
  end
7
8
  end
@@ -16,8 +16,9 @@ module ArelExtensions
16
16
  RETURN_TYPE = :boolean
17
17
 
18
18
  def initialize expr
19
- super expr.first
19
+ super expr.first
20
20
  end
21
21
  end
22
+
22
23
  end
23
24
  end
@@ -1,11 +1,7 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
- if Gem::Version.new(Arel::VERSION) < Gem::Version.new('7.1.0')
3
+ if Arel::VERSION < "7.1.0"
4
4
  class Case < Arel::Nodes::Node
5
- include Arel::Expressions
6
- include Arel::Math
7
- include Arel::Predications
8
- include Arel::OrderPredications
9
5
  attr_accessor :case, :conditions, :default
10
6
 
11
7
  def initialize expression = nil, default = nil
@@ -19,6 +15,7 @@ module ArelExtensions
19
15
 
20
16
  class Else < Arel::Nodes::Unary # :nodoc:
21
17
  end
18
+
22
19
  end
23
20
  else
24
21
  class Case < Arel::Nodes::Case
@@ -29,12 +26,9 @@ module ArelExtensions
29
26
  end
30
27
  end
31
28
 
32
- class ArelExtensions::Nodes::Case
29
+ ArelExtensions::Nodes::Case.class_eval do
33
30
  include Arel::Expressions
34
- include Arel::Math
35
- include Arel::Predications
36
31
  include Arel::OrderPredications
37
- include ArelExtensions::Aliases
38
32
  include ArelExtensions::Math
39
33
  include ArelExtensions::Comparators
40
34
  include ArelExtensions::Predications
@@ -44,9 +38,11 @@ module ArelExtensions
44
38
 
45
39
  def return_type
46
40
  obj = if @conditions.length > 0
47
- @conditions.last.right
41
+ @conditions.last.right
48
42
  elsif @default
49
43
  @default.expr
44
+ else
45
+ nil
50
46
  end
51
47
  if obj.respond_to?(:return_type)
52
48
  obj.return_type
@@ -54,10 +50,14 @@ module ArelExtensions
54
50
  case obj
55
51
  when Integer, Float
56
52
  :number
57
- when Date, DateTime, Time
53
+ when Date, DateTime,Time
58
54
  :datetime
59
55
  when Arel::Attributes::Attribute
60
- Arel.column_of(obj.relation.table_name, obj.name.to_s)&.type || :string
56
+ begin
57
+ Arel::Table.engine.connection.schema_cache.columns_hash(obj.relation.table_name)[obj.name.to_s].type
58
+ rescue Exception
59
+ :string
60
+ end
61
61
  else
62
62
  :string
63
63
  end
@@ -92,14 +92,14 @@ module ArelExtensions
92
92
 
93
93
  def eql? other
94
94
  self.class == other.class &&
95
- self.case == other.case &&
96
- self.conditions == other.conditions &&
97
- self.default == other.default
95
+ self.case == other.case &&
96
+ self.conditions == other.conditions &&
97
+ self.default == other.default
98
98
  end
99
99
  alias :== :eql?
100
100
 
101
101
  def as other
102
- Arel::Nodes::As.new self, Arel.sql(other)
102
+ Arel::Nodes::As.new self, Arel::Nodes::SqlLiteral.new(other)
103
103
  end
104
104
  end
105
105
  end
@@ -14,16 +14,13 @@ module ArelExtensions
14
14
  @return_type = :decimal
15
15
  when :number
16
16
  @return_type = :number
17
- when 'char', 'varchar', 'nchar', 'nvarchar'
17
+ when 'char', 'varchar', 'text', 'nchar', 'nvarchar', 'ntext'
18
18
  @return_type = :string
19
- when 'text', :text, 'ntext', :ntext
20
- @as_attr = expr[1].to_sym
21
- @return_type = :string
22
- when :datetime, 'datetime', 'smalldatetime'
19
+ when :datetime, 'datetime','smalldatetime'
23
20
  @return_type = :datetime
24
- when :time, 'time'
21
+ when :time,'time'
25
22
  @return_type = :time
26
- when :date, 'date'
23
+ when :date,'date'
27
24
  @return_type = :date
28
25
  when :binary, 'binary', 'varbinary', 'image'
29
26
  @return_type = :binary
@@ -42,13 +39,14 @@ module ArelExtensions
42
39
  when :ruby_time
43
40
  ArelExtensions::Nodes::DateAdd.new [self, other]
44
41
  else
45
- Arel.grouping(Arel::Nodes::Addition.new self, other)
42
+ Arel::Nodes::Grouping.new(Arel::Nodes::Addition.new self, other)
46
43
  end
47
44
  end
48
45
 
49
46
  def return_type
50
47
  @return_type
51
48
  end
49
+
52
50
  end
53
51
  end
54
52
  end
@@ -1,7 +1,7 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Ceil < Function
4
- RETURN_TYPE = :number
4
+ RETURN_TYPE = :number
5
5
  end
6
6
  end
7
7
  end
@@ -2,7 +2,7 @@ module ArelExtensions
2
2
  module Nodes
3
3
  class Coalesce < Function
4
4
  RETURN_TYPE = :string
5
-
5
+
6
6
  attr_accessor :left_node_type
7
7
 
8
8
  def return_type
@@ -20,7 +20,7 @@ module ArelExtensions
20
20
  @left_node_type = :number
21
21
  when ArelExtensions::Nodes::Coalesce, ArelExtensions::Nodes::Function
22
22
  @left_node_type = expr.first.respond_to?(:left_node_type) ? expr.first.left_node_type : nil
23
- when Arel::Nodes::Node, Arel::Attributes::Attribute
23
+ when Arel::Nodes::Node, Arel::Attributes::Attribute
24
24
  @left_node_type = type_of_attribute(expr.first)
25
25
  when Date
26
26
  @left_node_type = :ruby_date
@@ -29,6 +29,7 @@ module ArelExtensions
29
29
  end
30
30
  return super(tab)
31
31
  end
32
+
32
33
  end
33
34
  end
34
35
  end
@@ -1,17 +1,18 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Collate < Function
4
- RETURN_TYPE = :string
4
+ RETURN_TYPE = :string
5
5
 
6
- attr_accessor :ai, :ci, :option
6
+ attr_accessor :ai, :ci, :option
7
+
8
+ def initialize left, option=nil, ai=false, ci=false
9
+ @ai = ai
10
+ @ci = ci
11
+ @option = option
12
+ tab = [convert_to_node(left)]
13
+ return super(tab)
14
+ end
7
15
 
8
- def initialize left, option = nil, ai = false, ci = false
9
- @ai = ai
10
- @ci = ci
11
- @option = option
12
- tab = [convert_to_node(left)]
13
- return super(tab)
14
- end
15
16
  end
16
17
  end
17
18
  end
@@ -11,12 +11,12 @@ module ArelExtensions::Nodes
11
11
  else
12
12
  node
13
13
  end
14
- }.flatten.reduce([]) { |res, b|
14
+ }.flatten.reduce([]) { | res, b |
15
15
  # concatenate successive literal strings.
16
- if b.is_a?(Arel::Nodes::Quoted) && b.expr == ''
16
+ if b.is_a?(Arel::Nodes::Quoted) && b.expr == ""
17
17
  res
18
18
  elsif res.last && res.last.is_a?(Arel::Nodes::Quoted) && b.is_a?(Arel::Nodes::Quoted)
19
- res[-1] = Arel.quoted(res.last.expr + b.expr)
19
+ res[-1] = Arel::Nodes.build_quoted(res.last.expr + b.expr)
20
20
  else
21
21
  res << b
22
22
  end
@@ -37,16 +37,25 @@ module ArelExtensions::Nodes
37
37
  def concat(other)
38
38
  Concat.new(self.expressions + [other])
39
39
  end
40
+
40
41
  end
41
42
 
42
- class GroupConcat < AggregateFunction
43
+ class GroupConcat < Function
43
44
  RETURN_TYPE = :string
44
45
 
45
- attr_accessor :separator
46
-
47
- def initialize node, separator = ', ', **opts
48
- @separator = convert_to_node(separator)
49
- super node, **opts
46
+ attr_accessor :orders
47
+
48
+ def initialize expr
49
+ tab = expr.map { |arg|
50
+ if arg.is_a?(Array)
51
+ @orders = arg
52
+ nil
53
+ else
54
+ convert_to_node(arg)
55
+ end
56
+ }.compact
57
+ super(tab)
50
58
  end
59
+
51
60
  end
52
61
  end