arel 2.0.10 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/History.txt +51 -4
  2. data/Manifest.txt +15 -31
  3. data/README.markdown +27 -3
  4. data/Rakefile +0 -2
  5. data/arel.gemspec +20 -19
  6. data/lib/arel.rb +9 -1
  7. data/lib/arel/alias_predication.rb +7 -0
  8. data/lib/arel/attributes/attribute.rb +10 -1
  9. data/lib/arel/crud.rb +43 -8
  10. data/lib/arel/expression.rb +1 -0
  11. data/lib/arel/factory_methods.rb +35 -0
  12. data/lib/arel/insert_manager.rb +5 -1
  13. data/lib/arel/math.rb +19 -0
  14. data/lib/arel/nodes.rb +32 -42
  15. data/lib/arel/nodes/and.rb +18 -1
  16. data/lib/arel/nodes/binary.rb +28 -0
  17. data/lib/arel/nodes/count.rb +0 -3
  18. data/lib/arel/nodes/function.rb +13 -2
  19. data/lib/arel/nodes/infix_operation.rb +43 -0
  20. data/lib/arel/nodes/join_source.rb +14 -0
  21. data/lib/arel/nodes/named_function.rb +14 -0
  22. data/lib/arel/nodes/node.rb +5 -2
  23. data/lib/arel/nodes/select_core.rb +24 -10
  24. data/lib/arel/nodes/select_statement.rb +8 -6
  25. data/lib/arel/nodes/sql_literal.rb +2 -0
  26. data/lib/arel/nodes/string_join.rb +2 -4
  27. data/lib/arel/nodes/table_alias.rb +7 -3
  28. data/lib/arel/nodes/{as.rb → terminal.rb} +1 -1
  29. data/lib/arel/nodes/unary.rb +17 -0
  30. data/lib/arel/nodes/unqualified_column.rb +4 -0
  31. data/lib/arel/nodes/update_statement.rb +4 -2
  32. data/lib/arel/nodes/with.rb +10 -0
  33. data/lib/arel/order_predications.rb +13 -0
  34. data/lib/arel/predications.rb +6 -24
  35. data/lib/arel/select_manager.rb +95 -40
  36. data/lib/arel/table.rb +32 -19
  37. data/lib/arel/tree_manager.rb +1 -0
  38. data/lib/arel/update_manager.rb +4 -0
  39. data/lib/arel/visitors.rb +2 -0
  40. data/lib/arel/visitors/depth_first.rb +19 -9
  41. data/lib/arel/visitors/dot.rb +42 -25
  42. data/lib/arel/visitors/ibm_db.rb +12 -0
  43. data/lib/arel/visitors/join_sql.rb +2 -23
  44. data/lib/arel/visitors/mssql.rb +7 -0
  45. data/lib/arel/visitors/mysql.rb +4 -0
  46. data/lib/arel/visitors/oracle.rb +2 -2
  47. data/lib/arel/visitors/postgresql.rb +2 -38
  48. data/lib/arel/visitors/to_sql.rb +148 -67
  49. data/test/attributes/test_attribute.rb +3 -3
  50. data/test/helper.rb +1 -1
  51. data/test/nodes/test_as.rb +6 -0
  52. data/test/nodes/test_bin.rb +23 -0
  53. data/test/nodes/test_named_function.rb +30 -0
  54. data/test/nodes/test_node.rb +10 -0
  55. data/test/nodes/test_not.rb +4 -7
  56. data/test/nodes/test_select_core.rb +23 -14
  57. data/test/support/fake_record.rb +21 -4
  58. data/test/test_attributes.rb +8 -0
  59. data/test/test_crud.rb +6 -12
  60. data/test/test_factory_methods.rb +34 -0
  61. data/test/test_insert_manager.rb +19 -0
  62. data/test/test_select_manager.rb +343 -64
  63. data/test/test_table.rb +36 -45
  64. data/test/visitors/test_depth_first.rb +29 -11
  65. data/test/visitors/test_dot.rb +47 -0
  66. data/test/visitors/test_ibm_db.rb +27 -0
  67. data/test/visitors/test_join_sql.rb +14 -7
  68. data/test/visitors/test_mssql.rb +9 -0
  69. data/test/visitors/test_oracle.rb +11 -10
  70. data/test/visitors/test_postgres.rb +12 -0
  71. data/test/visitors/test_to_sql.rb +80 -17
  72. metadata +80 -101
  73. data/lib/arel/nodes/assignment.rb +0 -6
  74. data/lib/arel/nodes/avg.rb +0 -6
  75. data/lib/arel/nodes/between.rb +0 -6
  76. data/lib/arel/nodes/does_not_match.rb +0 -6
  77. data/lib/arel/nodes/except.rb +0 -7
  78. data/lib/arel/nodes/exists.rb +0 -7
  79. data/lib/arel/nodes/greater_than.rb +0 -6
  80. data/lib/arel/nodes/greater_than_or_equal.rb +0 -6
  81. data/lib/arel/nodes/group.rb +0 -6
  82. data/lib/arel/nodes/grouping.rb +0 -6
  83. data/lib/arel/nodes/having.rb +0 -6
  84. data/lib/arel/nodes/intersect.rb +0 -7
  85. data/lib/arel/nodes/join.rb +0 -13
  86. data/lib/arel/nodes/less_than.rb +0 -6
  87. data/lib/arel/nodes/less_than_or_equal.rb +0 -6
  88. data/lib/arel/nodes/limit.rb +0 -7
  89. data/lib/arel/nodes/lock.rb +0 -6
  90. data/lib/arel/nodes/matches.rb +0 -6
  91. data/lib/arel/nodes/max.rb +0 -6
  92. data/lib/arel/nodes/min.rb +0 -6
  93. data/lib/arel/nodes/not.rb +0 -6
  94. data/lib/arel/nodes/not_equal.rb +0 -6
  95. data/lib/arel/nodes/not_in.rb +0 -6
  96. data/lib/arel/nodes/offset.rb +0 -7
  97. data/lib/arel/nodes/on.rb +0 -6
  98. data/lib/arel/nodes/or.rb +0 -6
  99. data/lib/arel/nodes/sum.rb +0 -6
  100. data/lib/arel/nodes/top.rb +0 -6
  101. data/lib/arel/nodes/union.rb +0 -7
  102. data/lib/arel/nodes/union_all.rb +0 -7
