arel 7.0.0 → 9.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +27 -0
  3. data/MIT-LICENSE.txt +1 -1
  4. data/{README.markdown → README.md} +93 -31
  5. data/lib/arel/alias_predication.rb +1 -0
  6. data/lib/arel/attributes/attribute.rb +1 -0
  7. data/lib/arel/attributes.rb +1 -0
  8. data/lib/arel/collectors/bind.rb +6 -18
  9. data/lib/arel/collectors/composite.rb +32 -0
  10. data/lib/arel/collectors/plain_string.rb +2 -1
  11. data/lib/arel/collectors/sql_string.rb +1 -1
  12. data/lib/arel/collectors/substitute_binds.rb +28 -0
  13. data/lib/arel/compatibility/wheres.rb +1 -0
  14. data/lib/arel/crud.rb +1 -0
  15. data/lib/arel/delete_manager.rb +1 -0
  16. data/lib/arel/errors.rb +8 -0
  17. data/lib/arel/expressions.rb +1 -0
  18. data/lib/arel/factory_methods.rb +1 -0
  19. data/lib/arel/insert_manager.rb +6 -0
  20. data/lib/arel/math.rb +25 -0
  21. data/lib/arel/nodes/and.rb +1 -0
  22. data/lib/arel/nodes/ascending.rb +1 -0
  23. data/lib/arel/nodes/binary.rb +1 -0
  24. data/lib/arel/nodes/bind_param.rb +20 -2
  25. data/lib/arel/nodes/case.rb +58 -0
  26. data/lib/arel/nodes/casted.rb +6 -1
  27. data/lib/arel/nodes/count.rb +3 -0
  28. data/lib/arel/nodes/delete_statement.rb +1 -0
  29. data/lib/arel/nodes/descending.rb +1 -0
  30. data/lib/arel/nodes/equality.rb +1 -0
  31. data/lib/arel/nodes/extract.rb +1 -0
  32. data/lib/arel/nodes/false.rb +2 -0
  33. data/lib/arel/nodes/full_outer_join.rb +1 -0
  34. data/lib/arel/nodes/function.rb +3 -0
  35. data/lib/arel/nodes/grouping.rb +1 -0
  36. data/lib/arel/nodes/in.rb +1 -0
  37. data/lib/arel/nodes/infix_operation.rb +37 -1
  38. data/lib/arel/nodes/inner_join.rb +1 -0
  39. data/lib/arel/nodes/insert_statement.rb +1 -0
  40. data/lib/arel/nodes/join_source.rb +1 -0
  41. data/lib/arel/nodes/matches.rb +1 -0
  42. data/lib/arel/nodes/named_function.rb +1 -0
  43. data/lib/arel/nodes/node.rb +1 -0
  44. data/lib/arel/nodes/outer_join.rb +1 -0
  45. data/lib/arel/nodes/over.rb +1 -0
  46. data/lib/arel/nodes/regexp.rb +1 -0
  47. data/lib/arel/nodes/right_outer_join.rb +1 -0
  48. data/lib/arel/nodes/select_core.rb +1 -0
  49. data/lib/arel/nodes/select_statement.rb +1 -0
  50. data/lib/arel/nodes/sql_literal.rb +1 -0
  51. data/lib/arel/nodes/string_join.rb +1 -0
  52. data/lib/arel/nodes/table_alias.rb +1 -0
  53. data/lib/arel/nodes/terminal.rb +2 -0
  54. data/lib/arel/nodes/true.rb +2 -0
  55. data/lib/arel/nodes/unary.rb +7 -2
  56. data/lib/arel/nodes/unary_operation.rb +26 -0
  57. data/lib/arel/nodes/unqualified_column.rb +1 -0
  58. data/lib/arel/nodes/update_statement.rb +1 -0
  59. data/lib/arel/nodes/values.rb +1 -0
  60. data/lib/arel/nodes/values_list.rb +23 -0
  61. data/lib/arel/nodes/window.rb +2 -0
  62. data/lib/arel/nodes/with.rb +1 -0
  63. data/lib/arel/nodes.rb +6 -0
  64. data/lib/arel/order_predications.rb +1 -0
  65. data/lib/arel/predications.rb +9 -0
  66. data/lib/arel/select_manager.rb +2 -1
  67. data/lib/arel/table.rb +4 -19
  68. data/lib/arel/tree_manager.rb +3 -5
  69. data/lib/arel/update_manager.rb +1 -0
  70. data/lib/arel/visitors/depth_first.rb +15 -1
  71. data/lib/arel/visitors/dot.rb +15 -2
  72. data/lib/arel/visitors/ibm_db.rb +1 -0
  73. data/lib/arel/visitors/informix.rb +1 -2
  74. data/lib/arel/visitors/mssql.rb +1 -0
  75. data/lib/arel/visitors/mysql.rb +9 -0
  76. data/lib/arel/visitors/oracle.rb +16 -4
  77. data/lib/arel/visitors/oracle12.rb +10 -3
  78. data/lib/arel/visitors/postgresql.rb +38 -1
  79. data/lib/arel/visitors/reduce.rb +4 -2
  80. data/lib/arel/visitors/sqlite.rb +10 -0
  81. data/lib/arel/visitors/to_sql.rb +86 -86
  82. data/lib/arel/visitors/visitor.rb +4 -2
  83. data/lib/arel/visitors/where_sql.rb +1 -0
  84. data/lib/arel/visitors.rb +1 -23
  85. data/lib/arel/window_predications.rb +1 -0
  86. data/lib/arel.rb +4 -1
  87. metadata +27 -9
  88. data/lib/arel/visitors/bind_substitute.rb +0 -9
  89. data/lib/arel/visitors/bind_visitor.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7b8575f1877fe831a05c70632e7046c6ce384c9
