arel 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +26 -0
- data/History.txt +18 -0
- data/Manifest.txt +31 -30
- data/README.markdown +7 -99
- data/Rakefile +3 -2
- data/arel.gemspec +18 -11
- data/lib/arel.rb +2 -1
- data/lib/arel/attributes/attribute.rb +1 -174
- data/lib/arel/crud.rb +2 -2
- data/lib/arel/delete_manager.rb +4 -4
- data/lib/arel/insert_manager.rb +8 -8
- data/lib/arel/nodes/exists.rb +2 -6
- data/lib/arel/nodes/sql_literal.rb +1 -0
- data/lib/arel/predications.rb +177 -0
- data/lib/arel/select_manager.rb +17 -11
- data/lib/arel/table.rb +4 -0
- data/lib/arel/tree_manager.rb +4 -3
- data/lib/arel/update_manager.rb +8 -8
- data/lib/arel/visitors.rb +4 -0
- data/lib/arel/visitors/dot.rb +3 -3
- data/lib/arel/visitors/join_sql.rb +2 -0
- data/lib/arel/visitors/mysql.rb +14 -0
- data/lib/arel/visitors/oracle.rb +31 -1
- data/lib/arel/visitors/order_clauses.rb +2 -0
- data/lib/arel/visitors/sqlite.rb +11 -0
- data/lib/arel/visitors/to_sql.rb +8 -11
- data/lib/arel/visitors/visitor.rb +19 -0
- data/{spec/attributes/attribute_spec.rb → test/attributes/test_attribute.rb} +84 -84
- data/test/helper.rb +13 -0
- data/{spec/nodes/count_spec.rb → test/nodes/test_count.rb} +3 -3
- data/{spec/nodes/delete_statement_spec.rb → test/nodes/test_delete_statement.rb} +3 -4
- data/{spec/nodes/equality_spec.rb → test/nodes/test_equality.rb} +10 -8
- data/{spec/nodes/insert_statement_spec.rb → test/nodes/test_insert_statement.rb} +6 -6
- data/{spec/nodes/or_spec.rb → test/nodes/test_or.rb} +6 -4
- data/test/nodes/test_select_core.rb +22 -0
- data/{spec/nodes/select_statement_spec.rb → test/nodes/test_select_statement.rb} +3 -4
- data/test/nodes/test_sql_literal.rb +52 -0
- data/{spec/nodes/sum_spec.rb → test/nodes/test_sum.rb} +2 -2
- data/{spec/nodes/update_statement_spec.rb → test/nodes/test_update_statement.rb} +6 -6
- data/{spec → test}/support/fake_record.rb +4 -2
- data/{spec/activerecord_compat_spec.rb → test/test_activerecord_compat.rb} +3 -3
- data/{spec/attributes_spec.rb → test/test_attributes.rb} +7 -7
- data/{spec/crud_spec.rb → test/test_crud.rb} +4 -4
- data/{spec/delete_manager_spec.rb → test/test_delete_manager.rb} +5 -16
- data/{spec/insert_manager_spec.rb → test/test_insert_manager.rb} +15 -31
- data/{spec/select_manager_spec.rb → test/test_select_manager.rb} +95 -77
- data/{spec/table_spec.rb → test/test_table.rb} +38 -32
- data/{spec/update_manager_spec.rb → test/test_update_manager.rb} +9 -21
- data/{spec/visitors/join_sql_spec.rb → test/visitors/test_join_sql.rb} +3 -3
- data/test/visitors/test_mysql.rb +27 -0
- data/{spec/visitors/oracle_spec.rb → test/visitors/test_oracle.rb} +26 -10
- data/{spec/visitors/postgres_spec.rb → test/visitors/test_postgres.rb} +2 -2
- data/test/visitors/test_sqlite.rb +18 -0
- data/{spec/visitors/to_sql_spec.rb → test/visitors/test_to_sql.rb} +25 -18
- metadata +101 -43
- data/spec/nodes/select_core_spec.rb +0 -21
- data/spec/nodes/sql_literal_spec.rb +0 -26
- data/spec/spec.opts +0 -3
- data/spec/spec_helper.rb +0 -18
- data/spec/support/check.rb +0 -6
- data/spec/support/matchers.rb +0 -4
- data/spec/support/matchers/be_like.rb +0 -24
- data/spec/support/shared/tree_manager_shared.rb +0 -9
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
module Visitors
|
5
|
+
describe 'the sqlite visitor' do
|
6
|
+
before do
|
7
|
+
@visitor = SQLite.new Table.engine
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'defaults limit to -1' do
|
11
|
+
stmt = Nodes::SelectStatement.new
|
12
|
+
stmt.offset = Nodes::Offset.new(1)
|
13
|
+
sql = @visitor.accept(stmt)
|
14
|
+
sql.must_be_like "SELECT LIMIT -1 OFFSET 1"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
module Arel
|
4
4
|
module Visitors
|
@@ -11,13 +11,13 @@ module Arel
|
|
11
11
|
describe 'equality' do
|
12
12
|
it 'should handle false' do
|
13
13
|
sql = @visitor.accept Nodes::Equality.new(false, false)
|
14
|
-
sql.
|
14
|
+
sql.must_be_like %{ 'f' = 'f' }
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should use the column to quote' do
|
18
18
|
table = Table.new(:users)
|
19
19
|
sql = @visitor.accept Nodes::Equality.new(table[:id], '1-fooo')
|
20
|
-
sql.
|
20
|
+
sql.must_be_like %{ "users"."id" = 1 }
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -29,6 +29,10 @@ module Arel
|
|
29
29
|
@visitor.accept 2.14
|
30
30
|
end
|
31
31
|
|
32
|
+
it "should visit_Bignum" do
|
33
|
+
@visitor.accept 8787878092
|
34
|
+
end
|
35
|
+
|
32
36
|
it "should visit_Hash" do
|
33
37
|
@visitor.accept({:a => 1})
|
34
38
|
end
|
@@ -41,16 +45,20 @@ module Arel
|
|
41
45
|
@visitor.accept Date.today
|
42
46
|
end
|
43
47
|
|
48
|
+
it "should visit_NilClass" do
|
49
|
+
@visitor.accept(nil).must_be_like "NULL"
|
50
|
+
end
|
51
|
+
|
44
52
|
it "should visit_Arel_Nodes_And" do
|
45
53
|
node = Nodes::And.new @attr.eq(10), @attr.eq(11)
|
46
|
-
@visitor.accept(node).
|
54
|
+
@visitor.accept(node).must_be_like %{
|
47
55
|
"users"."id" = 10 AND "users"."id" = 11
|
48
56
|
}
|
49
57
|
end
|
50
58
|
|
51
59
|
it "should visit_Arel_Nodes_Or" do
|
52
60
|
node = Nodes::Or.new @attr.eq(10), @attr.eq(11)
|
53
|
-
@visitor.accept(node).
|
61
|
+
@visitor.accept(node).must_be_like %{
|
54
62
|
"users"."id" = 10 OR "users"."id" = 11
|
55
63
|
}
|
56
64
|
end
|
@@ -61,15 +69,14 @@ module Arel
|
|
61
69
|
end
|
62
70
|
|
63
71
|
it "should visit_TrueClass" do
|
64
|
-
test =
|
65
|
-
test.
|
66
|
-
@visitor.accept(test).should be_like %{ "users"."id" = 't' }
|
72
|
+
test = Table.new(:users)[:bool].eq(true)
|
73
|
+
@visitor.accept(test).must_be_like %{ "users"."bool" = 't' }
|
67
74
|
end
|
68
75
|
|
69
76
|
describe "Nodes::Ordering" do
|
70
77
|
it "should know how to visit" do
|
71
78
|
node = @attr.desc
|
72
|
-
@visitor.accept(node).
|
79
|
+
@visitor.accept(node).must_be_like %{
|
73
80
|
"users"."id" DESC
|
74
81
|
}
|
75
82
|
end
|
@@ -78,33 +85,34 @@ module Arel
|
|
78
85
|
describe "Nodes::In" do
|
79
86
|
it "should know how to visit" do
|
80
87
|
node = @attr.in [1, 2, 3]
|
81
|
-
@visitor.accept(node).
|
88
|
+
@visitor.accept(node).must_be_like %{
|
82
89
|
"users"."id" IN (1, 2, 3)
|
83
90
|
}
|
84
91
|
end
|
85
92
|
|
86
93
|
it "should turn empty right to NULL" do
|
87
94
|
node = @attr.in []
|
88
|
-
@visitor.accept(node).
|
95
|
+
@visitor.accept(node).must_be_like %{
|
89
96
|
"users"."id" IN (NULL)
|
90
97
|
}
|
91
98
|
end
|
92
99
|
|
93
100
|
it 'can handle two dot ranges' do
|
94
101
|
node = @attr.in 1..3
|
95
|
-
@visitor.accept(node).
|
102
|
+
@visitor.accept(node).must_be_like %{
|
96
103
|
"users"."id" BETWEEN 1 AND 3
|
97
104
|
}
|
98
105
|
end
|
99
106
|
|
100
107
|
it 'can handle three dot ranges' do
|
101
108
|
node = @attr.in 1...3
|
102
|
-
@visitor.accept(node).
|
109
|
+
@visitor.accept(node).must_be_like %{
|
103
110
|
"users"."id" >= 1 AND "users"."id" < 3
|
104
111
|
}
|
105
112
|
end
|
106
113
|
|
107
114
|
it 'uses the same column for escaping values' do
|
115
|
+
@attr = Table.new(:users)[:name]
|
108
116
|
visitor = Class.new(ToSql) do
|
109
117
|
attr_accessor :expected
|
110
118
|
|
@@ -116,16 +124,15 @@ module Arel
|
|
116
124
|
in_node = Nodes::In.new @attr, %w{ a b c }
|
117
125
|
visitor = visitor.new(Table.engine)
|
118
126
|
visitor.expected = @attr.column
|
119
|
-
|
127
|
+
visitor.accept(in_node).must_equal %("users"."name" IN ('a', 'b', 'c'))
|
120
128
|
end
|
121
129
|
end
|
122
130
|
|
123
131
|
describe 'Equality' do
|
124
132
|
it "should escape strings" do
|
125
|
-
test =
|
126
|
-
test.
|
127
|
-
|
128
|
-
"users"."id" = 'Aaron Patterson'
|
133
|
+
test = Table.new(:users)[:name].eq 'Aaron Patterson'
|
134
|
+
@visitor.accept(test).must_be_like %{
|
135
|
+
"users"."name" = 'Aaron Patterson'
|
129
136
|
}
|
130
137
|
end
|
131
138
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 2
|
10
|
+
version: 2.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Aaron Patterson
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2010-
|
21
|
+
date: 2010-11-11 00:00:00 -06:00
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
@@ -38,25 +38,58 @@ dependencies:
|
|
38
38
|
type: :development
|
39
39
|
version_requirements: *id001
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
|
-
name:
|
41
|
+
name: minitest
|
42
42
|
prerelease: false
|
43
43
|
requirement: &id002 !ruby/object:Gem::Requirement
|
44
44
|
none: false
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
hash:
|
48
|
+
hash: 31098209
|
49
49
|
segments:
|
50
|
-
-
|
51
|
-
- 3
|
50
|
+
- 2
|
52
51
|
- 0
|
53
|
-
|
52
|
+
- 0
|
53
|
+
- beta
|
54
|
+
version: 2.0.0.beta
|
54
55
|
type: :development
|
55
56
|
version_requirements: *id002
|
56
57
|
- !ruby/object:Gem::Dependency
|
57
58
|
name: hoe
|
58
59
|
prerelease: false
|
59
60
|
requirement: &id003 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 11
|
66
|
+
segments:
|
67
|
+
- 2
|
68
|
+
- 1
|
69
|
+
- 0
|
70
|
+
version: 2.1.0
|
71
|
+
type: :development
|
72
|
+
version_requirements: *id003
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: minitest
|
75
|
+
prerelease: false
|
76
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 15
|
82
|
+
segments:
|
83
|
+
- 1
|
84
|
+
- 6
|
85
|
+
- 0
|
86
|
+
version: 1.6.0
|
87
|
+
type: :development
|
88
|
+
version_requirements: *id004
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: hoe
|
91
|
+
prerelease: false
|
92
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
60
93
|
none: false
|
61
94
|
requirements:
|
62
95
|
- - ">="
|
@@ -68,7 +101,7 @@ dependencies:
|
|
68
101
|
- 2
|
69
102
|
version: 2.6.2
|
70
103
|
type: :development
|
71
|
-
version_requirements: *
|
104
|
+
version_requirements: *id005
|
72
105
|
description: Arel is a Relational Algebra for Ruby. It 1) simplifies the generation complex of SQL queries and it 2) adapts to various RDBMS systems. It is intended to be a framework framework; that is, you can build your own ORM with it, focusing on innovative object and collection modeling as opposed to database compatibility and query generation.
|
73
106
|
email:
|
74
107
|
- aaron@tenderlovemaking.com
|
@@ -85,6 +118,7 @@ extra_rdoc_files:
|
|
85
118
|
- Manifest.txt
|
86
119
|
- README.markdown
|
87
120
|
files:
|
121
|
+
- .autotest
|
88
122
|
- History.txt
|
89
123
|
- MIT-LICENSE.txt
|
90
124
|
- Manifest.txt
|
@@ -145,6 +179,7 @@ files:
|
|
145
179
|
- lib/arel/nodes/unqualified_column.rb
|
146
180
|
- lib/arel/nodes/update_statement.rb
|
147
181
|
- lib/arel/nodes/values.rb
|
182
|
+
- lib/arel/predications.rb
|
148
183
|
- lib/arel/relation.rb
|
149
184
|
- lib/arel/select_manager.rb
|
150
185
|
- lib/arel/sql/engine.rb
|
@@ -159,38 +194,37 @@ files:
|
|
159
194
|
- lib/arel/visitors/oracle.rb
|
160
195
|
- lib/arel/visitors/order_clauses.rb
|
161
196
|
- lib/arel/visitors/postgresql.rb
|
197
|
+
- lib/arel/visitors/sqlite.rb
|
162
198
|
- lib/arel/visitors/to_sql.rb
|
199
|
+
- lib/arel/visitors/visitor.rb
|
163
200
|
- lib/arel/visitors/where_sql.rb
|
164
|
-
-
|
165
|
-
-
|
166
|
-
-
|
167
|
-
-
|
168
|
-
-
|
169
|
-
-
|
170
|
-
-
|
171
|
-
-
|
172
|
-
-
|
173
|
-
-
|
174
|
-
-
|
175
|
-
-
|
176
|
-
-
|
177
|
-
-
|
178
|
-
-
|
179
|
-
-
|
180
|
-
-
|
181
|
-
-
|
182
|
-
-
|
183
|
-
-
|
184
|
-
-
|
185
|
-
-
|
186
|
-
-
|
187
|
-
-
|
188
|
-
-
|
189
|
-
-
|
190
|
-
-
|
191
|
-
- spec/visitors/oracle_spec.rb
|
192
|
-
- spec/visitors/postgres_spec.rb
|
193
|
-
- spec/visitors/to_sql_spec.rb
|
201
|
+
- test/attributes/test_attribute.rb
|
202
|
+
- test/helper.rb
|
203
|
+
- test/nodes/test_count.rb
|
204
|
+
- test/nodes/test_delete_statement.rb
|
205
|
+
- test/nodes/test_equality.rb
|
206
|
+
- test/nodes/test_insert_statement.rb
|
207
|
+
- test/nodes/test_or.rb
|
208
|
+
- test/nodes/test_select_core.rb
|
209
|
+
- test/nodes/test_select_statement.rb
|
210
|
+
- test/nodes/test_sql_literal.rb
|
211
|
+
- test/nodes/test_sum.rb
|
212
|
+
- test/nodes/test_update_statement.rb
|
213
|
+
- test/support/fake_record.rb
|
214
|
+
- test/test_activerecord_compat.rb
|
215
|
+
- test/test_attributes.rb
|
216
|
+
- test/test_crud.rb
|
217
|
+
- test/test_delete_manager.rb
|
218
|
+
- test/test_insert_manager.rb
|
219
|
+
- test/test_select_manager.rb
|
220
|
+
- test/test_table.rb
|
221
|
+
- test/test_update_manager.rb
|
222
|
+
- test/visitors/test_join_sql.rb
|
223
|
+
- test/visitors/test_mysql.rb
|
224
|
+
- test/visitors/test_oracle.rb
|
225
|
+
- test/visitors/test_postgres.rb
|
226
|
+
- test/visitors/test_sqlite.rb
|
227
|
+
- test/visitors/test_to_sql.rb
|
194
228
|
has_rdoc: true
|
195
229
|
homepage: http://github.com/rails/arel
|
196
230
|
licenses: []
|
@@ -226,5 +260,29 @@ rubygems_version: 1.3.7
|
|
226
260
|
signing_key:
|
227
261
|
specification_version: 3
|
228
262
|
summary: Arel is a Relational Algebra for Ruby
|
229
|
-
test_files:
|
230
|
-
|
263
|
+
test_files:
|
264
|
+
- test/attributes/test_attribute.rb
|
265
|
+
- test/nodes/test_count.rb
|
266
|
+
- test/nodes/test_delete_statement.rb
|
267
|
+
- test/nodes/test_equality.rb
|
268
|
+
- test/nodes/test_insert_statement.rb
|
269
|
+
- test/nodes/test_or.rb
|
270
|
+
- test/nodes/test_select_core.rb
|
271
|
+
- test/nodes/test_select_statement.rb
|
272
|
+
- test/nodes/test_sql_literal.rb
|
273
|
+
- test/nodes/test_sum.rb
|
274
|
+
- test/nodes/test_update_statement.rb
|
275
|
+
- test/test_activerecord_compat.rb
|
276
|
+
- test/test_attributes.rb
|
277
|
+
- test/test_crud.rb
|
278
|
+
- test/test_delete_manager.rb
|
279
|
+
- test/test_insert_manager.rb
|
280
|
+
- test/test_select_manager.rb
|
281
|
+
- test/test_table.rb
|
282
|
+
- test/test_update_manager.rb
|
283
|
+
- test/visitors/test_join_sql.rb
|
284
|
+
- test/visitors/test_mysql.rb
|
285
|
+
- test/visitors/test_oracle.rb
|
286
|
+
- test/visitors/test_postgres.rb
|
287
|
+
- test/visitors/test_sqlite.rb
|
288
|
+
- test/visitors/test_to_sql.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Arel::Nodes::SelectCore do
|
4
|
-
describe "#clone" do
|
5
|
-
it "clones froms, projections and wheres" do
|
6
|
-
core = Arel::Nodes::SelectCore.new
|
7
|
-
core.instance_variable_set "@froms", %w[a b c]
|
8
|
-
core.instance_variable_set "@projections", %w[d e f]
|
9
|
-
core.instance_variable_set "@wheres", %w[g h i]
|
10
|
-
|
11
|
-
[:froms, :projections, :wheres].each do |array_attr|
|
12
|
-
core.send(array_attr).should_receive(:clone).and_return([array_attr])
|
13
|
-
end
|
14
|
-
|
15
|
-
dolly = core.clone
|
16
|
-
check dolly.froms.should == [:froms]
|
17
|
-
check dolly.projections.should == [:projections]
|
18
|
-
check dolly.wheres.should == [:wheres]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Arel
|
2
|
-
module Nodes
|
3
|
-
describe 'sql literal' do
|
4
|
-
describe 'sql' do
|
5
|
-
it 'makes a sql literal node' do
|
6
|
-
sql = Arel.sql 'foo'
|
7
|
-
sql.should be_kind_of Arel::Nodes::SqlLiteral
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe 'count' do
|
12
|
-
it 'makes a count node' do
|
13
|
-
node = SqlLiteral.new('*').count
|
14
|
-
viz = Visitors::ToSql.new Table.engine
|
15
|
-
viz.accept(node).should be_like %{ COUNT(*) }
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'makes a distinct node' do
|
19
|
-
node = SqlLiteral.new('*').count true
|
20
|
-
viz = Visitors::ToSql.new Table.engine
|
21
|
-
viz.accept(node).should be_like %{ COUNT(DISTINCT *) }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/spec/spec.opts
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'spec'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'arel'
|
5
|
-
|
6
|
-
require 'support/matchers/be_like'
|
7
|
-
require 'support/check'
|
8
|
-
require 'support/fake_record'
|
9
|
-
require 'support/shared/tree_manager_shared'
|
10
|
-
|
11
|
-
Spec::Runner.configure do |config|
|
12
|
-
config.include Matchers
|
13
|
-
config.include Check
|
14
|
-
|
15
|
-
config.before do
|
16
|
-
Arel::Table.engine = Arel::Sql::Engine.new(FakeRecord::Base.new)
|
17
|
-
end
|
18
|
-
end
|