Class: Arel::OnConflictDoUpdateManager

Inherits:
TreeManager
  • Object
show all
Defined in:
lib/active_record_upsert/arel/on_conflict_do_update_manager.rb

Instance Method Summary collapse

Constructor Details

#initializeOnConflictDoUpdateManager

Returns a new instance of OnConflictDoUpdateManager.



3
4
5
6
7
8
9
# File 'lib/active_record_upsert/arel/on_conflict_do_update_manager.rb', line 3

def initialize
  super
  @ast = Nodes::OnConflict.new
  @action = Nodes::DoUpdateSet.new
  @ast.action = @action
  @ctx = @ast
end

Instance Method Details

#set(values) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/active_record_upsert/arel/on_conflict_do_update_manager.rb', line 37

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

#target(column) ⇒ Object



19
20
21
22
# File 'lib/active_record_upsert/arel/on_conflict_do_update_manager.rb', line 19

def target(column)
  @ast.target = column
  self
end

#target=(column) ⇒ Object



15
16
17
# File 'lib/active_record_upsert/arel/on_conflict_do_update_manager.rb', line 15

def target= column
  @ast.target = column
end

#target_condition=(where) ⇒ Object



11
12
13
# File 'lib/active_record_upsert/arel/on_conflict_do_update_manager.rb', line 11

def target_condition= where
  @ast.where = where
end

#to_nodeObject



33
34
35
# File 'lib/active_record_upsert/arel/on_conflict_do_update_manager.rb', line 33

def to_node
  @ast
end

#where(expr) ⇒ Object



28
29
30
31
# File 'lib/active_record_upsert/arel/on_conflict_do_update_manager.rb', line 28

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

#wheres=(exprs) ⇒ Object



24
25
26
# File 'lib/active_record_upsert/arel/on_conflict_do_update_manager.rb', line 24

def wheres= exprs
  @action.wheres = exprs
end