arel 2.0.7 → 2.0.8.beta.20110131120940

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,6 +26,7 @@ lib/arel/nodes/count.rb
26
26
  lib/arel/nodes/delete_statement.rb
27
27
  lib/arel/nodes/does_not_match.rb
28
28
  lib/arel/nodes/equality.rb
29
+ lib/arel/nodes/except.rb
29
30
  lib/arel/nodes/exists.rb
30
31
  lib/arel/nodes/function.rb
31
32
  lib/arel/nodes/greater_than.rb
@@ -36,6 +37,7 @@ lib/arel/nodes/having.rb
36
37
  lib/arel/nodes/in.rb
37
38
  lib/arel/nodes/inner_join.rb
38
39
  lib/arel/nodes/insert_statement.rb
40
+ lib/arel/nodes/intersect.rb
39
41
  lib/arel/nodes/join.rb
40
42
  lib/arel/nodes/less_than.rb
41
43
  lib/arel/nodes/less_than_or_equal.rb
@@ -61,6 +63,8 @@ lib/arel/nodes/sum.rb
61
63
  lib/arel/nodes/table_alias.rb
62
64
  lib/arel/nodes/top.rb
63
65
  lib/arel/nodes/unary.rb
66
+ lib/arel/nodes/union.rb
67
+ lib/arel/nodes/union_all.rb
64
68
  lib/arel/nodes/unqualified_column.rb
65
69
  lib/arel/nodes/update_statement.rb
