aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/crud.rb
blob: 640189fbe96af212c57cb788dc4c594781e058a7 (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
module Arel
  ###
  # FIXME hopefully we can remove this
  module Crud
    # FIXME: this method should go away
    def update values
      um = UpdateManager.new @engine

      if Nodes::SqlLiteral === values
        relation = @ctx.froms
      else
        relation = values.first.first.relation
      end
      um.table relation
      um.set values
      um.take @head.limit
      um.order(*@head.orders)
      um.wheres = @ctx.wheres

      @engine.connection.update um.to_sql, 'AREL'
    end

    # FIXME: this method should go away
    def insert values
      im = InsertManager.new @engine
      im.insert values
      @engine.connection.insert im.to_sql
    end

    def delete
      dm = DeleteManager.new @engine
      dm.wheres = @ctx.wheres
      dm.from @ctx.froms
      @engine.connection.delete dm.to_sql, 'AREL'
    end
  end
end