@@ -1,9 +1,56 @@
1
- == 2.0.10 / 2011/05/14
1
+ == 2.1.0 / 2011/04/30
2
2
 
3
- * Bug Fixes
3
+ * Enhancements
4
+
5
+ * AST is now Enumerable
6
+ * AND nodes are now n-ary nodes
7
+ * SQL Literals may be used as Attribute names
8
+ * Added Arel::Nodes::NamedFunction for representing generic SQL functions
9
+ * Add Arel::SelectManager#limit=
10
+ * Add Arel::SelectManager#offset
11
+ * Add Arel::SelectManager#offset=
12
+ * Added Arel::SelectManager#create_insert for building an insert manager.
13
+ * SQL Literals are allowed for values in INSERT statements.
14
+ * Math operations have been added to attributes, thanks to
15
+ Vladimir Meremyanin.
16
+
17
+ * Bug fixes
18
+
19
+ * MSSQL adds TOP to sub selects
20
+ * Assigning nil to take() removes LIMIT from statement.
21
+ * Assigning nil to offset() removes OFFSET from statement.
22
+ * TableAlias leg ordering fixed
23
+
24
+ * Deprecations
25
+
26
+ * Calls to `insert` are deprecated. Please use `compile_insert` then call
27
+ `to_sql` on the resulting object and execute that SQL.
28
+
29
+ * Calls to `update` are deprecated. Please use `compile_update` then call
30
+ `to_sql` on the resulting object and execute that SQL.
31
+
32
+ * Calls to `delete` are deprecated. Please use `compile_delete` then call
33
+ `to_sql` on the resulting object and execute that SQL.
34
+
35
+ * Arel::Table#joins is deprecated and will be removed in 3.0.0 with no
36
+ replacement.
37
+
38
+ * Arel::Table#columns is deprecated and will be removed in 3.0.0 with no
39
+ replacement.
40
+
41
+ * Arel::Table.table_cache is deprecated and will be removed in 3.0.0 with no
42
+ replacement.
43
+
44
+ * Arel::Nodes::And.new takes a single list instead of left and right.
45
+
46
+ * Arel::Table#primary_key is deprecated and will be removed in 3.0.0 with no
47
+ replacement.
48
+
49
+ * Arel::SelectManager#where_clauses is deprecated and will be removed in
50
+ 3.0.0 with no replacement.
4
51
 
