arel 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,11 @@
1
- source "http://rubygems.org"
1
+ # -*- ruby -*-
2
2
 
3
- gem 'hoe', '>= 2.1.0'
4
- gem 'minitest'
3
+ # DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
4
+
5
+ source :gemcutter
6
+
7
+
8
+ gem "minitest", "~>2.2", :group => [:development, :test]
9
+ gem "hoe", "~>2.10", :group => [:development, :test]
10
+
11
+ # vim: syntax=ruby
@@ -6,7 +6,7 @@
6
6
 
7
7
  Arel is a SQL AST manager for Ruby. It
8
8
 
9
- 1. Simplifies the generation complex of SQL queries
9
+ 1. Simplifies the generation of complex SQL queries
10
10
  2. Adapts to various RDBMS systems
11
11
 
12
12
  It is intended to be a framework framework; that is, you can build your own ORM
data/Rakefile CHANGED
@@ -6,6 +6,7 @@ Hoe.plugins.delete :rubyforge
6
6
  Hoe.plugin :minitest
7
7
  Hoe.plugin :gemspec # `gem install hoe-gemspec`
8
8
  Hoe.plugin :git # `gem install hoe-git`
9
+ Hoe.plugin :bundler # `gem install hoe-bundler`
9
10
 
10
11
  Hoe.spec 'arel' do
11
12
  developer('Aaron Patterson', 'aaron@tenderlovemaking.com')
