arel 3.0.0 → 3.0.3

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/Gemfile CHANGED
@@ -2,10 +2,11 @@
2
2
 
3
3
  # DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
4
4
 
5
- source :gemcutter
5
+ source "https://rubygems.org/"
6
6
 
7
7
 
8
- gem "minitest", "~>2.2", :group => [:development, :test]
9
- gem "hoe", "~>2.10", :group => [:development, :test]
8
+ gem "minitest", "~>4.7", :group => [:development, :test]
9
+ gem "rdoc", "~>4.0", :group => [:development, :test]
10
+ gem "hoe", "~>3.6", :group => [:development, :test]
10
11
 
11
12
  # vim: syntax=ruby
data/History.txt CHANGED
@@ -1,3 +1,54 @@
1
+ == 3.0.3 / 2013-11-12
2
+
3
+ * Enhancements
4
+
5
+ * Support ANSI 2003 window functions
6
+
7
+ * Bug Fixes
8
+
9
+ * Fix joins in Informix
10
+
11
+ == 3.0.2 / 2012-02-21
12
+
13
+ * Enhancements
14
+
15
+ * Added a module for visiting and transforming bind values
16
+ * Fix in [] to be false, not in [] to be true
17
+
18
+ * Bug Fixes
19
+
20
+ * Revert fix for LIMIT / OFFSET when query is ordered in Oracle
21
+
22
+ == 3.0.1 / 2012-02-17
23
+
24
+ * Bug Fixes
25
+
26
+ * Fixed LIMIT / OFFSET when query is ordered in Oracle
27
+
28
+ == 3.0.0 / 2012-01-12
29
+
30
+ * Enhancements
31
+
32
+ * Support connection pool and schema cache
33
+
34
+ * Bug Fixes
35
+
36
+ * Conditions with no column can be followed by other conditions in Postgres
37
+
38
+ == 2.2.3 / 2012-02-21
39
+
40
+ * Enhancements
41
+
42
+ * Added a module for visiting and transforming bind values
43
+
44
+ == 2.2.2 / 2012-02-20
45
+
46
+ * Enhancements
47
+
48
+ * Support LOCK
49
+ * Allow using non-table alias as a right-hand relation name
50
+ * Added SelectManager#distinct
51
+
1
52
  == 2.2.1 / 2011-09-15
2
53
 
3
54
  * Enhancements
data/Manifest.txt CHANGED
@@ -29,6 +29,7 @@ lib/arel/nodes/count.rb
29
29
  lib/arel/nodes/delete_statement.rb
30
30
  lib/arel/nodes/descending.rb
31
31
  lib/arel/nodes/equality.rb
32
+ lib/arel/nodes/extract.rb
32
33
  lib/arel/nodes/false.rb
33
34
  lib/arel/nodes/function.rb
34
35
  lib/arel/nodes/in.rb
@@ -40,6 +41,7 @@ lib/arel/nodes/named_function.rb
40
41
  lib/arel/nodes/node.rb
41
42
  lib/arel/nodes/ordering.rb
42
43
  lib/arel/nodes/outer_join.rb
44
+ lib/arel/nodes/over.rb
43
45
  lib/arel/nodes/select_core.rb
44
46
  lib/arel/nodes/select_statement.rb
45
47
  lib/arel/nodes/sql_literal.rb
@@ -51,6 +53,7 @@ lib/arel/nodes/unary.rb
51
53
  lib/arel/nodes/unqualified_column.rb
52
54
  lib/arel/nodes/update_statement.rb
53
55
  lib/arel/nodes/values.rb
56
+ lib/arel/nodes/window.rb
54
57
  lib/arel/nodes/with.rb
55
58
  lib/arel/order_predications.rb
56
59
  lib/arel/predications.rb
@@ -62,6 +65,7 @@ lib/arel/table.rb
62
65
  lib/arel/tree_manager.rb
63
66
  lib/arel/update_manager.rb
64
67
  lib/arel/visitors.rb
68
+ lib/arel/visitors/bind_visitor.rb
65
69
  lib/arel/visitors/depth_first.rb
66
70
  lib/arel/visitors/dot.rb
67
71
  lib/arel/visitors/ibm_db.rb
@@ -76,6 +80,7 @@ lib/arel/visitors/sqlite.rb
76
80
  lib/arel/visitors/to_sql.rb
77
81
  lib/arel/visitors/visitor.rb
78
82
  lib/arel/visitors/where_sql.rb
83
+ lib/arel/window_predications.rb
79
84
  test/attributes/test_attribute.rb
80
85
  test/helper.rb
81
86
  test/nodes/test_as.rb
@@ -85,12 +90,14 @@ test/nodes/test_count.rb
85
90
  test/nodes/test_delete_statement.rb
86
91
  test/nodes/test_descending.rb
87
92
  test/nodes/test_equality.rb
93
+ test/nodes/test_extract.rb
88
94
  test/nodes/test_infix_operation.rb
89
95
  test/nodes/test_insert_statement.rb
90
96
  test/nodes/test_named_function.rb
91
97
  test/nodes/test_node.rb
92
98
  test/nodes/test_not.rb
