aboutsummaryrefslogblamecommitdiffstats
path: root/lib/arel/update_manager.rb
blob: 3f6a48375103aa114ad77fc0225da09b4419f23d (plain) (tree)
1
2
3
4
5
6
7






                                         









                         






                            



                          



                          

                  



                                                  
                                




                                                 

          

     
module Arel
  class UpdateManager < Arel::TreeManager
    def initialize engine
      super
      @head = Nodes::UpdateStatement.new
    end

    def take limit
      @head.limit = limit
      self
    end

    def order *expr
      @head.orders = expr
      self
    end

    ###
    # UPDATE +table+
    def table table
      @head.relation = table
      self
    end

    def wheres= exprs
      @head.wheres = exprs
    end

    def where expr
      @head.wheres << expr
      self
    end

    def set values
      if String === values
        @head.values = [values]
      else
        @head.values = values.map { |column,value|
          Nodes::Assignment.new(
            Nodes::UnqualifiedColumn.new(column),
            value
          )
        }
      end
      self
    end
  end
end