4
- data.tar.gz: ab4c6895e273c5ad2bd6456bdf2f0fd1b3f7e0a2
3
+ metadata.gz: dc3719172683caa3fb2bd15ce6ef3ed477a8b2ef
4
+ data.tar.gz: 74b4f1d7d44871db56c62907ed1c4ba51040bf6e
5
5
  SHA512:
6
- metadata.gz: 71feebe60212b48f1bce1fe0acc756728aff663f7e84836bc5888ed237bc6315b22d95993d9b9fce655dbccbf35c75652e9fd62c185d141c0c246084e3d70e68
7
- data.tar.gz: 563e00ae3191b5d4be40b8ead9168ead202242593a9761a2a5e938454b13c3094542d83b2e3ca5706c572ca2d1551772a9bce80631e55be9aa3379435bfecb75
6
+ metadata.gz: bedb8b1701ee99fca067c4a52f92d096648d25d67d4809408ede3eeb40298b3fc83a9fdccf1f4195c32f871ee430eba29f11dedd19b12032639a8b03bc7ec54c
7
+ data.tar.gz: 97a3b3155db8b0c57ca4616598d45d8aad7592c56a6882e0e7f5369eeac221802cae5cd60b4d72a92d755eb13be4b39aedc9ea967e1c6faac28953a3414d1f39
data/History.txt CHANGED
@@ -1,3 +1,30 @@
1
+ === 9.0.0 / 2017-11-14
2
+
3
+ * Enhancements
4
+ * `InsertManager#insert` is now chainable
5
+ * Support multiple inserts
6
+
7
+ === 8.0.0 / 2017-02-21
8
+
9
+ * Enhancements
10
+
11
+ * Remove deprecated type casting support in Arel
12
+ * Frozen all string literals in Arel
13
+
14
+ === 7.1.1 / 2016-07-27
15
+
16
+ * Bug Fixes
17
+
18
+ * Fix warning in `Casted#hash`
19
+
20
+ === 7.1.0 / 2016-07-19
21
+
22
+ * Enhancements
23
+
24
+ * Support Ruby 2.4 unified Integer class
25
+ * Implement `CASE` conditional expression
26
+ * Support for Bitwise Operations as `InfixOperations`
27
+
1
28
  === 7.0.0 / 2015-12-17
2
29
 
3
30
  * Enhancements
data/MIT-LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007-2015 Nick Kallen, Bryan Helmkamp, Emilio Tagua, Aaron Patterson
1
+ Copyright (c) 2007-2016 Nick Kallen, Bryan Helmkamp, Emilio Tagua, Aaron Patterson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,6 +1,7 @@
1
1
  # Arel
