diff options
author | Bryan Helmkamp <bryan@brynary.com> | 2009-05-17 14:38:09 -0400 |
---|---|---|
committer | Bryan Helmkamp <bryan@brynary.com> | 2009-05-17 14:38:09 -0400 |
commit | b0a45d52fdb7d8ce564f4dc2013bc790f98f1da3 (patch) | |
tree | e9553add3be978b3392735a40b869bfdbc53ea7a /lib/arel/engines | |
parent | 7032a50297fce4d7724d1735e81e5df5fd919e71 (diff) | |
download | rails-b0a45d52fdb7d8ce564f4dc2013bc790f98f1da3.tar.gz rails-b0a45d52fdb7d8ce564f4dc2013bc790f98f1da3.tar.bz2 rails-b0a45d52fdb7d8ce564f4dc2013bc790f98f1da3.zip |
consolidated files
Conflicts:
lib/arel/algebra/predicates.rb
lib/arel/algebra/relations/writes/delete.rb
lib/arel/algebra/relations/writes/insert.rb
lib/arel/algebra/relations/writes/update.rb
lib/arel/engines/memory/predicates.rb
lib/arel/engines/memory/relations.rb
lib/arel/engines/sql/primitives/attribute.rb
lib/arel/engines/sql/relations/writes/insert.rb
lib/arel/engines/sql/relations/writes/update.rb
Diffstat (limited to 'lib/arel/engines')
-rw-r--r-- | lib/arel/engines/memory/predicates.rb | 14 | ||||
-rw-r--r-- | lib/arel/engines/memory/primitives.rb | 15 | ||||
-rw-r--r-- | lib/arel/engines/memory/primitives/attribute.rb | 7 | ||||
-rw-r--r-- | lib/arel/engines/memory/primitives/value.rb | 7 | ||||
-rw-r--r-- | lib/arel/engines/memory/relations.rb | 3 | ||||
-rw-r--r-- | lib/arel/engines/memory/relations/operations.rb (renamed from lib/arel/engines/memory/relations/operations/where.rb) | 0 | ||||
-rw-r--r-- | lib/arel/engines/sql/primitives.rb | 34 | ||||
-rw-r--r-- | lib/arel/engines/sql/primitives/attribute.rb | 15 | ||||
-rw-r--r-- | lib/arel/engines/sql/primitives/expression.rb | 7 | ||||
-rw-r--r-- | lib/arel/engines/sql/primitives/value.rb | 11 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations.rb | 4 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/writes.rb | 36 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/writes/delete.rb | 12 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/writes/insert.rb | 12 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/writes/update.rb | 14 |
15 files changed, 83 insertions, 108 deletions
diff --git a/lib/arel/engines/memory/predicates.rb b/lib/arel/engines/memory/predicates.rb index 3522ea3ffa..bbf39ba794 100644 --- a/lib/arel/engines/memory/predicates.rb +++ b/lib/arel/engines/memory/predicates.rb @@ -1,13 +1,4 @@ module Arel - class Predicate - def or(other_predicate) - Or.new(self, other_predicate) - end - - def and(other_predicate) - And.new(self, other_predicate) - end - end class Binary < Predicate def eval(row) @@ -30,11 +21,6 @@ module Arel end class Equality < Binary - def ==(other) - Equality === other and - ((operand1 == other.operand1 and operand2 == other.operand2) or - (operand1 == other.operand2 and operand2 == other.operand1)) - end end class GreaterThanOrEqualTo < Binary diff --git a/lib/arel/engines/memory/primitives.rb b/lib/arel/engines/memory/primitives.rb index 4d5c76e956..77d4c1a52c 100644 --- a/lib/arel/engines/memory/primitives.rb +++ b/lib/arel/engines/memory/primitives.rb @@ -1,2 +1,13 @@ -require 'arel/engines/memory/primitives/attribute' -require 'arel/engines/memory/primitives/value' +module Arel + class Attribute + def eval(row) + row[self] + end + end + + class Value + def eval(row) + value + end + end +end
\ No newline at end of file diff --git a/lib/arel/engines/memory/primitives/attribute.rb b/lib/arel/engines/memory/primitives/attribute.rb deleted file mode 100644 index 9864feadc2..0000000000 --- a/lib/arel/engines/memory/primitives/attribute.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Arel - class Attribute - def eval(row) - row[self] - end - end -end
\ No newline at end of file diff --git a/lib/arel/engines/memory/primitives/value.rb b/lib/arel/engines/memory/primitives/value.rb deleted file mode 100644 index b83cd02e57..0000000000 --- a/lib/arel/engines/memory/primitives/value.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Arel - class Value - def eval(row) - value - end - end -end
\ No newline at end of file diff --git a/lib/arel/engines/memory/relations.rb b/lib/arel/engines/memory/relations.rb index 6361d7c9d7..9f8264c439 100644 --- a/lib/arel/engines/memory/relations.rb +++ b/lib/arel/engines/memory/relations.rb @@ -1,2 +1,3 @@ require 'arel/engines/memory/relations/array' -require 'arel/engines/memory/relations/operations/where' +require 'arel/engines/memory/relations/operations' + diff --git a/lib/arel/engines/memory/relations/operations/where.rb b/lib/arel/engines/memory/relations/operations.rb index eb11fb55fd..eb11fb55fd 100644 --- a/lib/arel/engines/memory/relations/operations/where.rb +++ b/lib/arel/engines/memory/relations/operations.rb diff --git a/lib/arel/engines/sql/primitives.rb b/lib/arel/engines/sql/primitives.rb index 405b1ca803..5544d63710 100644 --- a/lib/arel/engines/sql/primitives.rb +++ b/lib/arel/engines/sql/primitives.rb @@ -1,3 +1,31 @@ -require 'arel/engines/sql/primitives/attribute' -require 'arel/engines/sql/primitives/value' -require 'arel/engines/sql/primitives/expression'
\ No newline at end of file +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 + + class Expression < Attribute + def to_sql(formatter = Sql::SelectClause.new(relation)) + formatter.expression self + end + end + + 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
\ No newline at end of file diff --git a/lib/arel/engines/sql/primitives/attribute.rb b/lib/arel/engines/sql/primitives/attribute.rb deleted file mode 100644 index ad78a9ec5b..0000000000 --- a/lib/arel/engines/sql/primitives/attribute.rb +++ /dev/null @@ -1,15 +0,0 @@ -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
\ No newline at end of file diff --git a/lib/arel/engines/sql/primitives/expression.rb b/lib/arel/engines/sql/primitives/expression.rb deleted file mode 100644 index 24f6879848..0000000000 --- a/lib/arel/engines/sql/primitives/expression.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Arel - class Expression < Attribute - def to_sql(formatter = Sql::SelectClause.new(relation)) - formatter.expression self - end - end -end
\ No newline at end of file diff --git a/lib/arel/engines/sql/primitives/value.rb b/lib/arel/engines/sql/primitives/value.rb deleted file mode 100644 index a44acc26e0..0000000000 --- a/lib/arel/engines/sql/primitives/value.rb +++ /dev/null @@ -1,11 +0,0 @@ -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
\ No newline at end of file diff --git a/lib/arel/engines/sql/relations.rb b/lib/arel/engines/sql/relations.rb index 39ef8852a1..d6e4d295ba 100644 --- a/lib/arel/engines/sql/relations.rb +++ b/lib/arel/engines/sql/relations.rb @@ -5,6 +5,4 @@ require 'arel/engines/sql/relations/relation' require 'arel/engines/sql/relations/table' require 'arel/engines/sql/relations/operations/join' require 'arel/engines/sql/relations/operations/alias' -require 'arel/engines/sql/relations/writes/delete' -require 'arel/engines/sql/relations/writes/insert' -require 'arel/engines/sql/relations/writes/update'
\ No newline at end of file +require 'arel/engines/sql/relations/writes'
\ No newline at end of file diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb new file mode 100644 index 0000000000..edfd9f7233 --- /dev/null +++ b/lib/arel/engines/sql/relations/writes.rb @@ -0,0 +1,36 @@ +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 + + 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 + + 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
\ No newline at end of file diff --git a/lib/arel/engines/sql/relations/writes/delete.rb b/lib/arel/engines/sql/relations/writes/delete.rb deleted file mode 100644 index b22ee51e24..0000000000 --- a/lib/arel/engines/sql/relations/writes/delete.rb +++ /dev/null @@ -1,12 +0,0 @@ -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
\ No newline at end of file diff --git a/lib/arel/engines/sql/relations/writes/insert.rb b/lib/arel/engines/sql/relations/writes/insert.rb deleted file mode 100644 index aac9c87a5b..0000000000 --- a/lib/arel/engines/sql/relations/writes/insert.rb +++ /dev/null @@ -1,12 +0,0 @@ -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
\ No newline at end of file diff --git a/lib/arel/engines/sql/relations/writes/update.rb b/lib/arel/engines/sql/relations/writes/update.rb deleted file mode 100644 index 3e35a0d5cc..0000000000 --- a/lib/arel/engines/sql/relations/writes/update.rb +++ /dev/null @@ -1,14 +0,0 @@ -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
\ No newline at end of file |