5
- * Fix thread safety issue in ToSql visitor. Thanks Damon McCormick and
6
- Cameron Walters!
52
+ * Arel::SelectManager#wheres is deprecated and will be removed in
53
+ 3.0.0 with no replacement.
7
54
 
8
55
  == 2.0.9 / 2010/02/25
9
56
 
@@ -1,4 +1,5 @@
1
1
  .autotest
2
+ .gemtest
2
3
  History.txt
3
4
  MIT-LICENSE.txt
4
5
  Manifest.txt
@@ -6,6 +7,7 @@ README.markdown
6
7
  Rakefile
7
8
  arel.gemspec
8
9
  lib/arel.rb
10
+ lib/arel/alias_predication.rb
9
11
  lib/arel/attributes.rb
10
12
  lib/arel/attributes/attribute.rb
11
13
  lib/arel/compatibility/wheres.rb
@@ -14,60 +16,37 @@ lib/arel/delete_manager.rb
14
16
  lib/arel/deprecated.rb
15
17
  lib/arel/expression.rb
16
18
  lib/arel/expressions.rb
19
+ lib/arel/factory_methods.rb
17
20
  lib/arel/insert_manager.rb
21
+ lib/arel/math.rb
18
22
  lib/arel/nodes.rb
19
23
  lib/arel/nodes/and.rb
20
- lib/arel/nodes/as.rb
21
- lib/arel/nodes/assignment.rb
22
- lib/arel/nodes/avg.rb
23
- lib/arel/nodes/between.rb
24
24
  lib/arel/nodes/binary.rb
25
25
  lib/arel/nodes/count.rb
26
26
  lib/arel/nodes/delete_statement.rb
27
- lib/arel/nodes/does_not_match.rb
28
27
  lib/arel/nodes/equality.rb
29
- lib/arel/nodes/except.rb
30
- lib/arel/nodes/exists.rb
31
28
  lib/arel/nodes/function.rb
32
- lib/arel/nodes/greater_than.rb
33
- lib/arel/nodes/greater_than_or_equal.rb
34
- lib/arel/nodes/group.rb
35
- lib/arel/nodes/grouping.rb
36
- lib/arel/nodes/having.rb
37
29
  lib/arel/nodes/in.rb
30
+ lib/arel/nodes/infix_operation.rb
38
31
  lib/arel/nodes/inner_join.rb
39
32
  lib/arel/nodes/insert_statement.rb
40
- lib/arel/nodes/intersect.rb
41
- lib/arel/nodes/join.rb
42
- lib/arel/nodes/less_than.rb
43
- lib/arel/nodes/less_than_or_equal.rb
44
- lib/arel/nodes/limit.rb
45
- lib/arel/nodes/lock.rb
46
- lib/arel/nodes/matches.rb
47
- lib/arel/nodes/max.rb
48
- lib/arel/nodes/min.rb
33
+ lib/arel/nodes/join_source.rb
34
+ lib/arel/nodes/named_function.rb
49
35
  lib/arel/nodes/node.rb
50
- lib/arel/nodes/not.rb
51
- lib/arel/nodes/not_equal.rb
52
- lib/arel/nodes/not_in.rb
53
- lib/arel/nodes/offset.rb
54
- lib/arel/nodes/on.rb
55
- lib/arel/nodes/or.rb
56
36
  lib/arel/nodes/ordering.rb
57
37
  lib/arel/nodes/outer_join.rb
58
38
  lib/arel/nodes/select_core.rb
59
39
  lib/arel/nodes/select_statement.rb
60
40
  lib/arel/nodes/sql_literal.rb
61
41
  lib/arel/nodes/string_join.rb
62
- lib/arel/nodes/sum.rb
63
42
  lib/arel/nodes/table_alias.rb
64
- lib/arel/nodes/top.rb
43
+ lib/arel/nodes/terminal.rb
65
44
  lib/arel/nodes/unary.rb
66
- lib/arel/nodes/union.rb
67
- lib/arel/nodes/union_all.rb
68
45
  lib/arel/nodes/unqualified_column.rb
69
46
  lib/arel/nodes/update_statement.rb
70
47
  lib/arel/nodes/values.rb