2
2
 
3
3
  * http://github.com/rails/arel
4
+ * [API Documentation](http://www.rubydoc.info/github/rails/arel)
4
5
 
5
6
  ## DESCRIPTION
6
7
 
@@ -8,8 +9,8 @@ Arel Really Exasperates Logicians
8
9
 
9
10
  Arel is a SQL AST manager for Ruby. It
10
11
 
11
- 1. Simplifies the generation of complex SQL queries
12
- 2. Adapts to various RDBMSes
12
+ 1. simplifies the generation of complex SQL queries, and
13
+ 2. adapts to various RDBMSes.
13
14
 
14
15
  It is intended to be a framework framework; that is, you can build your own ORM
15
16
  with it, focusing on innovative object and collection modeling as opposed to
@@ -17,7 +18,7 @@ database compatibility and query generation.
17
18
 
18
19
  ## Status
19
20
 
20
- For the moment, Arel uses Active Record's connection adapters to connect to the various engines, connection pooling, perform quoting, and do type conversion.
21
+ For the moment, Arel uses Active Record's connection adapters to connect to the various engines and perform connection pooling, quoting, and type conversion.
21
22
 
22
23
  ## A Gentle Introduction
23
24
 
@@ -27,7 +28,7 @@ Generating a query with Arel is simple. For example, in order to produce
27
28
  SELECT * FROM users
28
29
  ```
29
30
 
30
- you construct a table relation and convert it to sql:
31
+ you construct a table relation and convert it to SQL:
31
32
 
32
33
  ```ruby
33
34
  users = Arel::Table.new(:users)
@@ -56,13 +57,48 @@ users.project(users[:id])
56
57
  Comparison operators `=`, `!=`, `<`, `>`, `<=`, `>=`, `IN`:
57
58
 
58
59
  ```ruby
59
- users.where(users[:age].eq(10)).project(Arel.sql('*')) # => SELECT * FROM "users" WHERE "users"."age" = 10
60
- users.where(users[:age].not_eq(10)).project(Arel.sql('*')) # => SELECT * FROM "users" WHERE "users"."age" != 10
61
- users.where(users[:age].lt(10)).project(Arel.sql('*')) # => SELECT * FROM "users" WHERE "users"."age" < 10
62
- users.where(users[:age].gt(10)).project(Arel.sql('*')) # => SELECT * FROM "users" WHERE "users"."age" > 10
63
- users.where(users[:age].lteq(10)).project(Arel.sql('*')) # => SELECT * FROM "users" WHERE "users"."age" <= 10
64
- users.where(users[:age].gteq(10)).project(Arel.sql('*')) # => SELECT * FROM "users" WHERE "users"."age" >= 10
65
- users.where(users[:age].in([20, 16, 17])).project(Arel.sql('*')) # => SELECT * FROM "users" WHERE "users"."age" IN (20, 16, 17)
60
+ users.where(users[:age].eq(10)).project(Arel.sql('*'))
61
+ # => SELECT * FROM "users" WHERE "users"."age" = 10
62
+
63
+ users.where(users[:age].not_eq(10)).project(Arel.sql('*'))
64
+ # => SELECT * FROM "users" WHERE "users"."age" != 10
65
+
66
+ users.where(users[:age].lt(10)).project(Arel.sql('*'))
67
+ # => SELECT * FROM "users" WHERE "users"."age" < 10
68
+
69
+ users.where(users[:age].gt(10)).project(Arel.sql('*'))
70
+ # => SELECT * FROM "users" WHERE "users"."age" > 10
71
+
72
+ users.where(users[:age].lteq(10)).project(Arel.sql('*'))
73
+ # => SELECT * FROM "users" WHERE "users"."age" <= 10
74
+
75
+ users.where(users[:age].gteq(10)).project(Arel.sql('*'))
76
+ # => SELECT * FROM "users" WHERE "users"."age" >= 10
77
+
78
+ users.where(users[:age].in([20, 16, 17])).project(Arel.sql('*'))
79
+ # => SELECT * FROM "users" WHERE "users"."age" IN (20, 16, 17)
80
+ ```
81
+
82
+ Bitwise operators `&`, `|`, `^`, `<<`, `>>`:
83
+
84
+ ```ruby
85
+ users.where((users[:bitmap] & 16).gt(0)).project(Arel.sql('*'))
86
+ # => SELECT * FROM "users" WHERE ("users"."bitmap" & 16) > 0
87
+
88
+ users.where((users[:bitmap] | 16).gt(0)).project(Arel.sql('*'))
89
+ # => SELECT * FROM "users" WHERE ("users"."bitmap" | 16) > 0
90
+
91
+ users.where((users[:bitmap] ^ 16).gt(0)).project(Arel.sql('*'))
92
+ # => SELECT * FROM "users" WHERE ("users"."bitmap" ^ 16) > 0
93
+
94
+ users.where((users[:bitmap] << 1).gt(0)).project(Arel.sql('*'))
95
+ # => SELECT * FROM "users" WHERE ("users"."bitmap" << 1) > 0
96
+
97
+ users.where((users[:bitmap] >> 1).gt(0)).project(Arel.sql('*'))
98
+ # => SELECT * FROM "users" WHERE ("users"."bitmap" >> 1) > 0
99
+
100
+ users.where((~ users[:bitmap]).gt(0)).project(Arel.sql('*'))
101
+ # => SELECT * FROM "users" WHERE ~ "users"."bitmap" > 0
66
102
  ```
67
103
 
68
104
  Joins resemble SQL strongly:
@@ -72,7 +108,7 @@ users.join(photos).on(users[:id].eq(photos[:user_id]))
72
108
  # => SELECT * FROM users INNER JOIN photos ON users.id = photos.user_id
73
109
  ```
74
110
 
75
- Left Joins
111
+ Left joins:
76
112
 
77
113
  ```ruby
78
114
  users.join(photos, Arel::Nodes::OuterJoin).on(users[:id].eq(photos[:user_id]))
@@ -93,7 +129,7 @@ users.project(users[:name]).group(users[:name])
93
129
  # => SELECT users.name FROM users GROUP BY users.name
94
130
  ```
95
131
 
96
- The best property of arel is its "composability", or closure under all operations. For example, to restrict AND project, just "chain" the method invocations:
132
+ The best property of Arel is its "composability," or closure under all operations. For example, to restrict AND project, just "chain" the method invocations:
97
133
 
98
134
  ```ruby
99
135
  users \
@@ -114,28 +150,47 @@ The `OR` operator works like this:
114
150
  users.where(users[:name].eq('bob').or(users[:age].lt(25)))
115
151
  ```
116
152
 
117
- The `AND` operator behaves similarly.
153
+ The `AND` operator behaves similarly. Here is an example of the `DISTINCT` operator:
154
+
155
+ ```ruby
156
+ posts = Arel::Table.new(:posts)
157
+ posts.project(posts[:title])
158
+ posts.distinct
159
+ posts.to_sql # => 'SELECT DISTINCT "posts"."title" FROM "posts"'
160
+ ```
118
161
 
119
162
  Aggregate functions `AVG`, `SUM`, `COUNT`, `MIN`, `MAX`, `HAVING`:
120
163
 
121
164
  ```ruby
122
- photos.group(photos[:user_id]).having(photos[:id].count.gt(5)) # => SELECT FROM photos GROUP BY photos.user_id HAVING COUNT(photos.id) > 5
123
- users.project(users[:age].sum) # => SELECT SUM(users.age) FROM users
124
- users.project(users[:age].average) # => SELECT AVG(users.age) FROM users
125
- users.project(users[:age].maximum) # => SELECT MAX(users.age) FROM users
126
- users.project(users[:age].minimum) # => SELECT MIN(users.age) FROM users
127
- users.project(users[:age].count) # => SELECT COUNT(users.age) FROM users
165
+ photos.group(photos[:user_id]).having(photos[:id].count.gt(5))
166
+ # => SELECT FROM photos GROUP BY photos.user_id HAVING COUNT(photos.id) > 5
167
+
168
+ users.project(users[:age].sum)
169
+ # => SELECT SUM(users.age) FROM users
170
+
171
+ users.project(users[:age].average)
172
+ # => SELECT AVG(users.age) FROM users
173
+
174
+ users.project(users[:age].maximum)
175
+ # => SELECT MAX(users.age) FROM users
176
+
177
+ users.project(users[:age].minimum)
178
+ # => SELECT MIN(users.age) FROM users
179
+
180
+ users.project(users[:age].count)
181
+ # => SELECT COUNT(users.age) FROM users
128
182
  ```
129
183
 
130
184
  Aliasing Aggregate Functions:
131
185
 
132
186
  ```ruby
133
- users.project(users[:age].average.as("mean_age")) # => SELECT AVG(users.age) AS mean_age FROM users
187
+ users.project(users[:age].average.as("mean_age"))
188
+ # => SELECT AVG(users.age) AS mean_age FROM users
134
189
  ```
135
190
 
136
- ### The Crazy Features
191
+ ### The Advanced Features
137
192
 
138
- The examples above are fairly simple and other libraries match or come close to matching the expressiveness of Arel (e.g., `Sequel` in Ruby).
193
+ The examples above are fairly simple and other libraries match or come close to matching the expressiveness of Arel (e.g. `Sequel` in Ruby).
139
194
 
140
195
  #### Inline math operations
141
196
 
@@ -160,6 +215,7 @@ products.
160
215
 
161
216
  #### Complex Joins
162
217
 
218
+ ##### Alias
163
219
  Where Arel really shines is in its ability to handle complex joins and aggregations. As a first example, let's consider an "adjacency list", a tree represented in a table. Suppose we have a table `comments`, representing a threaded discussion:
164
220
 
165
221
  ```ruby
@@ -179,12 +235,14 @@ Joining a table to itself requires aliasing in SQL. This aliasing can be handled
179
235
  replies = comments.alias
180
236
  comments_with_replies = \
181
237
  comments.join(replies).on(replies[:parent_id].eq(comments[:id])).where(comments[:id].eq(1))
182
- # => SELECT * FROM comments INNER JOIN comments AS comments_2 WHERE comments_2.parent_id = comments.id AND comments.id = 1
238
+ # => SELECT * FROM comments INNER JOIN comments AS comments_2
239
+ # WHERE comments_2.parent_id = comments.id AND comments.id = 1
183
240
  ```
184
241
 
185
242
  This will return the reply for the first comment.
186
243
 
187
- [Common Table Expressions(CTE)](https://en.wikipedia.org/wiki/Common_table_expressions#Common_table_expression) support via:
244
+ ##### CTE
245
+ [Common Table Expressions (CTE)](https://en.wikipedia.org/wiki/Common_table_expressions#Common_table_expression) support via:
188
246
 
189
247
  Create a `CTE`
190
248
 
@@ -201,9 +259,12 @@ users.
201
259
  project(users[:id], cte_table[:click].sum).
202
260
  with(composed_cte)
203
261
 
204
- # => WITH cte_table AS (SELECT FROM photos WHERE photos.created_at > '2014-05-02') SELECT users.id, SUM(cte_table.click) FROM users INNER JOIN cte_table ON users.id = cte_table.user_id
262
+ # => WITH cte_table AS (SELECT FROM photos WHERE photos.created_at > '2014-05-02')
263
+ # SELECT users.id, SUM(cte_table.click)
264
+ # FROM users INNER JOIN cte_table ON users.id = cte_table.user_id
205
265
  ```
206
266
 
267
+ #### Write SQL strings
207
268
  When your query is too complex for `Arel`, you can use `Arel::SqlLiteral`:
208
269
 
209
270
  ```ruby
@@ -214,17 +275,18 @@ photo_clicks = Arel::Nodes::SqlLiteral.new(<<-SQL
214
275
  ELSE default_calculation END
215
276
  SQL
216
277
  )
278
+
217
279
  photos.project(photo_clicks.as("photo_clicks"))
218
280
  # => SELECT CASE WHEN condition1 THEN calculation1
219
- WHEN condition2 THEN calculation2
220
- WHEN condition3 THEN calculation3
221
- ELSE default_calculation END
222
- FROM "photos"
281
+ # WHEN condition2 THEN calculation2
282
+ # WHEN condition3 THEN calculation3
283
+ # ELSE default_calculation END
284
+ # FROM "photos"
223
285
  ```
224
286
 
225
287
  ## Contributing to Arel
226
288
 
227
- Arel is work of many contributors. You're encouraged to submit pull requests, propose
289
+ Arel is the work of many contributors. You're encouraged to submit pull requests, propose
228
290
  features and discuss issues.
229
291
 
230
292
  See [CONTRIBUTING](CONTRIBUTING.md).
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module AliasPredication
3
4
  def as other
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module Attributes
3
4
  class Attribute < Struct.new :relation, :name
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'arel/attributes/attribute'
2
3
 
3
4
  module Arel
@@ -1,35 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arel
2
4
  module Collectors
3
5
  class Bind
4
6
  def initialize
5
- @parts = []
7
+ @binds = []
6
8
  end
7
9
 
8
10
  def << str
9
- @parts << str
10
11
  self
11
12
  end
12
13
 
13
14
  def add_bind bind
14
- @parts << bind
15
+ @binds << bind
15
16
  self
16
17
  end
17
18
 
18
- def value; @parts; end
19
-
20
- def substitute_binds bvs
21
- bvs = bvs.dup
22
- @parts.map do |val|
23
- if Arel::Nodes::BindParam === val
24
- bvs.shift
25
- else
26
- val
27
- end
28
- end
29
- end
30
-
31
- def compile bvs
32
- substitute_binds(bvs).join
19
+ def value
20
+ @binds
33
21
  end
34
22
  end
35
23
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arel
4
+ module Collectors
5
+ class Composite
6
+ def initialize(left, right)
7
+ @left = left
8
+ @right = right
9
+ end
10
+
11
+ def << str
12
+ left << str
13
+ right << str
14
+ self
15
+ end
16
+
17
+ def add_bind bind, &block
18
+ left.add_bind bind, &block
19
+ right.add_bind bind, &block
20
+ self
21
+ end
22
+
23
+ def value
24
+ [left.value, right.value]
25
+ end
26
+
27
+ protected
28
+
29
+ attr_reader :left, :right
30
+ end
31
+ end
32
+ end
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module Collectors
3
4
  class PlainString
4
5
  def initialize
5
- @str = ''
6
+ @str = ''.dup
6
7
  end
7
8
 
8
9
  def value
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'arel/collectors/plain_string'
4
4
 
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ module Arel
3
+ module Collectors
4
+ class SubstituteBinds
5
+ def initialize(quoter, delegate_collector)
6
+ @quoter = quoter
7
+ @delegate = delegate_collector
8
+ end
9
+
10
+ def << str
11
+ delegate << str
12
+ self
13
+ end
14
+
15
+ def add_bind bind
16
+ self << quoter.quote(bind)
17
+ end
18
+
19
+ def value
20
+ delegate.value
21
+ end
22
+
23
+ protected
24
+
25
+ attr_reader :quoter, :delegate
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module Compatibility # :nodoc:
3
4
  class Wheres # :nodoc:
data/lib/arel/crud.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  ###
3
4
  # FIXME hopefully we can remove this
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  class DeleteManager < Arel::TreeManager
3
4
  def initialize
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module Arel
3
+ class ArelError < StandardError
4
+ end
5
+
6
+ class EmptyJoinError < ArelError
7
+ end
8
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module Expressions
3
4
  def count distinct = false
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  ###
3
4
  # Methods for creating various nodes
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  class InsertManager < Arel::TreeManager
3
4
  def initialize
@@ -33,10 +34,15 @@ module Arel
33
34
  end
34
35
  @ast.values = create_values values, @ast.columns
35
36
  end
37
+ self
36
38
  end
37
39
 
38
40
  def create_values values, columns
39
41
  Nodes::Values.new values, columns
40
42
  end
43
+
44
+ def create_values_list(rows)
45
+ Nodes::ValuesList.new(rows)
46
+ end
41
47
  end
42
48
  end
data/lib/arel/math.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module Math
3
4
  def *(other)
@@ -15,5 +16,29 @@ module Arel
15
16
  def /(other)
16
17
  Arel::Nodes::Division.new(self, other)
17
18
  end
19
+
20
+ def &(other)
21
+ Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseAnd.new(self, other))
22
+ end
23
+
24
+ def |(other)
25
+ Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseOr.new(self, other))
26
+ end
27
+
28
+ def ^(other)
29
+ Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseXor.new(self, other))
30
+ end
31
+
32
+ def <<(other)
33
+ Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseShiftLeft.new(self, other))
34
+ end
35
+
36
+ def >>(other)
37
+ Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseShiftRight.new(self, other))
38
+ end
39
+
40
+ def ~@
41
+ Arel::Nodes::BitwiseNot.new(self)
42
+ end
18
43
  end