@@ -1,40 +1,39 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = %q{arel}
5
- s.version = "2.2.0.20110809140134"
4
+ s.name = "arel"
5
+ s.version = "2.2.2.20120220180142"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = [%q{Aaron Patterson}, %q{Bryan Halmkamp}, %q{Emilio Tagua}, %q{Nick Kallen}]
9
- s.date = %q{2011-08-09}
10
- s.description = %q{Arel is a SQL AST manager for Ruby. It
11
-
12
- 1. Simplifies the generation complex of SQL queries
13
- 2. Adapts to various RDBMS systems
14
-
15
- It is intended to be a framework framework; that is, you can build your own ORM
16
- with it, focusing on innovative object and collection modeling as opposed to
17
- database compatibility and query generation.}
18
- s.email = [%q{aaron@tenderlovemaking.com}, %q{bryan@brynary.com}, %q{miloops@gmail.com}, %q{nick@example.org}]
19
- s.extra_rdoc_files = [%q{History.txt}, %q{MIT-LICENSE.txt}, %q{Manifest.txt}, %q{README.markdown}]
20
- s.files = [%q{.autotest}, %q{.gemtest}, %q{Gemfile}, %q{History.txt}, %q{MIT-LICENSE.txt}, %q{Manifest.txt}, %q{README.markdown}, %q{Rakefile}, %q{arel.gemspec}, %q{lib/arel.rb}, %q{lib/arel/alias_predication.rb}, %q{lib/arel/attributes.rb}, %q{lib/arel/attributes/attribute.rb}, %q{lib/arel/compatibility/wheres.rb}, %q{lib/arel/crud.rb}, %q{lib/arel/delete_manager.rb}, %q{lib/arel/deprecated.rb}, %q{lib/arel/expression.rb}, %q{lib/arel/expressions.rb}, %q{lib/arel/factory_methods.rb}, %q{lib/arel/insert_manager.rb}, %q{lib/arel/math.rb}, %q{lib/arel/nodes.rb}, %q{lib/arel/nodes/and.rb}, %q{lib/arel/nodes/ascending.rb}, %q{lib/arel/nodes/binary.rb}, %q{lib/arel/nodes/count.rb}, %q{lib/arel/nodes/delete_statement.rb}, %q{lib/arel/nodes/descending.rb}, %q{lib/arel/nodes/equality.rb}, %q{lib/arel/nodes/false.rb}, %q{lib/arel/nodes/function.rb}, %q{lib/arel/nodes/in.rb}, %q{lib/arel/nodes/infix_operation.rb}, %q{lib/arel/nodes/inner_join.rb}, %q{lib/arel/nodes/insert_statement.rb}, %q{lib/arel/nodes/join_source.rb}, %q{lib/arel/nodes/named_function.rb}, %q{lib/arel/nodes/node.rb}, %q{lib/arel/nodes/ordering.rb}, %q{lib/arel/nodes/outer_join.rb}, %q{lib/arel/nodes/select_core.rb}, %q{lib/arel/nodes/select_statement.rb}, %q{lib/arel/nodes/sql_literal.rb}, %q{lib/arel/nodes/string_join.rb}, %q{lib/arel/nodes/table_alias.rb}, %q{lib/arel/nodes/terminal.rb}, %q{lib/arel/nodes/true.rb}, %q{lib/arel/nodes/unary.rb}, %q{lib/arel/nodes/unqualified_column.rb}, %q{lib/arel/nodes/update_statement.rb}, %q{lib/arel/nodes/values.rb}, %q{lib/arel/nodes/with.rb}, %q{lib/arel/order_predications.rb}, %q{lib/arel/predications.rb}, %q{lib/arel/relation.rb}, %q{lib/arel/select_manager.rb}, %q{lib/arel/sql/engine.rb}, %q{lib/arel/sql_literal.rb}, %q{lib/arel/table.rb}, %q{lib/arel/tree_manager.rb}, %q{lib/arel/update_manager.rb}, %q{lib/arel/visitors.rb}, %q{lib/arel/visitors/depth_first.rb}, %q{lib/arel/visitors/dot.rb}, %q{lib/arel/visitors/ibm_db.rb}, %q{lib/arel/visitors/informix.rb}, %q{lib/arel/visitors/join_sql.rb}, %q{lib/arel/visitors/mssql.rb}, %q{lib/arel/visitors/mysql.rb}, %q{lib/arel/visitors/oracle.rb}, %q{lib/arel/visitors/order_clauses.rb}, %q{lib/arel/visitors/postgresql.rb}, %q{lib/arel/visitors/sqlite.rb}, %q{lib/arel/visitors/to_sql.rb}, %q{lib/arel/visitors/visitor.rb}, %q{lib/arel/visitors/where_sql.rb}, %q{test/attributes/test_attribute.rb}, %q{test/helper.rb}, %q{test/nodes/test_as.rb}, %q{test/nodes/test_ascending.rb}, %q{test/nodes/test_bin.rb}, %q{test/nodes/test_count.rb}, %q{test/nodes/test_delete_statement.rb}, %q{test/nodes/test_descending.rb}, %q{test/nodes/test_equality.rb}, %q{test/nodes/test_infix_operation.rb}, %q{test/nodes/test_insert_statement.rb}, %q{test/nodes/test_named_function.rb}, %q{test/nodes/test_node.rb}, %q{test/nodes/test_not.rb}, %q{test/nodes/test_or.rb}, %q{test/nodes/test_select_core.rb}, %q{test/nodes/test_select_statement.rb}, %q{test/nodes/test_sql_literal.rb}, %q{test/nodes/test_sum.rb}, %q{test/nodes/test_update_statement.rb}, %q{test/support/fake_record.rb}, %q{test/test_activerecord_compat.rb}, %q{test/test_attributes.rb}, %q{test/test_crud.rb}, %q{test/test_delete_manager.rb}, %q{test/test_factory_methods.rb}, %q{test/test_insert_manager.rb}, %q{test/test_select_manager.rb}, %q{test/test_table.rb}, %q{test/test_update_manager.rb}, %q{test/visitors/test_depth_first.rb}, %q{test/visitors/test_dot.rb}, %q{test/visitors/test_ibm_db.rb}, %q{test/visitors/test_informix.rb}, %q{test/visitors/test_join_sql.rb}, %q{test/visitors/test_mssql.rb}, %q{test/visitors/test_mysql.rb}, %q{test/visitors/test_oracle.rb}, %q{test/visitors/test_postgres.rb}, %q{test/visitors/test_sqlite.rb}, %q{test/visitors/test_to_sql.rb}]
21
- s.homepage = %q{http://github.com/rails/arel}
22
- s.rdoc_options = [%q{--main}, %q{README.markdown}]
23
- s.require_paths = [%q{lib}]
24
- s.rubyforge_project = %q{arel}
25
- s.rubygems_version = %q{1.8.6.1}
26
- s.summary = %q{Arel is a SQL AST manager for Ruby}
27
- s.test_files = [%q{test/attributes/test_attribute.rb}, %q{test/nodes/test_as.rb}, %q{test/nodes/test_ascending.rb}, %q{test/nodes/test_bin.rb}, %q{test/nodes/test_count.rb}, %q{test/nodes/test_delete_statement.rb}, %q{test/nodes/test_descending.rb}, %q{test/nodes/test_equality.rb}, %q{test/nodes/test_infix_operation.rb}, %q{test/nodes/test_insert_statement.rb}, %q{test/nodes/test_named_function.rb}, %q{test/nodes/test_node.rb}, %q{test/nodes/test_not.rb}, %q{test/nodes/test_or.rb}, %q{test/nodes/test_select_core.rb}, %q{test/nodes/test_select_statement.rb}, %q{test/nodes/test_sql_literal.rb}, %q{test/nodes/test_sum.rb}, %q{test/nodes/test_update_statement.rb}, %q{test/test_activerecord_compat.rb}, %q{test/test_attributes.rb}, %q{test/test_crud.rb}, %q{test/test_delete_manager.rb}, %q{test/test_factory_methods.rb}, %q{test/test_insert_manager.rb}, %q{test/test_select_manager.rb}, %q{test/test_table.rb}, %q{test/test_update_manager.rb}, %q{test/visitors/test_depth_first.rb}, %q{test/visitors/test_dot.rb}, %q{test/visitors/test_ibm_db.rb}, %q{test/visitors/test_informix.rb}, %q{test/visitors/test_join_sql.rb}, %q{test/visitors/test_mssql.rb}, %q{test/visitors/test_mysql.rb}, %q{test/visitors/test_oracle.rb}, %q{test/visitors/test_postgres.rb}, %q{test/visitors/test_sqlite.rb}, %q{test/visitors/test_to_sql.rb}]
8
+ s.authors = ["Aaron Patterson", "Bryan Halmkamp", "Emilio Tagua", "Nick Kallen"]
9
+ s.date = "2012-02-21"
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
+ s.email = ["aaron@tenderlovemaking.com", "bryan@brynary.com", "miloops@gmail.com", "nick@example.org"]
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/false.rb", "lib/arel/nodes/function.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/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/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/with.rb", "lib/arel/order_predications.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/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", "test/attributes/test_attribute.rb", "test/helper.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_equality.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_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_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_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"]
14
+ s.homepage = "http://github.com/rails/arel"
15
+ s.rdoc_options = ["--main", "README.markdown"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = "arel"
18
+ s.rubygems_version = "1.8.11"
19
+ s.summary = "Arel is a SQL AST manager for Ruby"
20
+ s.test_files = ["test/attributes/test_attribute.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_equality.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_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/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_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"]
28
21
 
29
22
  if s.respond_to? :specification_version then
30
23
  s.specification_version = 3
31
24
 
32
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
33
- s.add_development_dependency(%q<hoe>, ["~> 2.10"])
26
+ s.add_development_dependency(%q<minitest>, ["~> 2.11"])
27
+ s.add_development_dependency(%q<rdoc>, ["~> 3.10"])
28
+ s.add_development_dependency(%q<hoe>, ["~> 2.13"])
34
29
  else
35
- s.add_dependency(%q<hoe>, ["~> 2.10"])
30
+ s.add_dependency(%q<minitest>, ["~> 2.11"])
31
+ s.add_dependency(%q<rdoc>, ["~> 3.10"])
32
+ s.add_dependency(%q<hoe>, ["~> 2.13"])
36
33
  end
37
34
  else
38
- s.add_dependency(%q<hoe>, ["~> 2.10"])
35
+ s.add_dependency(%q<minitest>, ["~> 2.11"])
36
+ s.add_dependency(%q<rdoc>, ["~> 3.10"])
37
+ s.add_dependency(%q<hoe>, ["~> 2.13"])
39
38
  end
40
39
  end
@@ -33,7 +33,7 @@ require 'arel/sql_literal'
33
33
  ####
34
34
 
35
35
  module Arel
36
- VERSION = '2.2.1'
36
+ VERSION = '2.2.2'
37
37
 
38
38
  def self.sql raw_sql
39
39
  Arel::Nodes::SqlLiteral.new raw_sql
@@ -39,7 +39,7 @@ module Arel
39
39
  def each &block
40
40
  return enum_for(:each) unless block_given?
41
41
 
42
- Visitors::DepthFirst.new(block).accept self
42
+ ::Arel::Visitors::DepthFirst.new(block).accept self
43
43
  end
44
44
  end
45
45
  end
@@ -6,5 +6,8 @@ module Arel
6
6
  include Arel::AliasPredication
7
7
  include Arel::OrderPredications
8
8
  end
9
+
10
+ class BindParam < SqlLiteral
11
+ end
9
12
  end
10
13
  end
@@ -10,7 +10,7 @@ module Arel
10
10
  end
11
11
 
12
12
  def table_name
13
- relation.name
13
+ relation.respond_to?(:name) ? relation.name : name
14
14
  end
15
15
  end
16
16
  end
@@ -51,7 +51,7 @@ module Arel
51
51
  if $VERBOSE
52
52
  warn "(#{caller.first}) where_clauses is deprecated and will be removed in arel 3.0.0 with no replacement"
53
53
  end
54
- to_sql = Visitors::ToSql.new @engine
54
+ to_sql = Visitors::ToSql.new @engine.connection_pool
55
55
  @ctx.wheres.map { |c| to_sql.accept c }
56
56
  end
57
57
 
@@ -139,6 +139,14 @@ module Arel
139
139
  @ctx.projections = projections
140
140
  end
141
141
 
142
+ def distinct(value = true)
143
+ if value
144
+ @ctx.set_quantifier = Arel::Nodes::Distinct.new
145
+ else
146
+ @ctx.set_quantifier = nil
147
+ end
148
+ end
149
+
142
150
  def order *expr
143
151
  # FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
144
152
  @ast.orders.concat expr.map { |x|
@@ -109,6 +109,7 @@ module Arel
109
109
  alias :visit_Arel_Nodes_Lock :terminal
110
110
  alias :visit_Arel_Nodes_Node :terminal
111
111
  alias :visit_Arel_Nodes_SqlLiteral :terminal
112
+ alias :visit_Arel_Nodes_BindParam :terminal
112
113
  alias :visit_Arel_SqlLiteral :terminal
113
114
  alias :visit_BigDecimal :terminal
114
115
  alias :visit_Bignum :terminal
@@ -65,6 +65,7 @@ module Arel
65
65
  visit_edge o, "expr"
66
66
  end
67
67
  alias :visit_Arel_Nodes_Group :unary
68
+ alias :visit_Arel_Nodes_BindParam :unary
68
69
  alias :visit_Arel_Nodes_Grouping :unary
69
70
  alias :visit_Arel_Nodes_Having :unary
70
71
  alias :visit_Arel_Nodes_Limit :unary
@@ -28,10 +28,6 @@ module Arel
28
28
  "BINARY #{visit o.expr}"
29
29
  end
30
30
 
31
- def visit_Arel_Nodes_Lock o
32
- visit o.expr
33
- end
34
-
35
31
  ###
36
32
  # :'(
37
33
  # http://dev.mysql.com/doc/refman/5.0/en/select.html#id3482214
@@ -2,9 +2,6 @@ module Arel
2
2
  module Visitors
3
3
  class PostgreSQL < Arel::Visitors::ToSql
4
4
  private
5
- def visit_Arel_Nodes_Lock o
6
- visit o.expr
7
- end
8
5
 
9
6
  def visit_Arel_Nodes_Matches o
10
7
  "#{visit o.left} ILIKE #{visit o.right}"
@@ -2,6 +2,11 @@ module Arel
2
2
  module Visitors
3
3
  class SQLite < Arel::Visitors::ToSql
4
4
  private
5
+
6
+ # Locks are not supported in SQLite
7
+ def visit_Arel_Nodes_Lock o
8
+ end
9
+
5
10
  def visit_Arel_Nodes_SelectStatement o
6
11
  o.limit = Arel::Nodes::Limit.new(-1) if o.offset && !o.limit
7
12
  super
@@ -200,9 +200,8 @@ key on UpdateManager using UpdateManager#key=
200
200
  ""
201
201
  end
202
202
 
203
- # FIXME: this does nothing on SQLLite3, but should do things on other
204
- # databases.
205
203
  def visit_Arel_Nodes_Lock o
204
+ visit o.expr
206
205
  end
207
206
 
208
207
  def visit_Arel_Nodes_Grouping o
@@ -383,6 +382,7 @@ key on UpdateManager using UpdateManager#key=
383
382
 
384
383
  def literal o; o end
385
384
 
385
+ alias :visit_Arel_Nodes_BindParam :literal
386
386
  alias :visit_Arel_Nodes_SqlLiteral :literal
387
387
  alias :visit_Arel_SqlLiteral :literal # This is deprecated
388
388
  alias :visit_Bignum :literal
@@ -11,6 +11,7 @@ module Arel
11
11
  Nodes.const_get(k)
12
12
  }.grep(Class).each do |klass|
13
13
  next if Nodes::SqlLiteral == klass
14
+ next if Nodes::BindParam == klass
14
15
  next if klass.name =~ /^Arel::Nodes::Test/
15
16
  assert klass.ancestors.include?(Nodes::Node), klass.name
16
17
  end
@@ -454,7 +454,7 @@ module Arel
454
454
  it 'adds a lock node' do
455
455
  table = Table.new :users
456
456
  mgr = table.from table
457
- mgr.lock.to_sql.must_be_like %{ SELECT FROM "users" }
457
+ mgr.lock.to_sql.must_be_like %{ SELECT FROM "users" FOR UPDATE }
458
458
  end
459
459
  end
460
460
 
@@ -654,6 +654,23 @@ module Arel
654
654
  }
655
655
  end
656
656
 
657
+ it 'can have a non-table alias as relation name' do
658
+ users = Table.new :users
659
+ comments = Table.new :comments
660
+
661
+ counts = comments.from(comments).
662
+ group(comments[:user_id]).
663
+ project(
664
+ comments[:user_id].as("user_id"),
665
+ comments[:user_id].count.as("count")
666
+ ).as("counts")
667
+
668
+ joins = users.join(counts).on(counts[:user_id].eq(10))
669
+ joins.to_sql.must_be_like %{
670
+ SELECT FROM "users" INNER JOIN (SELECT "comments"."user_id" AS user_id, COUNT("comments"."user_id") AS count FROM "comments" GROUP BY "comments"."user_id") counts ON counts."user_id" = 10
671
+ }
672
+ end
673
+
657
674
  it 'returns string join sql' do
658
675
  table = Table.new :users
659
676
  manager = Arel::SelectManager.new Table.engine
@@ -964,5 +981,18 @@ module Arel
964
981
  manager.source.must_equal manager.ast.cores.last.source
965
982
  end
966
983
  end
984
+
985
+ describe 'distinct' do
986
+ it 'sets the quantifier' do
987
+ table = Table.new :users
988
+ manager = Arel::SelectManager.new Table.engine
989
+
990
+ manager.distinct
991
+ manager.ast.cores.last.set_quantifier.class.must_equal Arel::Nodes::Distinct
992
+
993
+ manager.distinct(false)
994
+ manager.ast.cores.last.set_quantifier.must_equal nil
995
+ end
996
+ end
967
997
  end
968
998
  end
@@ -143,6 +143,13 @@ module Arel
143
143
  ( SELECT * FROM users WHERE age > 10 MINUS SELECT * FROM users WHERE age > 20 )
144
144
  }