48
+ lib/arel/nodes/with.rb
49
+ lib/arel/order_predications.rb
71
50
  lib/arel/predications.rb
72
51
  lib/arel/relation.rb
73
52
  lib/arel/select_manager.rb
@@ -79,6 +58,7 @@ lib/arel/update_manager.rb
79
58
  lib/arel/visitors.rb
80
59
  lib/arel/visitors/depth_first.rb
81
60
  lib/arel/visitors/dot.rb
61
+ lib/arel/visitors/ibm_db.rb
82
62
  lib/arel/visitors/join_sql.rb
83
63
  lib/arel/visitors/mssql.rb
84
64
  lib/arel/visitors/mysql.rb
@@ -92,10 +72,12 @@ lib/arel/visitors/where_sql.rb
92
72
  test/attributes/test_attribute.rb
93
73
  test/helper.rb
94
74
  test/nodes/test_as.rb
75
+ test/nodes/test_bin.rb
95
76
  test/nodes/test_count.rb
96
77
  test/nodes/test_delete_statement.rb
97
78
  test/nodes/test_equality.rb
98
79
  test/nodes/test_insert_statement.rb
80
+ test/nodes/test_named_function.rb
99
81
  test/nodes/test_node.rb
100
82
  test/nodes/test_not.rb
101
83
  test/nodes/test_or.rb
@@ -109,12 +91,14 @@ test/test_activerecord_compat.rb
109
91
  test/test_attributes.rb
110
92
  test/test_crud.rb
111
93
  test/test_delete_manager.rb
94
+ test/test_factory_methods.rb
112
95
  test/test_insert_manager.rb
113
96
  test/test_select_manager.rb
114
97
  test/test_table.rb
115
98
  test/test_update_manager.rb
116
99
  test/visitors/test_depth_first.rb
117
100
  test/visitors/test_dot.rb
101
+ test/visitors/test_ibm_db.rb
118
102
  test/visitors/test_join_sql.rb
119
103
  test/visitors/test_mssql.rb
120
104
  test/visitors/test_mysql.rb
@@ -4,7 +4,14 @@
4
4
 
5
5
  ## DESCRIPTION
6
6
 
7
- 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.
7
+ Arel is a SQL AST manager for Ruby. It
8
+
9
+ 1. Simplifies the generation complex of SQL queries
10
+ 2. Adapts to various RDBMS systems
11
+
12
+ It is intended to be a framework framework; that is, you can build your own ORM
13
+ with it, focusing on innovative object and collection modeling as opposed to
14
+ database compatibility and query generation.
8
15
 
9
16
  ## Status
10
17
 
@@ -19,8 +26,8 @@ Generating a query with ARel is simple. For example, in order to produce
19
26
  you construct a table relation and convert it to sql:
20
27
 
21
28
  users = Arel::Table.new(:users)
22
- users.project(Arel.sql('*'))
23
- users.to_sql
29
+ query = users.project(Arel.sql('*'))
30
+ query.to_sql
24
31
 
25
32
  ### More Sophisticated Queries
26
33
 
@@ -74,6 +81,23 @@ The `AND` operator behaves similarly.
74
81
 
75
82
  The examples above are fairly simple and other libraries match or come close to matching the expressiveness of Arel (e.g., `Sequel` in Ruby).
76
83
 
84
+ #### Inline math operations
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:
87
+
88
+ products = Arel::Table.new(:products)
89
+ products.columns # => [products[:id], products[:name], products[:price], products[:currency_id]]
90
+
91
+ currency_rates = Arel::Table.new(:currency_rates)
92
+ currency_rates.columns # => [currency_rates[:from_id], currency_rates[:to_id], currency_rates[:date], currency_rates[:rate]]
93
+
94
+ Now, to order products by price in user preferred currency simply call:
95
+
96
+ products.
97
+ join(:currency_rates).on(products[:currency_id].eq(currency_rates[:from_id])).
98
+ where(currency_rates[:to_id].eq(user_preferred_currency), currency_rates[:date].eq(Date.today)).
99
+ order(products[:price] * currency_rates[:rate])
100
+
77
101
  #### Complex Joins
78
102
 
79
103
  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:
data/Rakefile CHANGED
@@ -15,6 +15,4 @@ Hoe.spec 'arel' do
15
15
 
16
16
  self.readme_file = 'README.markdown'
17
17
  self.extra_rdoc_files = FileList['README.markdown']
