aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/writes.rb
blob: 7df6d861a8917266ac1a9ed60cf354a03fc5649b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module Arel
  class Action < Compound
  end

  class Deletion < Action
    def call
      engine.delete(self)
    end

    def to_sql
      compiler.delete_sql
    end
  end

  class Insert < Action
    attr_reader :record

    def initialize(relation, record)
      super(relation)
      @record = record.bind(relation)
    end

    def call
      engine.create(self)
    end

    def eval
      unoperated_rows + [Row.new(self, record.values.collect(&:value))]
    end

    def to_sql(include_returning = true)
      compiler.insert_sql(include_returning)
    end
  end

  class Update < Insert
    alias :assignments :record

    def call
      engine.update(self)
    end

    def to_sql
      compiler.update_sql
    end
  end
end