145
145
  end
146
+
147
+ describe 'locking' do
148
+ it 'defaults to FOR UPDATE when locking' do
149
+ node = Nodes::Lock.new(Arel.sql('FOR UPDATE'))
150
+ @visitor.accept(node).must_be_like "FOR UPDATE"
151
+ end
152
+ end
146
153
  end
147
154
  end
148
155
  end
@@ -13,6 +13,11 @@ module Arel
13
13
  sql = @visitor.accept(stmt)
14
14
  sql.must_be_like "SELECT LIMIT -1 OFFSET 1"
15
15
  end
16
+
17
+ it 'does not support locking' do
18
+ node = Nodes::Lock.new(Arel.sql('FOR UPDATE'))
19
+ @visitor.accept(node).must_be_nil
20
+ end
16
21
  end
17
22
  end
18
23
  end
@@ -13,6 +13,12 @@ module Arel
13
13
  @attr = @table[:id]
14
14
  end
15
15
 
16
+ it 'works with BindParams' do
17
+ node = Nodes::BindParam.new 'omg'
18
+ sql = @visitor.accept node
19
+ sql.must_be_like 'omg'
20
+ end
21
+
16
22
  it 'can define a dispatch method' do
17
23
  visited = false
18
24
  viz = Class.new(Arel::Visitors::Visitor) {
metadata CHANGED
@@ -1,14 +1,10 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: arel
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 2
7
- - 2
8
- - 1
9
- version: 2.2.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.2.2
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Aaron Patterson
13
9
  - Bryan Halmkamp
14
10
  - Emilio Tagua
@@ -16,60 +12,67 @@ authors:
16
12
  autorequire:
17
13
  bindir: bin
18
14
  cert_chain: []
19
-
20
- date: 2011-08-15 00:00:00 -07:00
21
- default_executable:
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
15
+ date: 2012-02-21 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
24
18
  name: minitest
19
+ requirement: &70233423420200 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '2.11'
25
+ type: :development
25
26
  prerelease: false
26
- requirement: &id001 !ruby/object:Gem::Requirement
27
- requirements:
27
+ version_requirements: *70233423420200
28
+ - !ruby/object:Gem::Dependency
29
+ name: rdoc
30
+ requirement: &70233423415720 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
28
33
  - - ~>
29
- - !ruby/object:Gem::Version
30
- segments:
31
- - 2
32
- - 3
33
- version: "2.3"
34
+ - !ruby/object:Gem::Version
35
+ version: '3.10'
34
36
  type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: hoe
38
37
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- requirements:
38
+ version_requirements: *70233423415720
39
+ - !ruby/object:Gem::Dependency
40
+ name: hoe
41
+ requirement: &70233423403440 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
41
44
  - - ~>
42
- - !ruby/object:Gem::Version
43
- segments:
44
- - 2
45
- - 9
46
- version: "2.9"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.13'
47
47
  type: :development
48
- version_requirements: *id002
49
- description: |-
50
- Arel is a SQL AST manager for Ruby. It
51
-
52
- 1. Simplifies the generation complex of SQL queries
48
+ prerelease: false
49
+ version_requirements: *70233423403440
50
+ description: ! 'Arel is a SQL AST manager for Ruby. It
51
+
52
+
53
+ 1. Simplifies the generation of complex SQL queries
54
+
53
55
  2. Adapts to various RDBMS systems
54
-
56
+
57
+
55
58
  It is intended to be a framework framework; that is, you can build your own ORM
59
+
56
60
  with it, focusing on innovative object and collection modeling as opposed to
57
- database compatibility and query generation.
58
- email:
61
+
62
+ database compatibility and query generation.'
63
+ email:
59
64
  - aaron@tenderlovemaking.com
60
65
  - bryan@brynary.com
61
66
  - miloops@gmail.com
62
67
  - nick@example.org
63
68
  executables: []
64
-
65
69
  extensions: []
66
-
67
- extra_rdoc_files:
70
+ extra_rdoc_files:
68
71
  - History.txt
69
72
  - MIT-LICENSE.txt
70
73
  - Manifest.txt
71
74
  - README.markdown
72
- files:
75
+ files:
73
76
  - .autotest
74
77
  - .gemtest
75
78
  - .travis.yml
@@ -189,38 +192,33 @@ files:
189
192
  - test/visitors/test_postgres.rb
190
193
  - test/visitors/test_sqlite.rb
191
194
  - test/visitors/test_to_sql.rb
192
- has_rdoc: true
193
195
  homepage: http://github.com/rails/arel
194
196
  licenses: []
195
-
196
197
  post_install_message:
197
- rdoc_options:
198
+ rdoc_options:
198
199
  - --main
199
200
  - README.markdown
200
- require_paths:
201
+ require_paths:
201
202
  - lib
202
- required_ruby_version: !ruby/object:Gem::Requirement
203
- requirements:
204
- - - ">="
205
- - !ruby/object:Gem::Version
206
- segments:
207
- - 0
208
- version: "0"
209
- required_rubygems_version: !ruby/object:Gem::Requirement
210
- requirements:
211
- - - ">="
212
- - !ruby/object:Gem::Version
213
- segments:
214
- - 0
215
- version: "0"
203
+ required_ruby_version: !ruby/object:Gem::Requirement
204
+ none: false
205
+ requirements:
206
+ - - ! '>='
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
210
+ none: false
211
+ requirements:
212
+ - - ! '>='
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
216
215
  requirements: []
217
-
218
216
  rubyforge_project: arel
219
- rubygems_version: 1.3.6
217
+ rubygems_version: 1.8.11
220
218
  signing_key:
221
219
  specification_version: 3
222
220
  summary: Arel is a SQL AST manager for Ruby
223
- test_files:
221
+ test_files:
224
222
  - test/attributes/test_attribute.rb
225
223
  - test/nodes/test_as.rb
226
224
  - test/nodes/test_ascending.rb