18
- self.extra_dev_deps << [ 'hoe', '>= 2.1.0' ]
19
- self.extra_dev_deps << [ 'minitest', '>= 1.6.0' ]
20
18
  end
@@ -2,41 +2,42 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{arel}
5
- s.version = "2.0.9.20110222133018"
5
+ s.version = "2.1.0.20110430172428"
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 = %q{2011-02-22}
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.}
9
+ s.date = %q{2011-04-30}
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.}
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", "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"]
20
+ s.files = [".autotest", ".gemtest", "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/binary.rb", "lib/arel/nodes/count.rb", "lib/arel/nodes/delete_statement.rb", "lib/arel/nodes/equality.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/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/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_bin.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_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_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
21
  s.homepage = %q{http://github.com/rails/arel}
15
22
  s.rdoc_options = ["--main", "README.markdown"]
16
23
  s.require_paths = ["lib"]
17
24
  s.rubyforge_project = %q{arel}
18
- s.rubygems_version = %q{1.5.0}
19
- s.summary = %q{Arel is a Relational Algebra for Ruby}
20
- s.test_files = ["test/attributes/test_attribute.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/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"]
25
+ s.rubygems_version = %q{1.6.1}
26
+ s.summary = %q{Arel is a SQL AST manager for Ruby}
27
+ s.test_files = ["test/attributes/test_attribute.rb", "test/nodes/test_as.rb", "test/nodes/test_bin.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_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_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
28
 
22
29
  if s.respond_to? :specification_version then
23
30
  s.specification_version = 3
24
31
 
25
32
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_development_dependency(%q<minitest>, [">= 2.0.0"])
27
- s.add_development_dependency(%q<hoe>, [">= 2.1.0"])
28
- s.add_development_dependency(%q<minitest>, [">= 1.6.0"])
29
- s.add_development_dependency(%q<hoe>, [">= 2.8.0"])
33
+ s.add_development_dependency(%q<minitest>, [">= 2.0.2"])
34
+ s.add_development_dependency(%q<hoe>, [">= 2.9.1"])
30
35
  else
31
- s.add_dependency(%q<minitest>, [">= 2.0.0"])
32
- s.add_dependency(%q<hoe>, [">= 2.1.0"])
33
- s.add_dependency(%q<minitest>, [">= 1.6.0"])
34
- s.add_dependency(%q<hoe>, [">= 2.8.0"])
36
+ s.add_dependency(%q<minitest>, [">= 2.0.2"])
37
+ s.add_dependency(%q<hoe>, [">= 2.9.1"])
35
38
  end
36
39
  else
37
- s.add_dependency(%q<minitest>, [">= 2.0.0"])
38
- s.add_dependency(%q<hoe>, [">= 2.1.0"])
39
- s.add_dependency(%q<minitest>, [">= 1.6.0"])
40
- s.add_dependency(%q<hoe>, [">= 2.8.0"])
40
+ s.add_dependency(%q<minitest>, [">= 2.0.2"])
41
+ s.add_dependency(%q<hoe>, [">= 2.9.1"])
41
42
  end
42
43
  end
@@ -1,7 +1,11 @@
1
1
  require 'arel/crud'
2
+ require 'arel/factory_methods'
2
3
 
3
4
  require 'arel/expressions'
4
5
  require 'arel/predications'
6
+ require 'arel/math'
7
+ require 'arel/alias_predication'
8
+ require 'arel/order_predications'
5
9
  require 'arel/table'
6
10
  require 'arel/attributes'
7
11
  require 'arel/compatibility/wheres'
@@ -29,11 +33,15 @@ require 'arel/sql_literal'
29
33
  ####
30
34
 
31
35
  module Arel
32
- VERSION = '2.0.10'
36
+ VERSION = '2.1.0'
33
37
 
34
38
  def self.sql raw_sql
35
39
  Arel::Nodes::SqlLiteral.new raw_sql
36
40
  end
41
+
42
+ def self.star
43
+ sql '*'
44
+ end
37
45
  ## Convenience Alias
38
46
  Node = Arel::Nodes::Node
39
47
  end
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ module AliasPredication
3
+ def as other
4
+ Nodes::As.new self, Nodes::SqlLiteral.new(other)
5
+ end
6
+ end
7
+ end
@@ -1,8 +1,17 @@
1
1
  module Arel
2
2
  module Attributes
3
- class Attribute < Struct.new :relation, :name, :column
3
+ class Attribute < Struct.new :relation, :name
4
4
  include Arel::Expressions
5
5
  include Arel::Predications
6
+ include Arel::AliasPredication
7
+ include Arel::OrderPredications
8
+ include Arel::Math
9
+
10
+ ###
11
+ # Create a node for lowering this attribute
12
+ def lower
13
+ relation.lower self
14
+ end
6
15
  end
7
16
 
8
17
  class String < Attribute; end
@@ -2,12 +2,11 @@ module Arel
2
2
  ###
3
3
  # FIXME hopefully we can remove this
4
4
  module Crud
5
- # FIXME: this method should go away
6
- def update values
5
+ def compile_update values
7
6
  um = UpdateManager.new @engine
8
7
 
9
8
  if Nodes::SqlLiteral === values
10
- relation = @ctx.froms
9
+ relation = @ctx.from
11
10
  else
12
11
  relation = values.first.first.relation
13
12
  end
@@ -16,22 +15,58 @@ module Arel
16
15
  um.take @ast.limit.expr if @ast.limit
17
16
  um.order(*@ast.orders)
18
17
  um.wheres = @ctx.wheres
18
+ um
19
+ end
20
+
21
+ # FIXME: this method should go away
22
+ def update values
23
+ if $VERBOSE
24
+ warn <<-eowarn
25
+ update (#{caller.first}) is deprecated and will be removed in ARel 3.0.0. Please
26
+ switch to `compile_update`
27
+ eowarn
28
+ end
19
29
 
30
+ um = compile_update values
20
31
  @engine.connection.update um.to_sql, 'AREL'
21
32
  end
22
33
 
34
+ def compile_insert values
35
+ im = create_insert
36
+ im.insert values
37
+ im
38
+ end
39
+
40
+ def create_insert
41
+ InsertManager.new @engine
42
+ end
43
+
23
44
  # FIXME: this method should go away
24
45
  def insert values
25
- im = InsertManager.new @engine
26
- im.insert values
27
- @engine.connection.insert im.to_sql
46
+ if $VERBOSE
47
+ warn <<-eowarn
48
+ insert (#{caller.first}) is deprecated and will be removed in ARel 3.0.0. Please
49
+ switch to `compile_insert`
50
+ eowarn
51
+ end
52
+ @engine.connection.insert compile_insert(values).to_sql
28
53
  end
29
54
 
30
- def delete
55
+ def compile_delete
31
56
  dm = DeleteManager.new @engine
32
57
  dm.wheres = @ctx.wheres
33
58
  dm.from @ctx.froms
34
- @engine.connection.delete dm.to_sql, 'AREL'
59
+ dm
60
+ end
61
+
62
+ def delete
63
+ if $VERBOSE
64
+ warn <<-eowarn
65
+ delete (#{caller.first}) is deprecated and will be removed in ARel 3.0.0. Please
66
+ switch to `compile_delete`
67
+ eowarn
68
+ end
69
+ @engine.connection.delete compile_delete.to_sql, 'AREL'
35
70
  end
36
71
  end
37
72
  end
@@ -1,4 +1,5 @@
1
1
  module Arel
2
2
  module Expression
3
+ include Arel::OrderPredications
3
4
  end
4
5
  end
@@ -0,0 +1,35 @@
1
+ module Arel
2
+ ###
3
+ # Methods for creating various nodes
4
+ module FactoryMethods
5
+ def create_table_alias relation, name
6
+ Nodes::TableAlias.new(relation, name)
7
+ end
8
+
9
+ def create_join to, constraint = nil, klass = Nodes::InnerJoin
10
+ klass.new(to, constraint)
11
+ end
12
+
13
+ def create_string_join to
14
+ create_join to, nil, Nodes::StringJoin
15
+ end
16
+
17
+ def create_and clauses
18
+ Nodes::And.new clauses
19
+ end
20
+
21
+ def create_on expr
22
+ Nodes::On.new expr
23
+ end
24
+
25
+ def grouping expr
26
+ Nodes::Grouping.new expr
27
+ end
28
+
29
+ ###
30
+ # Create a LOWER() function
31
+ def lower column
32
+ Nodes::NamedFunction.new 'LOWER', [column]
33
+ end
34
+ end
35
+ end