93
99
  test/nodes/test_or.rb
100
+ test/nodes/test_over.rb
94
101
  test/nodes/test_select_core.rb
95
102
  test/nodes/test_select_statement.rb
96
103
  test/nodes/test_sql_literal.rb
@@ -106,6 +113,7 @@ test/test_insert_manager.rb
106
113
  test/test_select_manager.rb
107
114
  test/test_table.rb
108
115
  test/test_update_manager.rb
116
+ test/visitors/test_bind_visitor.rb
109
117
  test/visitors/test_depth_first.rb
110
118
  test/visitors/test_dot.rb
111
119
  test/visitors/test_ibm_db.rb
data/README.markdown CHANGED
@@ -83,7 +83,7 @@ The examples above are fairly simple and other libraries match or come close to
83
83
 
84
84
  #### Inline math operations
85
85
 
86
- 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:
86
+ 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
87
 
88
88
  products = Arel::Table.new(:products)
89
89
  products.columns # => [products[:id], products[:name], products[:price], products[:currency_id]]
data/arel.gemspec CHANGED
@@ -1,36 +1,47 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = "arel"
5
- s.version = "3.0.0.20120112113618"
4
+ s.name = %q{arel}
5
+ s.version = "3.0.3.20131114190737"
6
6
 
7
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 = "2012-01-12"
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."
9
+ s.date = %q{2013-11-14}
10
+ s.description = %q{Arel is a SQL AST manager for Ruby. It
11
+
12
+ 1. Simplifies the generation of complex 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.}
11
18
  s.email = ["aaron@tenderlovemaking.com", "bryan@brynary.com", "miloops@gmail.com", "nick@example.org"]
12
19
  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"
