Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moved sql related code to its own engine area

Conflicts:

	lib/arel/engine.rb
	lib/arel/extensions/object.rb
	lib/arel/predicates.rb
	lib/arel/primitives/attribute.rb
	lib/arel/primitives/expression.rb
	lib/arel/primitives/value.rb
	lib/arel/relations/operations/join.rb
	lib/arel/relations/relation.rb
	lib/arel/relations/utilities/externalization.rb
	lib/arel/relations/utilities/nil.rb
	lib/arel/relations/writes/delete.rb
	lib/arel/relations/writes/insert.rb
	lib/arel/relations/writes/update.rb
	spec/arel/unit/relations/skip_spec.rb
	spec/arel/unit/relations/take_spec.rb
	spec/spec_helper.rb
  • Loading branch information...
commit bdca9ed42ffea10aa6989ea3ecebedb424fa01ed 1 parent 2bbf8ca
@brynary brynary authored
Showing with 279 additions and 208 deletions.
  1. +1 −1  doc/TODO
  2. +1 −2  lib/arel.rb
  3. +0 −42 lib/arel/engine.rb
  4. +2 −0  lib/arel/engines.rb
  5. +1 −0  lib/arel/engines/array/array.rb
  6. 0  lib/arel/{ → engines/array}/relations/array.rb
  7. 0  lib/arel/{ → engines}/sql/christener.rb
  8. +41 −0 lib/arel/engines/sql/engine.rb
  9. +4 −0 lib/arel/engines/sql/extensions.rb
  10. +9 −0 lib/arel/engines/sql/extensions/array.rb
  11. 0  lib/arel/{ → engines/sql}/extensions/nil_class.rb
  12. +9 −0 lib/arel/engines/sql/extensions/object.rb
  13. 0  lib/arel/{ → engines/sql}/extensions/range.rb
  14. 0  lib/arel/{ → engines}/sql/formatters.rb
  15. +37 −0 lib/arel/engines/sql/predicates.rb
  16. +3 −0  lib/arel/engines/sql/primitives.rb
  17. +17 −0 lib/arel/engines/sql/primitives/attribute.rb
  18. +7 −0 lib/arel/engines/sql/primitives/expression.rb
  19. +11 −0 lib/arel/engines/sql/primitives/value.rb
  20. +5 −0 lib/arel/engines/sql/relations.rb
  21. +2 −0  lib/arel/engines/sql/relations/operations.rb
  22. +5 −0 lib/arel/engines/sql/relations/operations/alias.rb
  23. +19 −0 lib/arel/engines/sql/relations/operations/join.rb
  24. +28 −0 lib/arel/engines/sql/relations/relation.rb
  25. 0  lib/arel/{ → engines/sql}/relations/table.rb
  26. +3 −0  lib/arel/engines/sql/relations/utilities.rb
  27. +14 −0 lib/arel/engines/sql/relations/utilities/externalization.rb
  28. +6 −0 lib/arel/engines/sql/relations/utilities/nil.rb
  29. 0  lib/arel/{ → engines/sql}/relations/utilities/recursion.rb
  30. +3 −0  lib/arel/engines/sql/relations/writes.rb
  31. +12 −0 lib/arel/engines/sql/relations/writes/delete.rb
  32. +12 −0 lib/arel/engines/sql/relations/writes/insert.rb
  33. +14 −0 lib/arel/engines/sql/relations/writes/update.rb
  34. +7 −0 lib/arel/engines/sql/sql.rb
  35. +0 −2  lib/arel/extensions.rb
  36. +0 −8 lib/arel/extensions/array.rb
  37. +0 −8 lib/arel/extensions/object.rb
  38. +0 −15 lib/arel/predicates.rb
  39. +0 −12 lib/arel/primitives/attribute.rb
  40. +0 −4 lib/arel/primitives/expression.rb
  41. +0 −13 lib/arel/primitives/value.rb
  42. +0 −2  lib/arel/relations.rb
  43. +0 −1  lib/arel/relations/operations/alias.rb
  44. +0 −16 lib/arel/relations/operations/join.rb
  45. +1 −31 lib/arel/relations/relation.rb
  46. +0 −2  lib/arel/relations/utilities.rb
  47. +0 −10 lib/arel/relations/utilities/externalization.rb
  48. +0 −3  lib/arel/relations/utilities/nil.rb
  49. +0 −9 lib/arel/relations/writes/delete.rb
  50. +0 −9 lib/arel/relations/writes/insert.rb
  51. +0 −11 lib/arel/relations/writes/update.rb
  52. +0 −2  lib/arel/sql.rb
  53. +1 −1  spec/arel/unit/relations/skip_spec.rb
  54. +2 −2 spec/arel/unit/relations/table_spec.rb
  55. +1 −1  spec/arel/unit/relations/take_spec.rb
  56. +1 −1  spec/spec_helper.rb