66
70
  lib/arel/nodes/values.rb
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{arel}
5
- s.version = "2.0.7.20110114100952"
5
+ s.version = "2.0.8.beta.20110131120940"
6
6
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Aaron Patterson", "Bryan Halmkamp", "Emilio Tagua", "Nick Kallen"]
9
- s.date = %q{2011-01-14}
9
+ s.date = %q{2011-01-31}
10
10
  s.description = %q{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.}
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", "History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown", "Rakefile", "arel.gemspec", "lib/arel.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/insert_manager.rb", "lib/arel/nodes.rb", "lib/arel/nodes/and.rb", "lib/arel/nodes/as.rb", "lib/arel/nodes/assignment.rb", "lib/arel/nodes/avg.rb", "lib/arel/nodes/between.rb", "lib/arel/nodes/binary.rb", "lib/arel/nodes/count.rb", "lib/arel/nodes/delete_statement.rb", "lib/arel/nodes/does_not_match.rb", "lib/arel/nodes/equality.rb", "lib/arel/nodes/exists.rb", "lib/arel/nodes/function.rb", "lib/arel/nodes/greater_than.rb", "lib/arel/nodes/greater_than_or_equal.rb", "lib/arel/nodes/group.rb", "lib/arel/nodes/grouping.rb", "lib/arel/nodes/having.rb", "lib/arel/nodes/in.rb", "lib/arel/nodes/inner_join.rb", "lib/arel/nodes/insert_statement.rb", "lib/arel/nodes/join.rb", "lib/arel/nodes/less_than.rb", "lib/arel/nodes/less_than_or_equal.rb", "lib/arel/nodes/limit.rb", "lib/arel/nodes/lock.rb", "lib/arel/nodes/matches.rb", "lib/arel/nodes/max.rb", "lib/arel/nodes/min.rb", "lib/arel/nodes/node.rb", "lib/arel/nodes/not.rb", "lib/arel/nodes/not_equal.rb", "lib/arel/nodes/not_in.rb", "lib/arel/nodes/offset.rb", "lib/arel/nodes/on.rb", "lib/arel/nodes/or.rb", "lib/arel/nodes/ordering.rb", "lib/arel/nodes/outer_join.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/sum.rb", "lib/arel/nodes/table_alias.rb", "lib/arel/nodes/top.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/predications.rb", "lib/arel/relation.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/depth_first.rb", "lib/arel/visitors/dot.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", "test/attributes/test_attribute.rb", "test/helper.rb", "test/nodes/test_as.rb", "test/nodes/test_count.rb", "test/nodes/test_delete_statement.rb", "test/nodes/test_equality.rb", "test/nodes/test_insert_statement.rb", "test/nodes/test_node.rb", "test/nodes/test_not.rb", "test/nodes/test_or.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_update_statement.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_insert_manager.rb", "test/test_select_manager.rb", "test/test_table.rb", "test/test_update_manager.rb", "test/visitors/test_depth_first.rb", "test/visitors/test_dot.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", "History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown", "Rakefile", "arel.gemspec", "lib/arel.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/insert_manager.rb", "lib/arel/nodes.rb", "lib/arel/nodes/and.rb", "lib/arel/nodes/as.rb", "lib/arel/nodes/assignment.rb", "lib/arel/nodes/avg.rb", "lib/arel/nodes/between.rb", "lib/arel/nodes/binary.rb", "lib/arel/nodes/count.rb", "lib/arel/nodes/delete_statement.rb", "lib/arel/nodes/does_not_match.rb", "lib/arel/nodes/equality.rb", "lib/arel/nodes/except.rb", "lib/arel/nodes/exists.rb", "lib/arel/nodes/function.rb", "lib/arel/nodes/greater_than.rb", "lib/arel/nodes/greater_than_or_equal.rb", "lib/arel/nodes/group.rb", "lib/arel/nodes/grouping.rb", "lib/arel/nodes/having.rb", "lib/arel/nodes/in.rb", "lib/arel/nodes/inner_join.rb", "lib/arel/nodes/insert_statement.rb", "lib/arel/nodes/intersect.rb", "lib/arel/nodes/join.rb", "lib/arel/nodes/less_than.rb", "lib/arel/nodes/less_than_or_equal.rb", "lib/arel/nodes/limit.rb", "lib/arel/nodes/lock.rb", "lib/arel/nodes/matches.rb", "lib/arel/nodes/max.rb", "lib/arel/nodes/min.rb", "lib/arel/nodes/node.rb", "lib/arel/nodes/not.rb", "lib/arel/nodes/not_equal.rb", "lib/arel/nodes/not_in.rb", "lib/arel/nodes/offset.rb", "lib/arel/nodes/on.rb", "lib/arel/nodes/or.rb", "lib/arel/nodes/ordering.rb", "lib/arel/nodes/outer_join.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/sum.rb", "lib/arel/nodes/table_alias.rb", "lib/arel/nodes/top.rb", "lib/arel/nodes/unary.rb", "lib/arel/nodes/union.rb", "lib/arel/nodes/union_all.rb", "lib/arel/nodes/unqualified_column.rb", "lib/arel/nodes/update_statement.rb", "lib/arel/nodes/values.rb", "lib/arel/predications.rb", "lib/arel/relation.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/depth_first.rb", "lib/arel/visitors/dot.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", "test/attributes/test_attribute.rb", "test/helper.rb", "test/nodes/test_as.rb", "test/nodes/test_count.rb", "test/nodes/test_delete_statement.rb", "test/nodes/test_equality.rb", "test/nodes/test_insert_statement.rb", "test/nodes/test_node.rb", "test/nodes/test_not.rb", "test/nodes/test_or.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_update_statement.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_insert_manager.rb", "test/test_select_manager.rb", "test/test_table.rb", "test/test_update_manager.rb", "test/visitors/test_depth_first.rb", "test/visitors/test_dot.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 = %q{http://github.com/rails/arel}
15
15
  s.rdoc_options = ["--main", "README.markdown"]
16
16
  s.require_paths = ["lib"]
@@ -29,7 +29,7 @@ require 'arel/sql_literal'
29
29
  ####
30
30
 
31
31
  module Arel
32
- VERSION = '2.0.7'
32
+ VERSION = '2.0.8.beta'
33
33
 
34
34
  def self.sql raw_sql
35
35
  Arel::Nodes::SqlLiteral.new raw_sql
@@ -47,3 +47,7 @@ require 'arel/nodes/inner_join'
47
47
  require 'arel/nodes/outer_join'
48
48
  require 'arel/nodes/string_join'
49
49
  require 'arel/nodes/on'
50
+ require 'arel/nodes/except'
51
+ require 'arel/nodes/intersect'
52
+ require 'arel/nodes/union'
53
+ require 'arel/nodes/union_all'
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ module Nodes
3
+ class Except < Arel::Nodes::Binary
4
+ end
5
+ end
6
+ end
7
+
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ module Nodes
3
+ class Intersect < Arel::Nodes::Binary
4
+ end
5
+ end
6
+ end
7
+
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ module Nodes
3
+ class Union < Arel::Nodes::Binary
4
+ end
5
+ end
6
+ end
7
+
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ module Nodes
3
+ class UnionAll < Arel::Nodes::Binary
4
+ end
5
+ end
6
+ end
7
+
@@ -130,6 +130,26 @@ module Arel
130
130
  Nodes::SqlLiteral.new viz.accept @ctx
131
131
  end
132
132
 
133
+ def union operation, other = nil
134
+ if other
135
+ node_class = Nodes.const_get("Union#{operation.to_s.capitalize}")
136
+ else
137
+ other = operation
138
+ node_class = Nodes::Union
139
+ end
140
+
141
+ node_class.new self.ast, other.ast
142
+ end
143
+
144
+ def intersect other
145
+ Nodes::Intersect.new ast, other.ast
146
+ end
147
+
148
+ def except other
149
+ Nodes::Except.new ast, other.ast
150
+ end
151
+ alias :minus :except
152
+
133
153
  def take limit
134
154
  @ast.limit = Nodes::Limit.new(limit)
135
155
  @ctx.top = Nodes::Top.new(limit)
@@ -61,6 +61,10 @@ module Arel
61
61
  "raw_rnum_ > #{visit o.value}"
62
62
  end
63
63
 
64
+ def visit_Arel_Nodes_Except o
65
+ "( #{visit o.left} MINUS #{visit o.right} )"
66
+ end
67
+
64
68
  ###
65
69
  # Hacks for the order clauses specific to Oracle
66
70
  def order_hacks o
@@ -206,6 +206,22 @@ module Arel
206
206
  "NOT (#{visit o.expr})"
207
207
  end
208
208
 
209
+ def visit_Arel_Nodes_Union o
210
+ "( #{visit o.left} UNION #{visit o.right} )"
211
+ end
212
+
213
+ def visit_Arel_Nodes_UnionAll o
214
+ "( #{visit o.left} UNION ALL #{visit o.right} )"
215
+ end
216
+
217
+ def visit_Arel_Nodes_Intersect o
218
+ "( #{visit o.left} INTERSECT #{visit o.right} )"
219
+ end
220
+
221
+ def visit_Arel_Nodes_Except o
222
+ "( #{visit o.left} EXCEPT #{visit o.right} )"
223
+ end
224
+
209
225
  def visit_Arel_Table o
210
226
  if o.table_alias
211
227
  "#{quote_table_name o.name} #{quote_table_name o.table_alias}"
@@ -596,4 +596,46 @@ module Arel
596
596
  end
597
597
  end
598
598
  end
599
+
600
+ describe 'set operations' do
601
+ before do
602
+ @table = Table.new :users
603
+ @m1 = Arel::SelectManager.new Table.engine, @table
604
+ @m1.project Arel.sql('*')
605
+ @m2 = Arel::SelectManager.new Table.engine, @table
606
+ @m2.project Arel.sql('*')
607
+ end
608
+
609
+ it 'supports union' do
610
+ @m1.where(@table[:id].lt(18))
611
+ @m2.where(@table[:id].gt(99))
612
+ (@m1.union @m2).to_sql.must_be_like %{
613
+ ( SELECT * FROM "users" WHERE "users"."id" < 18 UNION SELECT * FROM "users" WHERE "users"."id" > 99 )
614
+ }
615
+ end
616
+
617
+ it 'supports union all' do
618
+ @m1.where(@table[:id].lt(18))
619
+ @m2.where(@table[:id].gt(99))
620
+ (@m1.union :all, @m2).to_sql.must_be_like %{
621
+ ( SELECT * FROM "users" WHERE "users"."id" < 18 UNION ALL SELECT * FROM "users" WHERE "users"."id" > 99 )
622
+ }
623
+ end
624
+
625
+ it 'supports intersect' do
626
+ @m1.where(@table[:id].gt(18))
627
+ @m2.where(@table[:id].lt(99))
628
+ (@m1.intersect @m2).to_sql.must_be_like %{
629
+ ( SELECT * FROM "users" WHERE "users"."id" > 18 INTERSECT SELECT * FROM "users" WHERE "users"."id" < 99 )
630
+ }
631
+ end
632
+
633
+ it 'supports except' do
634
+ @m1.where(@table[:id].in(18..60))
635
+ @m2.where(@table[:id].in(40..99))
636
+ (@m1.except @m2).to_sql.must_be_like %{
637
+ ( SELECT * FROM "users" WHERE "users"."id" BETWEEN 18 AND 60 EXCEPT SELECT * FROM "users" WHERE "users"."id" BETWEEN 40 AND 99 )
638
+ }
639
+ end
640
+ end
599
641
  end
@@ -133,6 +133,14 @@ module Arel
133
133
  end
134
134
  end
135
135
 
136
+ it 'modified except to be minus' do
137
+ left = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 10")
138
+ right = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 20")
139
+ sql = @visitor.accept Nodes::Except.new(left, right)
140
+ sql.must_be_like %{
141
+ ( SELECT * FROM users WHERE age > 10 MINUS SELECT * FROM users WHERE age > 20 )
142
+ }
143
+ end
136
144
  end
137
145
  end
138
146
  end
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
5
- prerelease: false
4
+ hash: 40220250905851
5
+ prerelease: true
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 7
10
- version: 2.0.7
9
+ - 8
10
+ - beta
11
+ - 20110131120940
12
+ version: 2.0.8.beta.20110131120940
11
13
  platform: ruby
12
14
  authors:
13
15
  - Aaron Patterson
@@ -18,7 +20,7 @@ autorequire:
18
20
  bindir: bin
19
21
  cert_chain: []
20
22
 
21
- date: 2011-01-14 00:00:00 -08:00
23
+ date: 2011-01-31 00:00:00 -08:00
22
24
  default_executable:
23
25
  dependencies:
24
26
  - !ruby/object:Gem::Dependency
@@ -129,6 +131,7 @@ files:
129
131
  - lib/arel/nodes/delete_statement.rb
130
132
  - lib/arel/nodes/does_not_match.rb
131
133
  - lib/arel/nodes/equality.rb
134
+ - lib/arel/nodes/except.rb
132
135
  - lib/arel/nodes/exists.rb
133
136
  - lib/arel/nodes/function.rb
134
137
  - lib/arel/nodes/greater_than.rb
@@ -139,6 +142,7 @@ files:
139
142
  - lib/arel/nodes/in.rb
140
143
  - lib/arel/nodes/inner_join.rb
141
144
  - lib/arel/nodes/insert_statement.rb
145
+ - lib/arel/nodes/intersect.rb
142
146
  - lib/arel/nodes/join.rb
143
147
  - lib/arel/nodes/less_than.rb
144
148
  - lib/arel/nodes/less_than_or_equal.rb
@@ -164,6 +168,8 @@ files:
164
168
  - lib/arel/nodes/table_alias.rb
165
169
  - lib/arel/nodes/top.rb
166
170
  - lib/arel/nodes/unary.rb
171
+ - lib/arel/nodes/union.rb
172
+ - lib/arel/nodes/union_all.rb
167
173
  - lib/arel/nodes/unqualified_column.rb
168
174
  - lib/arel/nodes/update_statement.rb
169
175
  - lib/arel/nodes/values.rb
@@ -243,12 +249,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
249
  required_rubygems_version: !ruby/object:Gem::Requirement
244
250
  none: false
245
251
  requirements:
246
- - - ">="
252
+ - - ">"
247
253
  - !ruby/object:Gem::Version
248
- hash: 3
254
+ hash: 25
249
255
  segments:
250
- - 0
251
- version: "0"
256
+ - 1
257
+ - 3
258
+ - 1
259
+ version: 1.3.1
252
260
  requirements: []
253
261
 
254
262
  rubyforge_project: arel