diff options
-rw-r--r-- | lib/arel/algebra/relations/writes.rb | 30 | ||||
-rw-r--r-- | lib/arel/engines/memory/relations/writes.rb | 2 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/writes.rb | 6 |
3 files changed, 20 insertions, 18 deletions
diff --git a/lib/arel/algebra/relations/writes.rb b/lib/arel/algebra/relations/writes.rb index d344987915..17da2b172b 100644 --- a/lib/arel/algebra/relations/writes.rb +++ b/lib/arel/algebra/relations/writes.rb @@ -1,33 +1,35 @@ module Arel - class Deletion < Compound - attributes :relation - deriving :initialize, :== + class Action < Compound + def == other + super || self.class === other && @relation == other.relation + end + end + class Deletion < Action def call engine.delete(self) end end - class Insert < Compound - attributes :relation, :record - deriving :== + class Insert < Action + attr_reader :record def initialize(relation, record) - @relation, @record = relation, record.bind(relation) + super(relation) + @record = record.bind(relation) end def call engine.create(self) end - end - class Update < Compound - attributes :relation, :assignments - deriving :== - - def initialize(relation, assignments) - @relation, @assignments = relation, assignments.bind(relation) + def == other + super && @record == other.record end + end + + class Update < Insert + alias :assignments :record def call engine.update(self) diff --git a/lib/arel/engines/memory/relations/writes.rb b/lib/arel/engines/memory/relations/writes.rb index 12c4f36c0d..39c1170ddc 100644 --- a/lib/arel/engines/memory/relations/writes.rb +++ b/lib/arel/engines/memory/relations/writes.rb @@ -1,5 +1,5 @@ module Arel - class Insert < Compound + class Insert < Action def eval unoperated_rows + [Row.new(self, record.values.collect(&:value))] end diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb index 4ed817f85d..50a2ce2e99 100644 --- a/lib/arel/engines/sql/relations/writes.rb +++ b/lib/arel/engines/sql/relations/writes.rb @@ -1,17 +1,17 @@ module Arel - class Deletion < Compound + class Deletion < Action def to_sql compiler.delete_sql end end - class Insert < Compound + class Insert < Action def to_sql(include_returning = true) compiler.insert_sql(include_returning) end end - class Update < Compound + class Update < Insert def to_sql compiler.update_sql end |