19
44
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module Nodes
3
4
  class And < Arel::Nodes::Node
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module Nodes
3
4
  class Ascending < Ordering
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module Nodes
3
4
  class Binary < Arel::Nodes::Node
@@ -1,8 +1,26 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module Nodes
3
4
  class BindParam < Node
4
- def ==(other)
5
- other.is_a?(BindParam)
5
+ attr_accessor :value
6
+
7
+ def initialize(value)
8
+ @value = value
9
+ super()
10
+ end
11
+
12
+ def hash
13
+ [self.class, self.value].hash
14
+ end
15
+
16
+ def eql?(other)
17
+ other.is_a?(BindParam) &&
18
+ value == other.value
19
+ end
20
+ alias :== :eql?
21
+
22
+ def nil?
23
+ value.nil?
6
24
  end
7
25
  end
8
26
  end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+ module Arel
3
+ module Nodes
4
+ class Case < Arel::Nodes::Node
5
+ include Arel::OrderPredications
6
+ include Arel::Predications
7
+ include Arel::AliasPredication
8
+
9
+ attr_accessor :case, :conditions, :default
10
+
11
+ def initialize expression = nil, default = nil
12
+ @case = expression
13
+ @conditions = []
14
+ @default = default
15
+ end
16
+
17
+ def when condition, expression = nil
18
+ @conditions << When.new(Nodes.build_quoted(condition), expression)
19
+ self
20
+ end
21
+
22
+ def then expression
23
+ @conditions.last.right = Nodes.build_quoted(expression)
24
+ self
25
+ end
26
+
27
+ def else expression
28
+ @default = Else.new Nodes.build_quoted(expression)
29
+ self
30
+ end
31
+
32
+ def initialize_copy other
33
+ super
34
+ @case = @case.clone if @case
35
+ @conditions = @conditions.map { |x| x.clone }
36
+ @default = @default.clone if @default
37
+ end
38
+
39
+ def hash
40
+ [@case, @conditions, @default].hash
41
+ end
42
+
43
+ def eql? other
44
+ self.class == other.class &&
45
+ self.case == other.case &&
46
+ self.conditions == other.conditions &&
47
+ self.default == other.default
48
+ end
49
+ alias :== :eql?
50
+ end
51
+
52
+ class When < Binary # :nodoc:
53
+ end
54
+
55
+ class Else < Unary # :nodoc:
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module Nodes
3
4
  class Casted < Arel::Nodes::Node # :nodoc:
@@ -10,6 +11,10 @@ module Arel
10
11
 
11
12
  def nil?; @val.nil?; end
12
13
 
14
+ def hash
15
+ [self.class, val, attribute].hash
16
+ end
17
+
13
18
  def eql? other
14
19
  self.class == other.class &&
15
20
  self.val == other.val &&
@@ -25,7 +30,7 @@ module Arel
25
30
 
26
31
  def self.build_quoted other, attribute = nil
27
32
  case other
28
- when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Table, Arel::Nodes::BindParam, Arel::SelectManager, Arel::Nodes::Quoted
33
+ when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Table, Arel::Nodes::BindParam, Arel::SelectManager, Arel::Nodes::Quoted, Arel::Nodes::SqlLiteral
29
34
  other
30
35
  else
31
36
  case attribute
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module Nodes
3
4
  class Count < Arel::Nodes::Function
5
+ include Math
6
+
4
7
  def initialize expr, distinct = false, aliaz = nil
5
8
  super(expr, aliaz)
6
9
  @distinct = distinct
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module Nodes
3
4
  class DeleteStatement < Arel::Nodes::Binary
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Arel
2
3
  module Nodes
3
4
  class Descending < Ordering