aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/relations
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/relations')
-rw-r--r--lib/arel/relations/array.rb19
-rw-r--r--lib/arel/relations/operations/alias.rb1
-rw-r--r--lib/arel/relations/operations/join.rb16
-rw-r--r--lib/arel/relations/relation.rb32
-rw-r--r--lib/arel/relations/table.rb36
-rw-r--r--lib/arel/relations/utilities.rb2
-rw-r--r--lib/arel/relations/utilities/externalization.rb10
-rw-r--r--lib/arel/relations/utilities/nil.rb3
-rw-r--r--lib/arel/relations/utilities/recursion.rb13
-rw-r--r--lib/arel/relations/writes/delete.rb9
-rw-r--r--lib/arel/relations/writes/insert.rb9
-rw-r--r--lib/arel/relations/writes/update.rb11
12 files changed, 1 insertions, 160 deletions
diff --git a/lib/arel/relations/array.rb b/lib/arel/relations/array.rb
deleted file mode 100644
index dac65abbc2..0000000000
--- a/lib/arel/relations/array.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-module Arel
- class Array < Relation
- include Recursion::BaseCase
-
- def initialize(array, attribute_names)
- @array, @attribute_names = array, attribute_names
- end
-
- def attributes
- @attributes ||= @attribute_names.collect do |name|
- Attribute.new(self, name.to_sym)
- end
- end
-
- def call(connection = nil)
- @array.collect { |row| attributes.zip(row).to_hash }
- end
- end
-end \ No newline at end of file
diff --git a/lib/arel/relations/operations/alias.rb b/lib/arel/relations/operations/alias.rb
index 8ed33fc597..67837f6a75 100644
--- a/lib/arel/relations/operations/alias.rb
+++ b/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?
diff --git a/lib/arel/relations/operations/join.rb b/lib/arel/relations/operations/join.rb
index 8fe89358d8..8e19254378 100644
--- a/lib/arel/relations/operations/join.rb
+++ b/lib/arel/relations/operations/join.rb
@@ -9,22 +9,6 @@ module Arel
@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) }
diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb
index ef295dfdd7..20badaf165 100644
--- a/lib/arel/relations/relation.rb
+++ b/lib/arel/relations/relation.rb
@@ -6,32 +6,6 @@ module Arel
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 @@ module Arel
self
end
- def christener
- @christener ||= Sql::Christener.new
- end
-
module Enumerable
include ::Enumerable
@@ -155,7 +125,7 @@ module Arel
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
diff --git a/lib/arel/relations/table.rb b/lib/arel/relations/table.rb
deleted file mode 100644
index 0433abbbb2..0000000000
--- a/lib/arel/relations/table.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-module Arel
- class Table < Relation
- include Recursion::BaseCase
-
- cattr_accessor :engine
- attr_reader :name, :engine
- hash_on :name
-
- def initialize(name, engine = Table.engine)
- @name, @engine = name.to_s, engine
- end
-
- def attributes
- @attributes ||= columns.collect do |column|
- Attribute.new(self, column.name.to_sym)
- end
- end
-
- def column_for(attribute)
- has_attribute?(attribute) and columns.detect { |c| c.name == attribute.name.to_s }
- end
-
- def columns
- @columns ||= engine.columns(name, "#{name} Columns")
- end
-
- def reset
- @attributes = @columns = nil
- end
-
- def ==(other)
- Table === other and
- name == other.name
- end
- end
-end
diff --git a/lib/arel/relations/utilities.rb b/lib/arel/relations/utilities.rb
index 454d455359..fbd949ef0c 100644
--- a/lib/arel/relations/utilities.rb
+++ b/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' \ No newline at end of file
diff --git a/lib/arel/relations/utilities/externalization.rb b/lib/arel/relations/utilities/externalization.rb
index 3b9b2296dc..bd067f2304 100644
--- a/lib/arel/relations/utilities/externalization.rb
+++ b/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
diff --git a/lib/arel/relations/utilities/nil.rb b/lib/arel/relations/utilities/nil.rb
index 56cf395d2c..6a9d678c45 100644
--- a/lib/arel/relations/utilities/nil.rb
+++ b/lib/arel/relations/utilities/nil.rb
@@ -3,8 +3,5 @@ require 'singleton'
module Arel
class Nil < Relation
include Singleton
-
- def table_sql(formatter = nil); '' end
- def name; '' end
end
end
diff --git a/lib/arel/relations/utilities/recursion.rb b/lib/arel/relations/utilities/recursion.rb
deleted file mode 100644
index 848b059507..0000000000
--- a/lib/arel/relations/utilities/recursion.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module Arel
- module Recursion
- module BaseCase
- def table
- self
- end
-
- def table_sql(formatter = Sql::TableReference.new(self))
- formatter.table self
- end
- end
- end
-end \ No newline at end of file
diff --git a/lib/arel/relations/writes/delete.rb b/lib/arel/relations/writes/delete.rb
index 0a04454e7f..a94067c7fa 100644
--- a/lib/arel/relations/writes/delete.rb
+++ b/lib/arel/relations/writes/delete.rb
@@ -3,15 +3,6 @@ module Arel
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
diff --git a/lib/arel/relations/writes/insert.rb b/lib/arel/relations/writes/insert.rb
index d05bd9cdc8..6d85e9769a 100644
--- a/lib/arel/relations/writes/insert.rb
+++ b/lib/arel/relations/writes/insert.rb
@@ -7,15 +7,6 @@ module Arel
@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
diff --git a/lib/arel/relations/writes/update.rb b/lib/arel/relations/writes/update.rb
index fd0aadb479..e647218a80 100644
--- a/lib/arel/relations/writes/update.rb
+++ b/lib/arel/relations/writes/update.rb
@@ -7,17 +7,6 @@ module Arel
@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