arel 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.txt +15 -3
- data/Manifest.txt +1 -0
- data/README.markdown +71 -34
- data/Rakefile +1 -0
- data/arel.gemspec +16 -15
- data/lib/arel.rb +1 -1
- data/lib/arel/nodes/and.rb +1 -0
- data/lib/arel/nodes/binary.rb +1 -0
- data/lib/arel/nodes/function.rb +1 -0
- data/lib/arel/nodes/insert_statement.rb +1 -0
- data/lib/arel/nodes/node.rb +10 -0
- data/lib/arel/nodes/select_core.rb +1 -0
- data/lib/arel/nodes/select_statement.rb +1 -0
- data/lib/arel/nodes/unary.rb +1 -0
- data/lib/arel/table.rb +4 -1
- data/lib/arel/visitors/bind_visitor.rb +4 -4
- data/lib/arel/visitors/depth_first.rb +56 -56
- data/lib/arel/visitors/dot.rb +75 -75
- data/lib/arel/visitors/ibm_db.rb +2 -2
- data/lib/arel/visitors/informix.rb +17 -17
- data/lib/arel/visitors/join_sql.rb +2 -2
- data/lib/arel/visitors/mssql.rb +12 -12
- data/lib/arel/visitors/mysql.rb +15 -15
- data/lib/arel/visitors/oracle.rb +19 -19
- data/lib/arel/visitors/order_clauses.rb +2 -2
- data/lib/arel/visitors/postgresql.rb +6 -6
- data/lib/arel/visitors/sqlite.rb +2 -2
- data/lib/arel/visitors/to_sql.rb +172 -168
- data/lib/arel/visitors/visitor.rb +8 -5
- data/lib/arel/visitors/where_sql.rb +2 -2
- data/test/test_update_manager.rb +1 -0
- data/test/visitors/test_dispatch_contamination.rb +22 -0
- data/test/visitors/test_oracle.rb +2 -1
- data/test/visitors/test_to_sql.rb +1 -1
- metadata +18 -27
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 43df8ad0c214e6f273a245b06ad740700735eadb
|
4
|
+
data.tar.gz: 15084841b2ad5743e4d81722bebbff6bc7471a2f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8c37e0d0b37551a9b27cbce6d7c3b7509bdbb98847175446a57fae35198ab9c996153baed4f9d3f7c7df018d4efa0830c9c150fc9f413a59087aa73cb09eebe
|
7
|
+
data.tar.gz: 439ace13cbdee92401d629c1874a82d9355c2a53a9fbc6b8b086a2fa1fac5a59fa9a6feb47163014bc452358154ded999b36fd2991a870c5557f5ea7ebe6fa3e
|
data/History.txt
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
== 4.0.1 / 2013-10-22
|
2
|
+
|
3
|
+
* Enhancements
|
4
|
+
|
5
|
+
* Cache visitor dispatch on a per-visitor basis
|
6
|
+
* Improve performance of #uniq across a large number of nodes
|
7
|
+
|
8
|
+
* Bug Fixes
|
9
|
+
|
10
|
+
* Make visitors threadsafe by removing @last_column
|
11
|
+
* Support `columns_for_distinct` with Oracle adapter
|
12
|
+
|
1
13
|
== 2.2.1 / 2011-09-15
|
2
14
|
|
3
15
|
* Enhancements
|
@@ -19,11 +31,11 @@
|
|
19
31
|
* Bug Fixes
|
20
32
|
|
21
33
|
* Fix depth-first traversal to understand ascending / descending nodes.
|
22
|
-
*
|
34
|
+
* Parenthesis are suppressed with nested unions in MySQL. Thanks jhtwong!
|
23
35
|
|
24
36
|
== 2.1.3 / 2011-06-27
|
25
37
|
|
26
|
-
* Bug
|
38
|
+
* Bug Fixes
|
27
39
|
|
28
40
|
* Fixed broken gem build.
|
29
41
|
|
@@ -31,7 +43,7 @@
|
|
31
43
|
|
32
44
|
* Bug Fixes
|
33
45
|
|
34
|
-
* Visitors can define their own cache
|
46
|
+
* Visitors can define their own cache strategy so caches are not shared.
|
35
47
|
Fixes #57
|
36
48
|
* Informix support fixed. Thanks Khronos.
|
37
49
|
* Ordering nodes broken to subclasses. Thanks Ernie Miller!
|
data/Manifest.txt
CHANGED
@@ -121,6 +121,7 @@ test/test_table.rb
|
|
121
121
|
test/test_update_manager.rb
|
122
122
|
test/visitors/test_bind_visitor.rb
|
123
123
|
test/visitors/test_depth_first.rb
|
124
|
+
test/visitors/test_dispatch_contamination.rb
|
124
125
|
test/visitors/test_dot.rb
|
125
126
|
test/visitors/test_ibm_db.rb
|
126
127
|
test/visitors/test_informix.rb
|
data/README.markdown
CHANGED
@@ -21,13 +21,17 @@ For the moment, Arel uses Active Record's connection adapters to connect to the
|
|
21
21
|
|
22
22
|
Generating a query with Arel is simple. For example, in order to produce
|
23
23
|
|
24
|
-
|
24
|
+
```sql
|
25
|
+
SELECT * FROM users
|
26
|
+
```
|
25
27
|
|
26
28
|
you construct a table relation and convert it to sql:
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
```ruby
|
31
|
+
users = Arel::Table.new(:users)
|
32
|
+
query = users.project(Arel.sql('*'))
|
33
|
+
query.to_sql
|
34
|
+
```
|
31
35
|
|
32
36
|
### More Sophisticated Queries
|
33
37
|
|
@@ -35,45 +39,65 @@ Here is a whirlwind tour through the most common relational operators. These wil
|
|
35
39
|
|
36
40
|
First is the 'restriction' operator, `where`:
|
37
41
|
|
38
|
-
|
39
|
-
|
42
|
+
```ruby
|
43
|
+
users.where(users[:name].eq('amy'))
|
44
|
+
# => SELECT * FROM users WHERE users.name = 'amy'
|
45
|
+
```
|
40
46
|
|
41
47
|
What would, in SQL, be part of the `SELECT` clause is called in Arel a `projection`:
|
42
48
|
|
43
|
-
|
49
|
+
```ruby
|
50
|
+
users.project(users[:id])
|
51
|
+
# => SELECT users.id FROM users
|
52
|
+
```
|
44
53
|
|
45
54
|
Joins resemble SQL strongly:
|
46
55
|
|
47
|
-
|
48
|
-
|
56
|
+
```ruby
|
57
|
+
users.join(photos).on(users[:id].eq(photos[:user_id]))
|
58
|
+
# => SELECT * FROM users INNER JOIN photos ON users.id = photos.user_id
|
59
|
+
```
|
49
60
|
|
50
61
|
What are called `LIMIT` and `OFFSET` in SQL are called `take` and `skip` in Arel:
|
51
62
|
|
52
|
-
|
53
|
-
|
63
|
+
```ruby
|
64
|
+
users.take(5) # => SELECT * FROM users LIMIT 5
|
65
|
+
users.skip(4) # => SELECT * FROM users OFFSET 4
|
66
|
+
```
|
54
67
|
|
55
68
|
`GROUP BY` is called `group`:
|
56
69
|
|
57
|
-
|
70
|
+
```ruby
|
71
|
+
users.project(users[:name]).group(users[:name])
|
72
|
+
# => SELECT users.name FROM users GROUP BY users.name
|
73
|
+
```
|
58
74
|
|
59
75
|
The best property of the Relational Algebra is its "composability", or closure under all operations. For example, to restrict AND project, just "chain" the method invocations:
|
60
76
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
77
|
+
```ruby
|
78
|
+
users \
|
79
|
+
.where(users[:name].eq('amy')) \
|
80
|
+
.project(users[:id]) \
|
81
|
+
# => SELECT users.id FROM users WHERE users.name = 'amy'
|
82
|
+
```
|
65
83
|
|
66
84
|
All operators are chainable in this way, and they are chainable any number of times, in any order.
|
67
85
|
|
68
|
-
|
86
|
+
```ruby
|
87
|
+
users.where(users[:name].eq('bob')).where(users[:age].lt(25))
|
88
|
+
```
|
69
89
|
|
70
90
|
Of course, many of the operators take multiple arguments, so the last example can be written more tersely:
|
71
91
|
|
72
|
-
|
92
|
+
```ruby
|
93
|
+
users.where(users[:name].eq('bob'), users[:age].lt(25))
|
94
|
+
```
|
73
95
|
|
74
96
|
The `OR` operator works like this:
|
75
97
|
|
76
|
-
|
98
|
+
```ruby
|
99
|
+
users.where(users[:name].eq('bob').or(users[:age].lt(25)))
|
100
|
+
```
|
77
101
|
|
78
102
|
The `AND` operator behaves similarly.
|
79
103
|
|
@@ -85,38 +109,51 @@ The examples above are fairly simple and other libraries match or come close to
|
|
85
109
|
|
86
110
|
Suppose we have a table `products` with prices in different currencies. And we have a table `currency_rates`, of constantly changing currency rates. In Arel:
|
87
111
|
|
88
|
-
|
89
|
-
|
112
|
+
```ruby
|
113
|
+
products = Arel::Table.new(:products)
|
114
|
+
products.columns
|
115
|
+
# => [products[:id], products[:name], products[:price], products[:currency_id]]
|
90
116
|
|
91
|
-
|
92
|
-
|
117
|
+
currency_rates = Arel::Table.new(:currency_rates)
|
118
|
+
currency_rates.columns
|
119
|
+
# => [currency_rates[:from_id], currency_rates[:to_id], currency_rates[:date], currency_rates[:rate]]
|
120
|
+
```
|
93
121
|
|
94
122
|
Now, to order products by price in user preferred currency simply call:
|
95
123
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
124
|
+
```ruby
|
125
|
+
products.
|
126
|
+
join(:currency_rates).on(products[:currency_id].eq(currency_rates[:from_id])).
|
127
|
+
where(currency_rates[:to_id].eq(user_preferred_currency), currency_rates[:date].eq(Date.today)).
|
128
|
+
order(products[:price] * currency_rates[:rate])
|
129
|
+
```
|
100
130
|
|
101
131
|
#### Complex Joins
|
102
132
|
|
103
133
|
Where Arel really shines 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:
|
104
134
|
|
105
|
-
|
135
|
+
```ruby
|
136
|
+
comments = Arel::Table.new(:comments)
|
137
|
+
```
|
106
138
|
|
107
139
|
And this table has the following attributes:
|
108
140
|
|
109
|
-
|
141
|
+
```ruby
|
142
|
+
comments.columns
|
143
|
+
# => [comments[:id], comments[:body], comments[:parent_id]]
|
144
|
+
```
|
110
145
|
|
111
146
|
The `parent_id` column is a foreign key from the `comments` table to itself. Now, joining a table to itself requires aliasing in SQL. In fact, you may alias in Arel as well:
|
112
147
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
148
|
+
```ruby
|
149
|
+
replies = comments.alias
|
150
|
+
comments_with_replies = \
|
151
|
+
comments.join(replies).on(replies[:parent_id].eq(comments[:id]))
|
152
|
+
# => SELECT * FROM comments INNER JOIN comments AS comments_2 WHERE comments_2.parent_id = comments.id
|
153
|
+
```
|
117
154
|
|
118
155
|
This will return the first comment's reply's body.
|
119
156
|
|
120
157
|
### License
|
121
|
-
|
158
|
+
|
122
159
|
Arel is released under the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -14,6 +14,7 @@ Hoe.spec 'arel' do
|
|
14
14
|
developer('Emilio Tagua', 'miloops@gmail.com')
|
15
15
|
developer('Nick Kallen', 'nick@example.org') # FIXME: need Nick's email
|
16
16
|
|
17
|
+
self.licenses = ['MIT']
|
17
18
|
self.readme_file = 'README.markdown'
|
18
19
|
self.extra_rdoc_files = FileList['README.markdown']
|
19
20
|
end
|
data/arel.gemspec
CHANGED
@@ -2,38 +2,39 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "arel"
|
5
|
-
s.version = "4.0.
|
5
|
+
s.version = "4.0.1.20131022201058"
|
6
6
|
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Aaron Patterson", "Bryan Halmkamp", "Emilio Tagua", "Nick Kallen"]
|
9
|
-
s.date = "2013-
|
9
|
+
s.date = "2013-10-22"
|
10
10
|
s.description = "Arel is a SQL AST manager for Ruby. It\n\n1. Simplifies the generation of complex SQL queries\n2. Adapts to various RDBMS systems\n\nIt is intended to be a framework framework; that is, you can build your own ORM\nwith it, focusing on innovative object and collection modeling as opposed to\ndatabase compatibility and query generation."
|
11
11
|
s.email = ["aaron@tenderlovemaking.com", "bryan@brynary.com", "miloops@gmail.com", "nick@example.org"]
|
12
12
|
s.extra_rdoc_files = ["History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown"]
|
13
|
-
s.files = [".autotest", ".gemtest", ".travis.yml", "Gemfile", "History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown", "Rakefile", "arel.gemspec", "lib/arel.rb", "lib/arel/alias_predication.rb", "lib/arel/attributes.rb", "lib/arel/attributes/attribute.rb", "lib/arel/compatibility/wheres.rb", "lib/arel/crud.rb", "lib/arel/delete_manager.rb", "lib/arel/deprecated.rb", "lib/arel/expression.rb", "lib/arel/expressions.rb", "lib/arel/factory_methods.rb", "lib/arel/insert_manager.rb", "lib/arel/math.rb", "lib/arel/nodes.rb", "lib/arel/nodes/and.rb", "lib/arel/nodes/ascending.rb", "lib/arel/nodes/binary.rb", "lib/arel/nodes/count.rb", "lib/arel/nodes/delete_statement.rb", "lib/arel/nodes/descending.rb", "lib/arel/nodes/equality.rb", "lib/arel/nodes/extract.rb", "lib/arel/nodes/false.rb", "lib/arel/nodes/function.rb", "lib/arel/nodes/grouping.rb", "lib/arel/nodes/in.rb", "lib/arel/nodes/infix_operation.rb", "lib/arel/nodes/inner_join.rb", "lib/arel/nodes/insert_statement.rb", "lib/arel/nodes/join_source.rb", "lib/arel/nodes/named_function.rb", "lib/arel/nodes/node.rb", "lib/arel/nodes/outer_join.rb", "lib/arel/nodes/over.rb", "lib/arel/nodes/select_core.rb", "lib/arel/nodes/select_statement.rb", "lib/arel/nodes/sql_literal.rb", "lib/arel/nodes/string_join.rb", "lib/arel/nodes/table_alias.rb", "lib/arel/nodes/terminal.rb", "lib/arel/nodes/true.rb", "lib/arel/nodes/unary.rb", "lib/arel/nodes/unqualified_column.rb", "lib/arel/nodes/update_statement.rb", "lib/arel/nodes/values.rb", "lib/arel/nodes/window.rb", "lib/arel/nodes/with.rb", "lib/arel/order_predications.rb", "lib/arel/predications.rb", "lib/arel/select_manager.rb", "lib/arel/sql/engine.rb", "lib/arel/sql_literal.rb", "lib/arel/table.rb", "lib/arel/tree_manager.rb", "lib/arel/update_manager.rb", "lib/arel/visitors.rb", "lib/arel/visitors/bind_visitor.rb", "lib/arel/visitors/depth_first.rb", "lib/arel/visitors/dot.rb", "lib/arel/visitors/ibm_db.rb", "lib/arel/visitors/informix.rb", "lib/arel/visitors/join_sql.rb", "lib/arel/visitors/mssql.rb", "lib/arel/visitors/mysql.rb", "lib/arel/visitors/oracle.rb", "lib/arel/visitors/order_clauses.rb", "lib/arel/visitors/postgresql.rb", "lib/arel/visitors/sqlite.rb", "lib/arel/visitors/to_sql.rb", "lib/arel/visitors/visitor.rb", "lib/arel/visitors/where_sql.rb", "lib/arel/window_predications.rb", "test/attributes/test_attribute.rb", "test/helper.rb", "test/nodes/test_and.rb", "test/nodes/test_as.rb", "test/nodes/test_ascending.rb", "test/nodes/test_bin.rb", "test/nodes/test_count.rb", "test/nodes/test_delete_statement.rb", "test/nodes/test_descending.rb", "test/nodes/test_distinct.rb", "test/nodes/test_equality.rb", "test/nodes/test_extract.rb", "test/nodes/test_false.rb", "test/nodes/test_grouping.rb", "test/nodes/test_infix_operation.rb", "test/nodes/test_insert_statement.rb", "test/nodes/test_named_function.rb", "test/nodes/test_node.rb", "test/nodes/test_not.rb", "test/nodes/test_or.rb", "test/nodes/test_over.rb", "test/nodes/test_select_core.rb", "test/nodes/test_select_statement.rb", "test/nodes/test_sql_literal.rb", "test/nodes/test_sum.rb", "test/nodes/test_table_alias.rb", "test/nodes/test_true.rb", "test/nodes/test_update_statement.rb", "test/nodes/test_window.rb", "test/support/fake_record.rb", "test/test_activerecord_compat.rb", "test/test_attributes.rb", "test/test_crud.rb", "test/test_delete_manager.rb", "test/test_factory_methods.rb", "test/test_insert_manager.rb", "test/test_select_manager.rb", "test/test_table.rb", "test/test_update_manager.rb", "test/visitors/test_bind_visitor.rb", "test/visitors/test_depth_first.rb", "test/visitors/test_dot.rb", "test/visitors/test_ibm_db.rb", "test/visitors/test_informix.rb", "test/visitors/test_join_sql.rb", "test/visitors/test_mssql.rb", "test/visitors/test_mysql.rb", "test/visitors/test_oracle.rb", "test/visitors/test_postgres.rb", "test/visitors/test_sqlite.rb", "test/visitors/test_to_sql.rb"]
|
13
|
+
s.files = [".autotest", ".gemtest", ".travis.yml", "Gemfile", "History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown", "Rakefile", "arel.gemspec", "lib/arel.rb", "lib/arel/alias_predication.rb", "lib/arel/attributes.rb", "lib/arel/attributes/attribute.rb", "lib/arel/compatibility/wheres.rb", "lib/arel/crud.rb", "lib/arel/delete_manager.rb", "lib/arel/deprecated.rb", "lib/arel/expression.rb", "lib/arel/expressions.rb", "lib/arel/factory_methods.rb", "lib/arel/insert_manager.rb", "lib/arel/math.rb", "lib/arel/nodes.rb", "lib/arel/nodes/and.rb", "lib/arel/nodes/ascending.rb", "lib/arel/nodes/binary.rb", "lib/arel/nodes/count.rb", "lib/arel/nodes/delete_statement.rb", "lib/arel/nodes/descending.rb", "lib/arel/nodes/equality.rb", "lib/arel/nodes/extract.rb", "lib/arel/nodes/false.rb", "lib/arel/nodes/function.rb", "lib/arel/nodes/grouping.rb", "lib/arel/nodes/in.rb", "lib/arel/nodes/infix_operation.rb", "lib/arel/nodes/inner_join.rb", "lib/arel/nodes/insert_statement.rb", "lib/arel/nodes/join_source.rb", "lib/arel/nodes/named_function.rb", "lib/arel/nodes/node.rb", "lib/arel/nodes/outer_join.rb", "lib/arel/nodes/over.rb", "lib/arel/nodes/select_core.rb", "lib/arel/nodes/select_statement.rb", "lib/arel/nodes/sql_literal.rb", "lib/arel/nodes/string_join.rb", "lib/arel/nodes/table_alias.rb", "lib/arel/nodes/terminal.rb", "lib/arel/nodes/true.rb", "lib/arel/nodes/unary.rb", "lib/arel/nodes/unqualified_column.rb", "lib/arel/nodes/update_statement.rb", "lib/arel/nodes/values.rb", "lib/arel/nodes/window.rb", "lib/arel/nodes/with.rb", "lib/arel/order_predications.rb", "lib/arel/predications.rb", "lib/arel/select_manager.rb", "lib/arel/sql/engine.rb", "lib/arel/sql_literal.rb", "lib/arel/table.rb", "lib/arel/tree_manager.rb", "lib/arel/update_manager.rb", "lib/arel/visitors.rb", "lib/arel/visitors/bind_visitor.rb", "lib/arel/visitors/depth_first.rb", "lib/arel/visitors/dot.rb", "lib/arel/visitors/ibm_db.rb", "lib/arel/visitors/informix.rb", "lib/arel/visitors/join_sql.rb", "lib/arel/visitors/mssql.rb", "lib/arel/visitors/mysql.rb", "lib/arel/visitors/oracle.rb", "lib/arel/visitors/order_clauses.rb", "lib/arel/visitors/postgresql.rb", "lib/arel/visitors/sqlite.rb", "lib/arel/visitors/to_sql.rb", "lib/arel/visitors/visitor.rb", "lib/arel/visitors/where_sql.rb", "lib/arel/window_predications.rb", "test/attributes/test_attribute.rb", "test/helper.rb", "test/nodes/test_and.rb", "test/nodes/test_as.rb", "test/nodes/test_ascending.rb", "test/nodes/test_bin.rb", "test/nodes/test_count.rb", "test/nodes/test_delete_statement.rb", "test/nodes/test_descending.rb", "test/nodes/test_distinct.rb", "test/nodes/test_equality.rb", "test/nodes/test_extract.rb", "test/nodes/test_false.rb", "test/nodes/test_grouping.rb", "test/nodes/test_infix_operation.rb", "test/nodes/test_insert_statement.rb", "test/nodes/test_named_function.rb", "test/nodes/test_node.rb", "test/nodes/test_not.rb", "test/nodes/test_or.rb", "test/nodes/test_over.rb", "test/nodes/test_select_core.rb", "test/nodes/test_select_statement.rb", "test/nodes/test_sql_literal.rb", "test/nodes/test_sum.rb", "test/nodes/test_table_alias.rb", "test/nodes/test_true.rb", "test/nodes/test_update_statement.rb", "test/nodes/test_window.rb", "test/support/fake_record.rb", "test/test_activerecord_compat.rb", "test/test_attributes.rb", "test/test_crud.rb", "test/test_delete_manager.rb", "test/test_factory_methods.rb", "test/test_insert_manager.rb", "test/test_select_manager.rb", "test/test_table.rb", "test/test_update_manager.rb", "test/visitors/test_bind_visitor.rb", "test/visitors/test_depth_first.rb", "test/visitors/test_dispatch_contamination.rb", "test/visitors/test_dot.rb", "test/visitors/test_ibm_db.rb", "test/visitors/test_informix.rb", "test/visitors/test_join_sql.rb", "test/visitors/test_mssql.rb", "test/visitors/test_mysql.rb", "test/visitors/test_oracle.rb", "test/visitors/test_postgres.rb", "test/visitors/test_sqlite.rb", "test/visitors/test_to_sql.rb"]
|
14
14
|
s.homepage = "http://github.com/rails/arel"
|
15
|
+
s.licenses = ["MIT"]
|
15
16
|
s.rdoc_options = ["--main", "README.markdown"]
|
16
17
|
s.require_paths = ["lib"]
|
17
18
|
s.rubyforge_project = "arel"
|
18
|
-
s.rubygems_version = "2.0.
|
19
|
+
s.rubygems_version = "2.0.6"
|
19
20
|
s.summary = "Arel is a SQL AST manager for Ruby"
|
20
|
-
s.test_files = ["test/attributes/test_attribute.rb", "test/nodes/test_and.rb", "test/nodes/test_as.rb", "test/nodes/test_ascending.rb", "test/nodes/test_bin.rb", "test/nodes/test_count.rb", "test/nodes/test_delete_statement.rb", "test/nodes/test_descending.rb", "test/nodes/test_distinct.rb", "test/nodes/test_equality.rb", "test/nodes/test_extract.rb", "test/nodes/test_false.rb", "test/nodes/test_grouping.rb", "test/nodes/test_infix_operation.rb", "test/nodes/test_insert_statement.rb", "test/nodes/test_named_function.rb", "test/nodes/test_node.rb", "test/nodes/test_not.rb", "test/nodes/test_or.rb", "test/nodes/test_over.rb", "test/nodes/test_select_core.rb", "test/nodes/test_select_statement.rb", "test/nodes/test_sql_literal.rb", "test/nodes/test_sum.rb", "test/nodes/test_table_alias.rb", "test/nodes/test_true.rb", "test/nodes/test_update_statement.rb", "test/nodes/test_window.rb", "test/test_activerecord_compat.rb", "test/test_attributes.rb", "test/test_crud.rb", "test/test_delete_manager.rb", "test/test_factory_methods.rb", "test/test_insert_manager.rb", "test/test_select_manager.rb", "test/test_table.rb", "test/test_update_manager.rb", "test/visitors/test_bind_visitor.rb", "test/visitors/test_depth_first.rb", "test/visitors/test_dot.rb", "test/visitors/test_ibm_db.rb", "test/visitors/test_informix.rb", "test/visitors/test_join_sql.rb", "test/visitors/test_mssql.rb", "test/visitors/test_mysql.rb", "test/visitors/test_oracle.rb", "test/visitors/test_postgres.rb", "test/visitors/test_sqlite.rb", "test/visitors/test_to_sql.rb"]
|
21
|
+
s.test_files = ["test/attributes/test_attribute.rb", "test/nodes/test_and.rb", "test/nodes/test_as.rb", "test/nodes/test_ascending.rb", "test/nodes/test_bin.rb", "test/nodes/test_count.rb", "test/nodes/test_delete_statement.rb", "test/nodes/test_descending.rb", "test/nodes/test_distinct.rb", "test/nodes/test_equality.rb", "test/nodes/test_extract.rb", "test/nodes/test_false.rb", "test/nodes/test_grouping.rb", "test/nodes/test_infix_operation.rb", "test/nodes/test_insert_statement.rb", "test/nodes/test_named_function.rb", "test/nodes/test_node.rb", "test/nodes/test_not.rb", "test/nodes/test_or.rb", "test/nodes/test_over.rb", "test/nodes/test_select_core.rb", "test/nodes/test_select_statement.rb", "test/nodes/test_sql_literal.rb", "test/nodes/test_sum.rb", "test/nodes/test_table_alias.rb", "test/nodes/test_true.rb", "test/nodes/test_update_statement.rb", "test/nodes/test_window.rb", "test/test_activerecord_compat.rb", "test/test_attributes.rb", "test/test_crud.rb", "test/test_delete_manager.rb", "test/test_factory_methods.rb", "test/test_insert_manager.rb", "test/test_select_manager.rb", "test/test_table.rb", "test/test_update_manager.rb", "test/visitors/test_bind_visitor.rb", "test/visitors/test_depth_first.rb", "test/visitors/test_dispatch_contamination.rb", "test/visitors/test_dot.rb", "test/visitors/test_ibm_db.rb", "test/visitors/test_informix.rb", "test/visitors/test_join_sql.rb", "test/visitors/test_mssql.rb", "test/visitors/test_mysql.rb", "test/visitors/test_oracle.rb", "test/visitors/test_postgres.rb", "test/visitors/test_sqlite.rb", "test/visitors/test_to_sql.rb"]
|
21
22
|
|
22
23
|
if s.respond_to? :specification_version then
|
23
24
|
s.specification_version = 4
|
24
25
|
|
25
26
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
-
s.add_development_dependency(%q<minitest>, ["~>
|
27
|
-
s.add_development_dependency(%q<rdoc>, ["~>
|
28
|
-
s.add_development_dependency(%q<hoe>, ["~> 3.
|
27
|
+
s.add_development_dependency(%q<minitest>, ["~> 5.0"])
|
28
|
+
s.add_development_dependency(%q<rdoc>, ["~> 4.0"])
|
29
|
+
s.add_development_dependency(%q<hoe>, ["~> 3.7"])
|
29
30
|
else
|
30
|
-
s.add_dependency(%q<minitest>, ["~>
|
31
|
-
s.add_dependency(%q<rdoc>, ["~>
|
32
|
-
s.add_dependency(%q<hoe>, ["~> 3.
|
31
|
+
s.add_dependency(%q<minitest>, ["~> 5.0"])
|
32
|
+
s.add_dependency(%q<rdoc>, ["~> 4.0"])
|
33
|
+
s.add_dependency(%q<hoe>, ["~> 3.7"])
|
33
34
|
end
|
34
35
|
else
|
35
|
-
s.add_dependency(%q<minitest>, ["~>
|
36
|
-
s.add_dependency(%q<rdoc>, ["~>
|
37
|
-
s.add_dependency(%q<hoe>, ["~> 3.
|
36
|
+
s.add_dependency(%q<minitest>, ["~> 5.0"])
|
37
|
+
s.add_dependency(%q<rdoc>, ["~> 4.0"])
|
38
|
+
s.add_dependency(%q<hoe>, ["~> 3.7"])
|
38
39
|
end
|
39
40
|
end
|
data/lib/arel.rb
CHANGED
data/lib/arel/nodes/and.rb
CHANGED
data/lib/arel/nodes/binary.rb
CHANGED
data/lib/arel/nodes/function.rb
CHANGED
data/lib/arel/nodes/node.rb
CHANGED
@@ -6,6 +6,16 @@ module Arel
|
|
6
6
|
include Arel::FactoryMethods
|
7
7
|
include Enumerable
|
8
8
|
|
9
|
+
if $DEBUG
|
10
|
+
def _caller
|
11
|
+
@caller
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@caller = caller.dup
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
9
19
|
###
|
10
20
|
# Factory method to create a Nodes::Not node that has the recipient of
|
11
21
|
# the caller as a child.
|
data/lib/arel/nodes/unary.rb
CHANGED
data/lib/arel/table.rb
CHANGED
@@ -124,7 +124,10 @@ Arel 4.0.0 with no replacement. PEW PEW PEW!!!
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def hash
|
127
|
-
|
127
|
+
# Perf note: aliases, table alias and engine is excluded from the hash
|
128
|
+
# aliases can have a loop back to this table breaking hashes in parent
|
129
|
+
# relations, for the vast majority of cases @name is unique to a query
|
130
|
+
@name.hash
|
128
131
|
end
|
129
132
|
|
130
133
|
def eql? other
|
@@ -13,22 +13,22 @@ module Arel
|
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
def visit_Arel_Nodes_Assignment o
|
16
|
+
def visit_Arel_Nodes_Assignment o, a
|
17
17
|
if o.right.is_a? Arel::Nodes::BindParam
|
18
|
-
"#{visit o.left} = #{visit o.right}"
|
18
|
+
"#{visit o.left, a} = #{visit o.right, a}"
|
19
19
|
else
|
20
20
|
super
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def visit_Arel_Nodes_BindParam o
|
24
|
+
def visit_Arel_Nodes_BindParam o, a
|
25
25
|
if @block
|
26
26
|
@block.call
|
27
27
|
else
|
28
28
|
super
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -7,13 +7,13 @@ module Arel
|
|
7
7
|
|
8
8
|
private
|
9
9
|
|
10
|
-
def visit o
|
10
|
+
def visit o, a = nil
|
11
11
|
super
|
12
12
|
@block.call o
|
13
13
|
end
|
14
14
|
|
15
|
-
def unary o
|
16
|
-
visit o.expr
|
15
|
+
def unary o, a
|
16
|
+
visit o.expr, a
|
17
17
|
end
|
18
18
|
alias :visit_Arel_Nodes_Group :unary
|
19
19
|
alias :visit_Arel_Nodes_Grouping :unary
|
@@ -28,10 +28,10 @@ module Arel
|
|
28
28
|
alias :visit_Arel_Nodes_Top :unary
|
29
29
|
alias :visit_Arel_Nodes_UnqualifiedColumn :unary
|
30
30
|
|
31
|
-
def function o
|
32
|
-
visit o.expressions
|
33
|
-
visit o.alias
|
34
|
-
visit o.distinct
|
31
|
+
def function o, a
|
32
|
+
visit o.expressions, a
|
33
|
+
visit o.alias, a
|
34
|
+
visit o.distinct, a
|
35
35
|
end
|
36
36
|
alias :visit_Arel_Nodes_Avg :function
|
37
37
|
alias :visit_Arel_Nodes_Exists :function
|
@@ -39,27 +39,27 @@ module Arel
|
|
39
39
|
alias :visit_Arel_Nodes_Min :function
|
40
40
|
alias :visit_Arel_Nodes_Sum :function
|
41
41
|
|
42
|
-
def visit_Arel_Nodes_NamedFunction o
|
43
|
-
visit o.name
|
44
|
-
visit o.expressions
|
45
|
-
visit o.distinct
|
46
|
-
visit o.alias
|
42
|
+
def visit_Arel_Nodes_NamedFunction o, a
|
43
|
+
visit o.name, a
|
44
|
+
visit o.expressions, a
|
45
|
+
visit o.distinct, a
|
46
|
+
visit o.alias, a
|
47
47
|
end
|
48
48
|
|
49
|
-
def visit_Arel_Nodes_Count o
|
50
|
-
visit o.expressions
|
51
|
-
visit o.alias
|
52
|
-
visit o.distinct
|
49
|
+
def visit_Arel_Nodes_Count o, a
|
50
|
+
visit o.expressions, a
|
51
|
+
visit o.alias, a
|
52
|
+
visit o.distinct, a
|
53
53
|
end
|
54
54
|
|
55
|
-
def nary o
|
56
|
-
o.children.each { |child| visit child }
|
55
|
+
def nary o, a
|
56
|
+
o.children.each { |child| visit child, a }
|
57
57
|
end
|
58
58
|
alias :visit_Arel_Nodes_And :nary
|
59
59
|
|
60
|
-
def binary o
|
61
|
-
visit o.left
|
62
|
-
visit o.right
|
60
|
+
def binary o, a
|
61
|
+
visit o.left, a
|
62
|
+
visit o.right, a
|
63
63
|
end
|
64
64
|
alias :visit_Arel_Nodes_As :binary
|
65
65
|
alias :visit_Arel_Nodes_Assignment :binary
|
@@ -83,13 +83,13 @@ module Arel
|
|
83
83
|
alias :visit_Arel_Nodes_TableAlias :binary
|
84
84
|
alias :visit_Arel_Nodes_Values :binary
|
85
85
|
|
86
|
-
def visit_Arel_Nodes_StringJoin o
|
87
|
-
visit o.left
|
86
|
+
def visit_Arel_Nodes_StringJoin o, a
|
87
|
+
visit o.left, a
|
88
88
|
end
|
89
89
|
|
90
|
-
def visit_Arel_Attribute o
|
91
|
-
visit o.relation
|
92
|
-
visit o.name
|
90
|
+
def visit_Arel_Attribute o, a
|
91
|
+
visit o.relation, a
|
92
|
+
visit o.name, a
|
93
93
|
end
|
94
94
|
alias :visit_Arel_Attributes_Integer :visit_Arel_Attribute
|
95
95
|
alias :visit_Arel_Attributes_Float :visit_Arel_Attribute
|
@@ -99,11 +99,11 @@ module Arel
|
|
99
99
|
alias :visit_Arel_Attributes_Attribute :visit_Arel_Attribute
|
100
100
|
alias :visit_Arel_Attributes_Decimal :visit_Arel_Attribute
|
101
101
|
|
102
|
-
def visit_Arel_Table o
|
103
|
-
visit o.name
|
102
|
+
def visit_Arel_Table o, a
|
103
|
+
visit o.name, a
|
104
104
|
end
|
105
105
|
|
106
|
-
def terminal o
|
106
|
+
def terminal o, a
|
107
107
|
end
|
108
108
|
alias :visit_ActiveSupport_Multibyte_Chars :terminal
|
109
109
|
alias :visit_ActiveSupport_StringInquirer :terminal
|
@@ -127,43 +127,43 @@ module Arel
|
|
127
127
|
alias :visit_Time :terminal
|
128
128
|
alias :visit_TrueClass :terminal
|
129
129
|
|
130
|
-
def visit_Arel_Nodes_InsertStatement o
|
131
|
-
visit o.relation
|
132
|
-
visit o.columns
|
133
|
-
visit o.values
|
130
|
+
def visit_Arel_Nodes_InsertStatement o, a
|
131
|
+
visit o.relation, a
|
132
|
+
visit o.columns, a
|
133
|
+
visit o.values, a
|
134
134
|
end
|
135
135
|
|
136
|
-
def visit_Arel_Nodes_SelectCore o
|
137
|
-
visit o.projections
|
138
|
-
visit o.source
|
139
|
-
visit o.wheres
|
140
|
-
visit o.groups
|
141
|
-
visit o.windows
|
142
|
-
visit o.having
|
136
|
+
def visit_Arel_Nodes_SelectCore o, a
|
137
|
+
visit o.projections, a
|
138
|
+
visit o.source, a
|
139
|
+
visit o.wheres, a
|
140
|
+
visit o.groups, a
|
141
|
+
visit o.windows, a
|
142
|
+
visit o.having, a
|
143
143
|
end
|
144
144
|
|
145
|
-
def visit_Arel_Nodes_SelectStatement o
|
146
|
-
visit o.cores
|
147
|
-
visit o.orders
|
148
|
-
visit o.limit
|
149
|
-
visit o.lock
|
150
|
-
visit o.offset
|
145
|
+
def visit_Arel_Nodes_SelectStatement o, a
|
146
|
+
visit o.cores, a
|
147
|
+
visit o.orders, a
|
148
|
+
visit o.limit, a
|
149
|
+
visit o.lock, a
|
150
|
+
visit o.offset, a
|
151
151
|
end
|
152
152
|
|
153
|
-
def visit_Arel_Nodes_UpdateStatement o
|
154
|
-
visit o.relation
|
155
|
-
visit o.values
|
156
|
-
visit o.wheres
|
157
|
-
visit o.orders
|
158
|
-
visit o.limit
|
153
|
+
def visit_Arel_Nodes_UpdateStatement o, a
|
154
|
+
visit o.relation, a
|
155
|
+
visit o.values, a
|
156
|
+
visit o.wheres, a
|
157
|
+
visit o.orders, a
|
158
|
+
visit o.limit, a
|
159
159
|
end
|
160
160
|
|
161
|
-
def visit_Array o
|
162
|
-
o.each { |i| visit i }
|
161
|
+
def visit_Array o, a
|
162
|
+
o.each { |i| visit i, a }
|
163
163
|
end
|
164
164
|
|
165
|
-
def visit_Hash o
|
166
|
-
o.each { |k,v| visit(k); visit(v) }
|
165
|
+
def visit_Hash o, a
|
166
|
+
o.each { |k,v| visit(k, a); visit(v, a) }
|
167
167
|
end
|
168
168
|
end
|
169
169
|
end
|