20
+ 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/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/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/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/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_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_extract.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_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_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.homepage = %q{http://github.com/rails/arel}
22
+ s.licenses = ["MIT"]
15
23
  s.rdoc_options = ["--main", "README.markdown"]
16
24
  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"]
25
+ s.rubyforge_project = %q{arel}
26
+ s.rubygems_version = %q{1.6.2}
27
+ s.summary = %q{Arel is a SQL AST manager for Ruby}
28
+ 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_extract.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_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_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
29
 
22
30
  if s.respond_to? :specification_version then
23
31
  s.specification_version = 3
24
32
 
25
33
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_development_dependency(%q<hoe>, ["~> 2.12"])
27
- s.add_development_dependency(%q<rdoc>, ["~> 3.10"])
34
+ s.add_development_dependency(%q<minitest>, ["~> 4.7"])
35
+ s.add_development_dependency(%q<rdoc>, ["~> 4.0"])
36
+ s.add_development_dependency(%q<hoe>, ["~> 3.7"])
28
37
  else
29
- s.add_dependency(%q<hoe>, ["~> 2.12"])
30
- s.add_dependency(%q<rdoc>, ["~> 3.10"])
38
+ s.add_dependency(%q<minitest>, ["~> 4.7"])
39
+ s.add_dependency(%q<rdoc>, ["~> 4.0"])
40
+ s.add_dependency(%q<hoe>, ["~> 3.7"])
31
41
  end
32
42
  else
33
- s.add_dependency(%q<hoe>, ["~> 2.12"])
34
- s.add_dependency(%q<rdoc>, ["~> 3.10"])
43
+ s.add_dependency(%q<minitest>, ["~> 4.7"])
44
+ s.add_dependency(%q<rdoc>, ["~> 4.0"])
45
+ s.add_dependency(%q<hoe>, ["~> 3.7"])
35
46
  end
36
47
  end
data/lib/arel.rb CHANGED
@@ -3,6 +3,7 @@ require 'arel/factory_methods'
3
3
 
4
4
  require 'arel/expressions'
5
5
  require 'arel/predications'
6
+ require 'arel/window_predications'
6
7
  require 'arel/math'
7
8
  require 'arel/alias_predication'
8
9
  require 'arel/order_predications'
@@ -33,7 +34,7 @@ require 'arel/sql_literal'
33
34
  ####
34
35
 
35
36
  module Arel
36
- VERSION = '3.0.0'
37
+ VERSION = '3.0.3'
37
38
 
38
39
  def self.sql raw_sql
39
40
  Arel::Nodes::SqlLiteral.new raw_sql
@@ -19,5 +19,9 @@ module Arel
19
19
  def average
20
20
  Nodes::Avg.new [self], Nodes::SqlLiteral.new('avg_id')
21
21
  end
22
+
23
+ def extract field
24
+ Nodes::Extract.new [self], field
25
+ end
22
26
  end
23
27
  end
data/lib/arel/nodes.rb CHANGED
@@ -26,6 +26,7 @@ require 'arel/nodes/join_source'
26
26
  require 'arel/nodes/delete_statement'
27
27
  require 'arel/nodes/table_alias'
28
28
  require 'arel/nodes/infix_operation'
29
+ require 'arel/nodes/over'
29
30
 
30
31
  # nary
31
32
  require 'arel/nodes/and'
@@ -35,9 +36,13 @@ require 'arel/nodes/and'
35
36
  # We should make Function a Unary node and deprecate the use of "aliaz"
36
37
  require 'arel/nodes/function'
37
38
  require 'arel/nodes/count'
39
+ require 'arel/nodes/extract'
38
40
  require 'arel/nodes/values'
39
41
  require 'arel/nodes/named_function'
40
42
 
43
+ # windows
44
+ require 'arel/nodes/window'
45
+
41
46
  # joins
42
47
  require 'arel/nodes/inner_join'
43
48
  require 'arel/nodes/outer_join'
@@ -0,0 +1,23 @@
1
+ module Arel
2
+ module Nodes
3
+
4
+ class Extract < Arel::Nodes::Unary
5
+ include Arel::Expression
6
+ include Arel::Predications
7
+
8
+ attr_accessor :field
9
+ attr_accessor :alias
10
+
11
+ def initialize expr, field, aliaz = nil
12
+ super(expr)
13
+ @field = field
14
+ @alias = aliaz && SqlLiteral.new(aliaz)
15
+ end
16
+
17
+ def as aliaz
18
+ self.alias = SqlLiteral.new(aliaz)
19
+ self
20
+ end
21
+ end
22
+ end
23
+ end
@@ -3,6 +3,7 @@ module Arel
3
3
  class Function < Arel::Nodes::Node
4
4
  include Arel::Expression
5
5
  include Arel::Predications
6
+ include Arel::WindowPredications
6
7
  attr_accessor :expressions, :alias, :distinct
7
8
 
8
9
  def initialize expr, aliaz = nil
@@ -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
@@ -0,0 +1,15 @@
1
+ module Arel
2
+ module Nodes
3
+
4
+ class Over < Binary
5
+ include Arel::AliasPredication
6
+
7
+ def initialize(left, right = nil)
8
+ super(left, right)
9
+ end
10
+
11
+ def operator; 'OVER' end
12
+ end
13
+
14
+ end
15
+ end
@@ -1,7 +1,7 @@
1
1
  module Arel
2
2
  module Nodes
3
3
  class SelectCore < Arel::Nodes::Node
4
- attr_accessor :top, :projections, :wheres, :groups
4
+ attr_accessor :top, :projections, :wheres, :groups, :windows
5
5
  attr_accessor :having, :source, :set_quantifier
6
6
 
7
7
  def initialize
@@ -14,6 +14,7 @@ module Arel
14
14
  @wheres = []
15
15
  @groups = []
16
16
  @having = nil
17
+ @windows = []
17
18
  end
18
19
 
19
20
  def from
@@ -34,6 +35,7 @@ module Arel
34
35
  @wheres = @wheres.clone
35
36
  @groups = @groups.clone
36
37
  @having = @having.clone if @having
38
+ @windows = @windows.clone
37
39
  end
38
40
  end
39
41
  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
@@ -0,0 +1,78 @@
1
+ module Arel
2
+ module Nodes
3
+ class Window < Arel::Nodes::Node
4
+ include Arel::Expression
5
+ attr_accessor :orders, :framing
6
+
7
+ def initialize
8
+ @orders = []
9
+ end
10
+
11
+ def order *expr
12
+ # FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
13
+ @orders.concat expr.map { |x|
14
+ String === x || Symbol === x ? Nodes::SqlLiteral.new(x.to_s) : x
15
+ }
16
+ self
17
+ end
18
+
19
+ def frame(expr)
20
+ raise ArgumentError, "Window frame cannot be set more than once" if @frame
21
+ @framing = expr
22
+ end
23
+
24
+ def rows(expr = nil)
25
+ frame(Rows.new(expr))
26
+ end
27
+
28
+ def range(expr = nil)
29
+ frame(Range.new(expr))
30
+ end
31
+
32
+ def initialize_copy other
33
+ super
34
+ @orders = @orders.map { |x| x.clone }
35
+ end
36
+ end
37
+
38
+ class NamedWindow < Window
39
+ attr_accessor :name
40
+
41
+ def initialize name
42
+ super()
43
+ @name = name
44
+ end
45
+
46
+ def initialize_copy other
47
+ super
48
+ @name = other.name.clone
49
+ end
50
+ end
51
+
52
+ class Rows < Unary
53
+ def initialize(expr = nil)
54
+ super(expr)
55
+ end
56
+ end
57
+
58
+ class Range < Unary
59
+ def initialize(expr = nil)
60
+ super(expr)
61
+ end
62
+ end
63
+
64
+ class CurrentRow < Arel::Nodes::Node; end
65
+
66
+ class Preceding < Unary
67
+ def initialize(expr = nil)
68
+ super(expr)
69
+ end
70
+ end
71
+
72
+ class Following < Unary
73
+ def initialize(expr = nil)
74
+ super(expr)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -126,6 +126,12 @@ module Arel
126
126
  self
127
127
  end
128
128
 
129
+ def window name
130
+ window = Nodes::NamedWindow.new(name)
131
+ @ctx.windows.push window
132
+ window
133
+ end
134
+
129
135
  def project *projections
130
136
  # FIXME: converting these to SQLLiterals is probably not good, but
131
137
  # rails tests require it.