View
2  doc/TODO
@@ -1,5 +1,5 @@
todo:
-
+- expressions should be class-based, and joins too, anything _sql should be renamed
- refactor adapter pattern
- implement in memory adapter
- implement mnesia adapter
View
3  lib/arel.rb
@@ -7,9 +7,8 @@
require 'arel/arel'
require 'arel/extensions'
-require 'arel/sql'
require 'arel/predicates'
require 'arel/relations'
-require 'arel/engine'
+require 'arel/engines'
require 'arel/session'
require 'arel/primitives'
View
42 lib/arel/engine.rb
@@ -1,42 +0,0 @@
-module Arel
- # this file is currently just a hack to adapt between activerecord::base which holds the connection specification
- # and active relation. ultimately, this file should be in effect what the connection specification is in active record;
- # that is: a spec of the database (url, password, etc.), a quoting adapter layer, and a connection pool.
- class Engine
- def initialize(ar = nil)
- @ar = ar
- end
-
- def connection
- @ar.connection
- end
-
- def method_missing(method, *args, &block)
- @ar.connection.send(method, *args, &block)
- end
-
- module CRUD
- def create(relation)
- connection.insert(relation.to_sql)
- end
-
- def read(relation)
- results = connection.execute(relation.to_sql)
- rows = []
- results.each do |row|
- rows << attributes.zip(row).to_hash
- end
- rows
- end
-
- def update(relation)
- connection.update(relation.to_sql)
- end
-
- def delete(relation)
- connection.delete(relation.to_sql)
- end
- end
- include CRUD
- end
-end
View
2  lib/arel/engines.rb
@@ -0,0 +1,2 @@
+require 'arel/engines/sql/sql'
+require 'arel/engines/array/array'
View
1  lib/arel/engines/array/array.rb
@@ -0,0 +1 @@
+require 'arel/engines/array/relations/array'
View
0  lib/arel/relations/array.rb → lib/arel/engines/array/relations/array.rb
File renamed without changes
View
0  lib/arel/sql/christener.rb → lib/arel/engines/sql/christener.rb
File renamed without changes
View
41 lib/arel/engines/sql/engine.rb
@@ -0,0 +1,41 @@
+module Arel
+ module Sql
+ class Engine
+ def initialize(ar = nil)
+ @ar = ar
+ end
+
+ def connection
+ @ar.connection
+ end
+
+ def method_missing(method, *args, &block)
+ @ar.connection.send(method, *args, &block)
+ end
+
+ module CRUD
+ def create(relation)
+ connection.insert(relation.to_sql)
+ end
+
+ def read(relation)
+ results = connection.execute(relation.to_sql)
+ rows = []
+ results.each do |row|
+ rows << attributes.zip(row).to_hash
+ end
+ rows
+ end
+
+ def update(relation)
+ connection.update(relation.to_sql)
+ end
+
+ def delete(relation)
+ connection.delete(relation.to_sql)
+ end
+ end
+ include CRUD
+ end
+ end
+end
View
4 lib/arel/engines/sql/extensions.rb
@@ -0,0 +1,4 @@
+require 'arel/engines/sql/extensions/object'
+require 'arel/engines/sql/extensions/array'
+require 'arel/engines/sql/extensions/range'
+require 'arel/engines/sql/extensions/nil_class'
View
9 lib/arel/engines/sql/extensions/array.rb
@@ -0,0 +1,9 @@
+class Array
+ def to_sql(formatter = nil)
+ "(" + collect { |e| e.to_sql(formatter) }.join(', ') + ")"
+ end
+
+ def inclusion_predicate_sql
+ "IN"
+ end
+end
View
0  lib/arel/extensions/nil_class.rb → lib/arel/engines/sql/extensions/nil_class.rb
File renamed without changes
View
9 lib/arel/engines/sql/extensions/object.rb
@@ -0,0 +1,9 @@
+class Object
+ def to_sql(formatter)
+ formatter.scalar self
+ end
+
+ def equality_predicate_sql
+ '='
+ end
+end
View
0  lib/arel/extensions/range.rb → lib/arel/engines/sql/extensions/range.rb
File renamed without changes
View
0  lib/arel/sql/formatters.rb → lib/arel/engines/sql/formatters.rb
File renamed without changes
View
37 lib/arel/engines/sql/predicates.rb
@@ -0,0 +1,37 @@
+module Arel
+ class Binary < Predicate
+ def to_sql(formatter = nil)
+ "#{operand1.to_sql} #{predicate_sql} #{operand1.format(operand2)}"
+ end
+ end
+
+ class Equality < Binary
+ def predicate_sql
+ operand2.equality_predicate_sql
+ end
+ end
+
+ class GreaterThanOrEqualTo < Binary
+ def predicate_sql; '>=' end
+ end
+
+ class GreaterThan < Binary
+ def predicate_sql; '>' end
+ end
+
+ class LessThanOrEqualTo < Binary
+ def predicate_sql; '<=' end
+ end
+
+ class LessThan < Binary
+ def predicate_sql; '<' end
+ end
+
+ class Match < Binary
+ def predicate_sql; 'LIKE' end
+ end
+
+ class In < Binary
+ def predicate_sql; operand2.inclusion_predicate_sql end
+ end
+end
View
3  lib/arel/engines/sql/primitives.rb
@@ -0,0 +1,3 @@
+require 'arel/engines/sql/primitives/attribute'
+require 'arel/engines/sql/primitives/value'
+require 'arel/engines/sql/primitives/expression'
View
17 lib/arel/engines/sql/primitives/attribute.rb
@@ -0,0 +1,17 @@
+require 'set'
+
+module Arel
+ class Attribute
+ def column
+ original_relation.column_for(self)
+ end
+
+ def format(object)
+ object.to_sql(Sql::Attribute.new(self))
+ end
+
+ def to_sql(formatter = Sql::WhereCondition.new(relation))
+ formatter.attribute self
+ end
+ end
+end
View
7 lib/arel/engines/sql/primitives/expression.rb
@@ -0,0 +1,7 @@
+module Arel
+ class Expression < Attribute
+ def to_sql(formatter = Sql::SelectClause.new(relation))
+ formatter.expression self
+ end
+ end
+end
View
11 lib/arel/engines/sql/primitives/value.rb
@@ -0,0 +1,11 @@
+module Arel
+ class Value
+ def to_sql(formatter = Sql::WhereCondition.new(relation))
+ formatter.value value
+ end
+
+ def format(object)
+ object.to_sql(Sql::Value.new(relation))
+ end
+ end
+end
View
5 lib/arel/engines/sql/relations.rb
@@ -0,0 +1,5 @@
+require 'arel/engines/sql/relations/utilities'
+require 'arel/engines/sql/relations/relation'
+require 'arel/engines/sql/relations/operations'
+require 'arel/engines/sql/relations/writes'
+require 'arel/engines/sql/relations/table'
View
2  lib/arel/engines/sql/relations/operations.rb
@@ -0,0 +1,2 @@
+require 'arel/engines/sql/relations/operations/alias'
+require 'arel/engines/sql/relations/operations/join'
View
5 lib/arel/engines/sql/relations/operations/alias.rb
@@ -0,0 +1,5 @@
+module Arel
+ class Alias < Compound
+ include Recursion::BaseCase
+ end
+end
View
19 lib/arel/engines/sql/relations/operations/join.rb
@@ -0,0 +1,19 @@
+module Arel
+ class Join < Relation
+ def table_sql(formatter = Sql::TableReference.new(self))
+ relation1.externalize.table_sql(formatter)
+ end
+
+ def joins(environment, formatter = Sql::TableReference.new(environment))
+ @joins ||= begin
+ this_join = [
+ join_sql,
+ relation2.externalize.table_sql(formatter),
+ ("ON" unless predicates.blank?),
+ (ons + relation2.externalize.wheres).collect { |p| p.bind(environment).to_sql(Sql::WhereClause.new(environment)) }.join(' AND ')
+ ].compact.join(" ")
+ [relation1.joins(environment), this_join, relation2.joins(environment)].compact.join(" ")
+ end
+ end
+ end
+end
View
28 lib/arel/engines/sql/relations/relation.rb
@@ -0,0 +1,28 @@
+module Arel
+ class Relation
+ def to_sql(formatter = Sql::SelectStatement.new(self))
+ formatter.select select_sql, self
+ end
+
+ def select_sql
+ [
+ "SELECT #{attributes.collect { |a| a.to_sql(Sql::SelectClause.new(self)) }.join(', ')}",
+ "FROM #{table_sql(Sql::TableReference.new(self))}",
+ (joins(self) unless joins(self).blank? ),
+ ("WHERE #{wheres .collect { |w| w.to_sql(Sql::WhereClause.new(self)) }.join("\n\tAND ")}" unless wheres.blank? ),
+ ("GROUP BY #{groupings.collect { |g| g.to_sql(Sql::GroupClause.new(self)) }.join(', ')}" unless groupings.blank? ),
+ ("ORDER BY #{orders .collect { |o| o.to_sql(Sql::OrderClause.new(self)) }.join(', ')}" unless orders.blank? ),
+ ("LIMIT #{taken}" unless taken.blank? ),
+ ("OFFSET #{skipped}" unless skipped.blank? )
+ ].compact.join("\n")
+ end
+
+ def inclusion_predicate_sql
+ "IN"
+ end
+
+ def christener
+ @christener ||= Sql::Christener.new
+ end
+ end
+end
View
0  lib/arel/relations/table.rb → lib/arel/engines/sql/relations/table.rb
File renamed without changes
View
3  lib/arel/engines/sql/relations/utilities.rb
@@ -0,0 +1,3 @@
+require 'arel/engines/sql/relations/utilities/recursion'
+require 'arel/engines/sql/relations/utilities/externalization'
+require 'arel/engines/sql/relations/utilities/nil'
View
14 lib/arel/engines/sql/relations/utilities/externalization.rb
@@ -0,0 +1,14 @@
+module Arel
+ class Externalization < Compound
+ include Recursion::BaseCase
+
+ def table_sql(formatter = Sql::TableReference.new(relation))
+ formatter.select relation.select_sql, self
+ end
+
+ # REMOVEME
+ def name
+ relation.name + '_external'
+ end
+ end
+end
View
6 lib/arel/engines/sql/relations/utilities/nil.rb
@@ -0,0 +1,6 @@
+module Arel
+ class Nil < Relation
+ def table_sql(formatter = nil); '' end
+ def name; '' end
+ end
+end
View
0  lib/arel/relations/utilities/recursion.rb → ...ines/sql/relations/utilities/recursion.rb
File renamed without changes
View
3  lib/arel/engines/sql/relations/writes.rb
@@ -0,0 +1,3 @@
+require 'arel/engines/sql/relations/writes/delete'
+require 'arel/engines/sql/relations/writes/insert'
+require 'arel/engines/sql/relations/writes/update'
View
12 lib/arel/engines/sql/relations/writes/delete.rb
@@ -0,0 +1,12 @@
+module Arel
+ class Deletion < Compound
+ def to_sql(formatter = nil)
+ [
+ "DELETE",
+ "FROM #{table_sql}",
+ ("WHERE #{wheres.collect(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ),
+ ("LIMIT #{taken}" unless taken.blank? ),
+ ].compact.join("\n")
+ end
+ end
+end
View
12 lib/arel/engines/sql/relations/writes/insert.rb
@@ -0,0 +1,12 @@
+module Arel
+ class Insert < Compound
+ def to_sql(formatter = nil)
+ [
+ "INSERT",
+ "INTO #{table_sql}",
+ "(#{record.keys.collect { |key| engine.quote_column_name(key.name) }.join(', ')})",
+ "VALUES (#{record.collect { |key, value| key.format(value) }.join(', ')})"
+ ].join("\n")
+ end
+ end
+end
View
14 lib/arel/engines/sql/relations/writes/update.rb
@@ -0,0 +1,14 @@
+module Arel
+ class Update < Compound
+ def to_sql(formatter = nil)
+ [
+ "UPDATE #{table_sql} SET",
+ assignments.collect do |attribute, value|
+ "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}"
+ end.join(",\n"),
+ ("WHERE #{wheres.collect(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ),
+ ("LIMIT #{taken}" unless taken.blank? )
+ ].join("\n")
+ end
+ end
+end
View
7 lib/arel/engines/sql/sql.rb
@@ -0,0 +1,7 @@
+require 'arel/engines/sql/engine'
+require 'arel/engines/sql/relations'
+require 'arel/engines/sql/primitives'
+require 'arel/engines/sql/predicates'
+require 'arel/engines/sql/formatters'
+require 'arel/engines/sql/extensions'
+require 'arel/engines/sql/christener'
View
2  lib/arel/extensions.rb
@@ -2,5 +2,3 @@
require 'arel/extensions/class'
require 'arel/extensions/array'
require 'arel/extensions/hash'
-require 'arel/extensions/range'
-require 'arel/extensions/nil_class'
View
8 lib/arel/extensions/array.rb
@@ -2,12 +2,4 @@ class Array
def to_hash
Hash[*flatten]
end
-
- def to_sql(formatter = nil)
- "(" + collect { |e| e.to_sql(formatter) }.join(', ') + ")"
- end
-
- def inclusion_predicate_sql
- "IN"
- end
end
View
8 lib/arel/extensions/object.rb
@@ -7,14 +7,6 @@ def find_correlate_in(relation)
bind(relation)
end
- def to_sql(formatter)
- formatter.scalar self
- end
-
- def equality_predicate_sql
- '='
- end
-
def metaclass
class << self
self
View
15 lib/arel/predicates.rb
@@ -22,11 +22,6 @@ def ==(other)
def bind(relation)
self.class.new(operand1.find_correlate_in(relation), operand2.find_correlate_in(relation))
end
-
- def to_sql(formatter = nil)
- "#{operand1.to_sql} #{predicate_sql} #{operand1.format(operand2)}"
- end
- alias_method :to_s, :to_sql
end
class CompoundPredicate < Binary
@@ -49,33 +44,23 @@ def ==(other)
((operand1 == other.operand1 and operand2 == other.operand2) or
(operand1 == other.operand2 and operand2 == other.operand1))
end
-
- def predicate_sql
- operand2.equality_predicate_sql
- end
end
class GreaterThanOrEqualTo < Binary
- def predicate_sql; '>=' end
end
class GreaterThan < Binary
- def predicate_sql; '>' end
end
class LessThanOrEqualTo < Binary
- def predicate_sql; '<=' end
end
class LessThan < Binary
- def predicate_sql; '<' end
end
class Match < Binary
- def predicate_sql; 'LIKE' end
end
class In < Binary
- def predicate_sql; operand2.inclusion_predicate_sql end
end
end
View
12 lib/arel/primitives/attribute.rb
@@ -18,18 +18,6 @@ def aggregation?
false
end
- def column
- original_relation.column_for(self)
- end
-
- def format(object)
- object.to_sql(Sql::Attribute.new(self))
- end
-
- def to_sql(formatter = Sql::WhereCondition.new(relation))
- formatter.attribute self
- end
-
module Transformations
def self.included(klass)
klass.send :alias_method, :eql?, :==
View
4 lib/arel/primitives/expression.rb
@@ -9,10 +9,6 @@ def initialize(attribute, function_sql, aliaz = nil, ancestor = nil)
@attribute, @function_sql, @alias, @ancestor = attribute, function_sql, aliaz, ancestor
end
- def to_sql(formatter = Sql::SelectClause.new(relation))
- formatter.expression self
- end
-
def aggregation?
true
end
View
13 lib/arel/primitives/value.rb
@@ -4,19 +4,6 @@ class Value
deriving :initialize, :==
delegate :inclusion_predicate_sql, :equality_predicate_sql, :to => :value
-
- def to_sql(formatter = Sql::WhereCondition.new(relation))
- if value =~ /^\(.*\)$/
- value
- else
- formatter.value value
- end
- end
-
- def format(object)
- object.to_sql(Sql::Value.new(relation))
- end
-
def bind(relation)
Value.new(value, relation)
end
View
2  lib/arel/relations.rb
@@ -1,6 +1,4 @@
require 'arel/relations/relation'
require 'arel/relations/utilities'
-require 'arel/relations/table'
-require 'arel/relations/array'
require 'arel/relations/writes'
require 'arel/relations/operations'
View
1  lib/arel/relations/operations/alias.rb
@@ -1,6 +1,5 @@
module Arel
class Alias < Compound
- include Recursion::BaseCase
attributes :relation
deriving :initialize
alias_method :==, :equal?
View
16 lib/arel/relations/operations/join.rb
@@ -9,22 +9,6 @@ def initialize(join_sql, relation1, relation2 = Nil.instance, *predicates)
@join_sql, @relation1, @relation2, @predicates = join_sql, relation1, relation2, predicates
end
- def table_sql(formatter = Sql::TableReference.new(self))
- relation1.externalize.table_sql(formatter)
- end
-
- def joins(environment, formatter = Sql::TableReference.new(environment))
- @joins ||= begin
- this_join = [
- join_sql,
- relation2.externalize.table_sql(formatter),
- ("ON" unless predicates.blank?),
- (ons + relation2.externalize.wheres).collect { |p| p.bind(environment).to_sql(Sql::WhereClause.new(environment)) }.join(' AND ')
- ].compact.join(" ")
- [relation1.joins(environment), this_join, relation2.joins(environment)].compact.join(" ")
- end
- end
-
def attributes
@attributes ||= (relation1.externalize.attributes +
relation2.externalize.attributes).collect { |a| a.bind(self) }
View
32 lib/arel/relations/relation.rb
@@ -6,32 +6,6 @@ def session
Session.new
end
- def count
- @count = "COUNT(*) AS count_all"
- end
-
- def to_sql(formatter = Sql::SelectStatement.new(self))
- formatter.select select_sql, self
- end
- alias_method :to_s, :to_sql
-
- def select_sql
- [
- "SELECT #{@count} #{attributes.collect { |a| a.to_sql(Sql::SelectClause.new(self)) }.join(', ') unless @count}",
- "FROM #{table_sql(Sql::TableReference.new(self))}",
- (joins(self) unless joins(self).blank? ),
- ("WHERE #{wheres .collect { |w| w.to_sql(Sql::WhereClause.new(self)) }.join("\n\tAND ")}" unless wheres.blank? ),
- ("GROUP BY #{groupings.collect { |g| g.to_sql(Sql::GroupClause.new(self)) }.join(', ')}" unless groupings.blank? ),
- ("ORDER BY #{orders .collect { |o| o.to_sql(Sql::OrderClause.new(self)) }.join(', ')}" unless orders.blank? ),
- ("LIMIT #{taken}" unless taken.blank? ),
- ("OFFSET #{skipped}" unless skipped.blank? )
- ].compact.join("\n")
- end
-
- def inclusion_predicate_sql
- "IN"
- end
-
def call
engine.read(self)
end
@@ -44,10 +18,6 @@ def root
self
end
- def christener
- @christener ||= Sql::Christener.new
- end
-
module Enumerable
include ::Enumerable
@@ -155,7 +125,7 @@ def wheres; [] end
def orders; [] end
def inserts; [] end
def groupings; [] end
- def joins(formatter = nil); nil end
+ def joins(formatter = nil); nil end # FIXME
def taken; nil end
def skipped; nil end
end
View
2  lib/arel/relations/utilities.rb
@@ -1,5 +1,3 @@
require 'arel/relations/utilities/compound'
-require 'arel/relations/utilities/recursion'
require 'arel/relations/utilities/nil'
require 'arel/relations/utilities/externalization'
-require 'arel/relations/utilities/recursion'
View
10 lib/arel/relations/utilities/externalization.rb
@@ -2,24 +2,14 @@ module Arel
class Externalization < Compound
attributes :relation
deriving :initialize, :==
- include Recursion::BaseCase
def wheres
[]
end
- def table_sql(formatter = Sql::TableReference.new(relation))
- formatter.select relation.select_sql, self
- end
-
def attributes
@attributes ||= relation.attributes.collect(&:to_attribute).collect { |a| a.bind(self) }
end
-
- # REMOVEME
- def name
- relation.name + '_external'
- end
end
class Relation
View
3  lib/arel/relations/utilities/nil.rb
@@ -3,8 +3,5 @@
module Arel
class Nil < Relation
include Singleton
-
- def table_sql(formatter = nil); '' end
- def name; '' end
end
end
View
9 lib/arel/relations/writes/delete.rb
@@ -3,15 +3,6 @@ class Deletion < Compound
attributes :relation
deriving :initialize, :==
- def to_sql(formatter = nil)
- [
- "DELETE",
- "FROM #{table_sql}",
- ("WHERE #{wheres.collect(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ),
- ("LIMIT #{taken}" unless taken.blank? ),
- ].compact.join("\n")
- end
-
def call
engine.delete(self)
end
View
9 lib/arel/relations/writes/insert.rb
@@ -7,15 +7,6 @@ def initialize(relation, record)
@relation, @record = relation, record.bind(relation)
end
- def to_sql(formatter = nil)
- [
- "INSERT",
- "INTO #{table_sql}",
- "(#{record.keys.map { |key| engine.quote_column_name(key.name) }.join(', ')})",
- "VALUES (#{record.map { |key, value| key.format(value) }.join(', ')})"
- ].join("\n")
- end
-
def call
engine.create(self)
end
View
11 lib/arel/relations/writes/update.rb
@@ -7,17 +7,6 @@ def initialize(relation, assignments)
@relation, @assignments = relation, assignments
end
- def to_sql(formatter = nil)
- [
- "UPDATE #{table_sql} SET",
- assignments.collect do |attribute, value|
- "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}"
- end.join(",\n"),
- ("WHERE #{wheres.map(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ),
- ("LIMIT #{taken}" unless taken.blank? )
- ].join("\n")
- end
-
def call
engine.update(self)
end
View
2  lib/arel/sql.rb
@@ -1,2 +0,0 @@
-require 'arel/sql/formatters'
-require 'arel/sql/christener'
View
2  spec/arel/unit/relations/skip_spec.rb
@@ -9,7 +9,7 @@ module Arel
describe '#to_sql' do
it "manufactures sql with limit and offset" do
- sql = Skip.new(@relation, @skipped).to_s
+ sql = Skip.new(@relation, @skipped).to_sql
adapter_is :mysql do
sql.should be_like(%Q{
View
4 spec/arel/unit/relations/table_spec.rb
@@ -87,12 +87,12 @@ module Arel
describe '#engine' do
it "defaults to global engine" do
- Table.engine = engine = Engine.new
+ Table.engine = engine = Sql::Engine.new
Table.new(:users).engine.should == engine
end
it "can be specified" do
- Table.new(:users, engine = Engine.new).engine.should == engine
+ Table.new(:users, engine = Sql::Engine.new).engine.should == engine
end
end
end
View
2  spec/arel/unit/relations/take_spec.rb
@@ -9,7 +9,7 @@ module Arel
describe '#to_sql' do
it "manufactures sql with limit and offset" do
- sql = Take.new(@relation, @taken).to_s
+ sql = Take.new(@relation, @taken).to_sql
adapter_is :mysql do
sql.should be_like(%Q{
View
2  spec/spec_helper.rb
@@ -30,6 +30,6 @@ def adapter_name
config.include AdapterGuards
config.mock_with :rr
config.before do
- Arel::Table.engine = Arel::Engine.new(ActiveRecord::Base)
+ Arel::Table.engine = Arel::Sql::Engine.new(ActiveRecord::Base)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.