arel 6.0.0.beta2 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +1 -1
- data/README.markdown +5 -5
- data/lib/arel.rb +1 -1
- data/lib/arel/collectors/sql_string.rb +7 -1
- data/lib/arel/expressions.rb +5 -4
- data/lib/arel/nodes.rb +1 -0
- data/lib/arel/nodes/bind_param.rb +6 -0
- data/lib/arel/nodes/sql_literal.rb +0 -3
- data/lib/arel/predications.rb +2 -2
- data/lib/arel/visitors/depth_first.rb +6 -0
- data/lib/arel/visitors/oracle.rb +4 -0
- data/lib/arel/visitors/postgresql.rb +4 -0
- data/lib/arel/visitors/reduce.rb +4 -4
- data/lib/arel/visitors/to_sql.rb +3 -2
- data/lib/arel/visitors/visitor.rb +15 -15
- metadata +26 -69
- data/.gitignore +0 -9
- data/.travis.yml +0 -18
- data/Gemfile +0 -5
- data/Rakefile +0 -15
- data/arel.gemspec +0 -24
- data/test/attributes/test_attribute.rb +0 -910
- data/test/collectors/test_bind_collector.rb +0 -70
- data/test/collectors/test_sql_string.rb +0 -38
- data/test/helper.rb +0 -22
- data/test/nodes/test_and.rb +0 -20
- data/test/nodes/test_as.rb +0 -34
- data/test/nodes/test_ascending.rb +0 -44
- data/test/nodes/test_bin.rb +0 -33
- data/test/nodes/test_binary.rb +0 -26
- data/test/nodes/test_count.rb +0 -33
- data/test/nodes/test_delete_statement.rb +0 -34
- data/test/nodes/test_descending.rb +0 -44
- data/test/nodes/test_distinct.rb +0 -20
- data/test/nodes/test_equality.rb +0 -84
- data/test/nodes/test_extract.rb +0 -41
- data/test/nodes/test_false.rb +0 -20
- data/test/nodes/test_grouping.rb +0 -25
- data/test/nodes/test_infix_operation.rb +0 -40
- data/test/nodes/test_insert_statement.rb +0 -42
- data/test/nodes/test_named_function.rb +0 -46
- data/test/nodes/test_node.rb +0 -39
- data/test/nodes/test_not.rb +0 -29
- data/test/nodes/test_or.rb +0 -34
- data/test/nodes/test_over.rb +0 -67
- data/test/nodes/test_select_core.rb +0 -69
- data/test/nodes/test_select_statement.rb +0 -49
- data/test/nodes/test_sql_literal.rb +0 -73
- data/test/nodes/test_sum.rb +0 -24
- data/test/nodes/test_table_alias.rb +0 -36
- data/test/nodes/test_true.rb +0 -21
- data/test/nodes/test_update_statement.rb +0 -58
- data/test/nodes/test_window.rb +0 -79
- data/test/support/fake_record.rb +0 -135
- data/test/test_attributes.rb +0 -66
- data/test/test_crud.rb +0 -63
- data/test/test_delete_manager.rb +0 -42
- data/test/test_factory_methods.rb +0 -44
- data/test/test_insert_manager.rb +0 -171
- data/test/test_select_manager.rb +0 -1181
- data/test/test_table.rb +0 -253
- data/test/test_update_manager.rb +0 -124
- data/test/visitors/test_bind_visitor.rb +0 -60
- data/test/visitors/test_depth_first.rb +0 -258
- data/test/visitors/test_dispatch_contamination.rb +0 -22
- data/test/visitors/test_dot.rb +0 -76
- data/test/visitors/test_ibm_db.rb +0 -33
- data/test/visitors/test_informix.rb +0 -58
- data/test/visitors/test_mssql.rb +0 -70
- data/test/visitors/test_mysql.rb +0 -60
- data/test/visitors/test_oracle.rb +0 -170
- data/test/visitors/test_postgres.rb +0 -122
- data/test/visitors/test_sqlite.rb +0 -23
- data/test/visitors/test_to_sql.rb +0 -598
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 607f322b2e6662d91cbef8d1433904774af2584c
|
4
|
+
data.tar.gz: 7b45ade5c1572eb9b60ec5bc96b90cf307ddd470
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d3471ace631b643c589efca9461e4810a5db0b5f4a4f0126b56cd033c802d75a3cfb5b44771738869582bf651103679e4bfa7b3628328c5493f9992490bf627
|
7
|
+
data.tar.gz: 8e5a1949954982acc175e6bc1f6c3e15070245d5d2643c292ac47fdc56b9cd19a37ac7390ee97c3570dd4269d4b4ae886ee8b35fcdcfc29056b4840bb1ae225b
|
data/History.txt
CHANGED
data/README.markdown
CHANGED
@@ -120,10 +120,10 @@ Aggregate functions `AVG`, `SUM`, `COUNT`, `MIN`, `MAX`, `HAVING`:
|
|
120
120
|
|
121
121
|
```ruby
|
122
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)
|
124
|
-
users.project(users[:age].average) # => SELECT AVG(users.age)
|
125
|
-
users.project(users[:age].maximum) # => SELECT MAX(users.age)
|
126
|
-
users.project(users[:age].minimum) # => SELECT MIN(users.age)
|
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
127
|
users.project(users[:age].count) # => SELECT COUNT(users.age) FROM users
|
128
128
|
```
|
129
129
|
|
@@ -201,7 +201,7 @@ users.
|
|
201
201
|
project(users[:id], cte_table[:click].sum).
|
202
202
|
with(composed_cte)
|
203
203
|
|
204
|
-
# => WITH cte_table AS (SELECT FROM photos WHERE photos.created_at > '2014-05-02') SELECT users.id, SUM(cte_table.click)
|
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
|
205
205
|
```
|
206
206
|
|
207
207
|
When your query is too complex for `Arel`, you can use `Arel::SqlLiteral`:
|
data/lib/arel.rb
CHANGED
@@ -5,8 +5,14 @@ require 'arel/collectors/plain_string'
|
|
5
5
|
module Arel
|
6
6
|
module Collectors
|
7
7
|
class SQLString < PlainString
|
8
|
+
def initialize(*)
|
9
|
+
super
|
10
|
+
@bind_index = 1
|
11
|
+
end
|
12
|
+
|
8
13
|
def add_bind bind
|
9
|
-
self <<
|
14
|
+
self << yield(@bind_index)
|
15
|
+
@bind_index += 1
|
10
16
|
self
|
11
17
|
end
|
12
18
|
|
data/lib/arel/expressions.rb
CHANGED
@@ -5,23 +5,24 @@ module Arel
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def sum
|
8
|
-
Nodes::Sum.new [self]
|
8
|
+
Nodes::Sum.new [self]
|
9
9
|
end
|
10
10
|
|
11
11
|
def maximum
|
12
|
-
Nodes::Max.new [self]
|
12
|
+
Nodes::Max.new [self]
|
13
13
|
end
|
14
14
|
|
15
15
|
def minimum
|
16
|
-
Nodes::Min.new [self]
|
16
|
+
Nodes::Min.new [self]
|
17
17
|
end
|
18
18
|
|
19
19
|
def average
|
20
|
-
Nodes::Avg.new [self]
|
20
|
+
Nodes::Avg.new [self]
|
21
21
|
end
|
22
22
|
|
23
23
|
def extract field
|
24
24
|
Nodes::Extract.new [self], field
|
25
25
|
end
|
26
|
+
|
26
27
|
end
|
27
28
|
end
|
data/lib/arel/nodes.rb
CHANGED
data/lib/arel/predications.rb
CHANGED
@@ -55,7 +55,7 @@ Passing a range to `#in` is deprecated. Call `#between`, instead.
|
|
55
55
|
eowarn
|
56
56
|
end
|
57
57
|
between(other)
|
58
|
-
when
|
58
|
+
when Enumerable
|
59
59
|
Nodes::In.new self, quoted_array(other)
|
60
60
|
else
|
61
61
|
Nodes::In.new self, quoted_node(other)
|
@@ -103,7 +103,7 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
|
|
103
103
|
eowarn
|
104
104
|
end
|
105
105
|
not_between(other)
|
106
|
-
when
|
106
|
+
when Enumerable
|
107
107
|
Nodes::NotIn.new self, quoted_array(other)
|
108
108
|
else
|
109
109
|
Nodes::NotIn.new self, quoted_node(other)
|
data/lib/arel/visitors/oracle.rb
CHANGED
data/lib/arel/visitors/reduce.rb
CHANGED
@@ -10,14 +10,14 @@ module Arel
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def visit object, collector
|
13
|
-
send dispatch[object.class
|
13
|
+
send dispatch[object.class], object, collector
|
14
14
|
rescue NoMethodError => e
|
15
|
-
raise e if respond_to?(dispatch[object.class
|
15
|
+
raise e if respond_to?(dispatch[object.class], true)
|
16
16
|
superklass = object.class.ancestors.find { |klass|
|
17
|
-
respond_to?(dispatch[klass
|
17
|
+
respond_to?(dispatch[klass], true)
|
18
18
|
}
|
19
19
|
raise(TypeError, "Cannot visit #{object.class}") unless superklass
|
20
|
-
dispatch[object.class
|
20
|
+
dispatch[object.class] = dispatch[superklass]
|
21
21
|
retry
|
22
22
|
end
|
23
23
|
end
|
data/lib/arel/visitors/to_sql.rb
CHANGED
@@ -186,7 +186,8 @@ module Arel
|
|
186
186
|
|
187
187
|
len = o.expressions.length - 1
|
188
188
|
o.expressions.zip(o.columns).each_with_index { |(value, attr), i|
|
189
|
-
|
189
|
+
case value
|
190
|
+
when Nodes::SqlLiteral, Nodes::BindParam
|
190
191
|
collector = visit value, collector
|
191
192
|
else
|
192
193
|
collector << quote(value, attr && column_for(attr)).to_s
|
@@ -713,7 +714,7 @@ module Arel
|
|
713
714
|
def literal o, collector; collector << o.to_s; end
|
714
715
|
|
715
716
|
def visit_Arel_Nodes_BindParam o, collector
|
716
|
-
collector.add_bind
|
717
|
+
collector.add_bind(o) { "?" }
|
717
718
|
end
|
718
719
|
|
719
720
|
alias :visit_Arel_Nodes_SqlLiteral :literal
|
@@ -2,17 +2,7 @@ module Arel
|
|
2
2
|
module Visitors
|
3
3
|
class Visitor
|
4
4
|
def initialize
|
5
|
-
@dispatch =
|
6
|
-
raise if class_name == 'Arel::Nodes::Union'
|
7
|
-
hash[class_name] = "visit_#{(class_name || '').gsub('::', '_')}"
|
8
|
-
end
|
9
|
-
|
10
|
-
# pre-populate cache. FIXME: this should be passed in to each
|
11
|
-
# instance, but we can do that later.
|
12
|
-
self.class.private_instance_methods.sort.each do |name|
|
13
|
-
next unless name =~ /^visit_(.*)$/
|
14
|
-
@dispatch[$1.gsub('_', '::')] = name
|
15
|
-
end
|
5
|
+
@dispatch = get_dispatch_cache
|
16
6
|
end
|
17
7
|
|
18
8
|
def accept object
|
@@ -21,19 +11,29 @@ module Arel
|
|
21
11
|
|
22
12
|
private
|
23
13
|
|
14
|
+
def self.dispatch_cache
|
15
|
+
Hash.new do |hash, klass|
|
16
|
+
hash[klass] = "visit_#{(klass.name || '').gsub('::', '_')}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_dispatch_cache
|
21
|
+
self.class.dispatch_cache
|
22
|
+
end
|
23
|
+
|
24
24
|
def dispatch
|
25
25
|
@dispatch
|
26
26
|
end
|
27
27
|
|
28
28
|
def visit object
|
29
|
-
send dispatch[object.class
|
29
|
+
send dispatch[object.class], object
|
30
30
|
rescue NoMethodError => e
|
31
|
-
raise e if respond_to?(dispatch[object.class
|
31
|
+
raise e if respond_to?(dispatch[object.class], true)
|
32
32
|
superklass = object.class.ancestors.find { |klass|
|
33
|
-
respond_to?(dispatch[klass
|
33
|
+
respond_to?(dispatch[klass], true)
|
34
34
|
}
|
35
35
|
raise(TypeError, "Cannot visit #{object.class}") unless superklass
|
36
|
-
dispatch[object.class
|
36
|
+
dispatch[object.class] = dispatch[superklass]
|
37
37
|
retry
|
38
38
|
end
|
39
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.0
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Patterson
|
@@ -11,36 +11,50 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-
|
14
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: minitest
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
20
|
-
- - ~>
|
20
|
+
- - "~>"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '5.4'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - ~>
|
27
|
+
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '5.4'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rdoc
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
|
-
- - ~>
|
34
|
+
- - "~>"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '4.0'
|
37
37
|
type: :development
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- - ~>
|
41
|
+
- - "~>"
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '4.0'
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: rake
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
44
58
|
description: |-
|
45
59
|
Arel Really Exasperates Logicians
|
46
60
|
|
@@ -63,14 +77,9 @@ extra_rdoc_files:
|
|
63
77
|
- MIT-LICENSE.txt
|
64
78
|
- README.markdown
|
65
79
|
files:
|
66
|
-
- .gitignore
|
67
|
-
- .travis.yml
|
68
|
-
- Gemfile
|
69
80
|
- History.txt
|
70
81
|
- MIT-LICENSE.txt
|
71
82
|
- README.markdown
|
72
|
-
- Rakefile
|
73
|
-
- arel.gemspec
|
74
83
|
- lib/arel.rb
|
75
84
|
- lib/arel/alias_predication.rb
|
76
85
|
- lib/arel/attributes.rb
|
@@ -89,6 +98,7 @@ files:
|
|
89
98
|
- lib/arel/nodes/and.rb
|
90
99
|
- lib/arel/nodes/ascending.rb
|
91
100
|
- lib/arel/nodes/binary.rb
|
101
|
+
- lib/arel/nodes/bind_param.rb
|
92
102
|
- lib/arel/nodes/count.rb
|
93
103
|
- lib/arel/nodes/delete_statement.rb
|
94
104
|
- lib/arel/nodes/descending.rb
|
@@ -145,82 +155,29 @@ files:
|
|
145
155
|
- lib/arel/visitors/visitor.rb
|
146
156
|
- lib/arel/visitors/where_sql.rb
|
147
157
|
- lib/arel/window_predications.rb
|
148
|
-
- test/attributes/test_attribute.rb
|
149
|
-
- test/collectors/test_bind_collector.rb
|
150
|
-
- test/collectors/test_sql_string.rb
|
151
|
-
- test/helper.rb
|
152
|
-
- test/nodes/test_and.rb
|
153
|
-
- test/nodes/test_as.rb
|
154
|
-
- test/nodes/test_ascending.rb
|
155
|
-
- test/nodes/test_bin.rb
|
156
|
-
- test/nodes/test_binary.rb
|
157
|
-
- test/nodes/test_count.rb
|
158
|
-
- test/nodes/test_delete_statement.rb
|
159
|
-
- test/nodes/test_descending.rb
|
160
|
-
- test/nodes/test_distinct.rb
|
161
|
-
- test/nodes/test_equality.rb
|
162
|
-
- test/nodes/test_extract.rb
|
163
|
-
- test/nodes/test_false.rb
|
164
|
-
- test/nodes/test_grouping.rb
|
165
|
-
- test/nodes/test_infix_operation.rb
|
166
|
-
- test/nodes/test_insert_statement.rb
|
167
|
-
- test/nodes/test_named_function.rb
|
168
|
-
- test/nodes/test_node.rb
|
169
|
-
- test/nodes/test_not.rb
|
170
|
-
- test/nodes/test_or.rb
|
171
|
-
- test/nodes/test_over.rb
|
172
|
-
- test/nodes/test_select_core.rb
|
173
|
-
- test/nodes/test_select_statement.rb
|
174
|
-
- test/nodes/test_sql_literal.rb
|
175
|
-
- test/nodes/test_sum.rb
|
176
|
-
- test/nodes/test_table_alias.rb
|
177
|
-
- test/nodes/test_true.rb
|
178
|
-
- test/nodes/test_update_statement.rb
|
179
|
-
- test/nodes/test_window.rb
|
180
|
-
- test/support/fake_record.rb
|
181
|
-
- test/test_attributes.rb
|
182
|
-
- test/test_crud.rb
|
183
|
-
- test/test_delete_manager.rb
|
184
|
-
- test/test_factory_methods.rb
|
185
|
-
- test/test_insert_manager.rb
|
186
|
-
- test/test_select_manager.rb
|
187
|
-
- test/test_table.rb
|
188
|
-
- test/test_update_manager.rb
|
189
|
-
- test/visitors/test_bind_visitor.rb
|
190
|
-
- test/visitors/test_depth_first.rb
|
191
|
-
- test/visitors/test_dispatch_contamination.rb
|
192
|
-
- test/visitors/test_dot.rb
|
193
|
-
- test/visitors/test_ibm_db.rb
|
194
|
-
- test/visitors/test_informix.rb
|
195
|
-
- test/visitors/test_mssql.rb
|
196
|
-
- test/visitors/test_mysql.rb
|
197
|
-
- test/visitors/test_oracle.rb
|
198
|
-
- test/visitors/test_postgres.rb
|
199
|
-
- test/visitors/test_sqlite.rb
|
200
|
-
- test/visitors/test_to_sql.rb
|
201
158
|
homepage: https://github.com/rails/arel
|
202
159
|
licenses:
|
203
160
|
- MIT
|
204
161
|
metadata: {}
|
205
162
|
post_install_message:
|
206
163
|
rdoc_options:
|
207
|
-
- --main
|
164
|
+
- "--main"
|
208
165
|
- README.markdown
|
209
166
|
require_paths:
|
210
167
|
- lib
|
211
168
|
required_ruby_version: !ruby/object:Gem::Requirement
|
212
169
|
requirements:
|
213
|
-
- -
|
170
|
+
- - ">="
|
214
171
|
- !ruby/object:Gem::Version
|
215
172
|
version: '0'
|
216
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
217
174
|
requirements:
|
218
|
-
- -
|
175
|
+
- - ">="
|
219
176
|
- !ruby/object:Gem::Version
|
220
|
-
version:
|
177
|
+
version: '0'
|
221
178
|
requirements: []
|
222
179
|
rubyforge_project:
|
223
|
-
rubygems_version: 2.2.
|
180
|
+
rubygems_version: 2.2.2
|
224
181
|
signing_key:
|
225
182
|
specification_version: 4
|
226
183
|
summary: Arel Really Exasperates Logicians Arel is a SQL AST manager for Ruby
|