Method: ROM::SQL::Relation::Writing#upsert

Defined in:
lib/rom/sql/relation/writing.rb

#upsert(*args, &block) ⇒ Object

Add upsert option (only PostgreSQL >= 9.5) Uses internal Sequel implementation Default - ON CONFLICT DO NOTHING more options: sequel.jeremyevans.net/rdoc-adapters/classes/Sequel/Postgres/DatasetMethods.html#method-i-insert_conflict

Examples:

users.upsert({ name: 'Jane', email: '[email protected]' },
             { target: :email, update: { name: :excluded__name } }

API:

  • public



15
16
17
18
19
20
21
22
23
24
# File 'lib/rom/sql/relation/writing.rb', line 15

def upsert(*args, &block)
  if args.size > 1 && args[-1].is_a?(Hash)
    *values, opts = args
  else
    values = args
    opts = EMPTY_HASH
  end

  dataset.insert_conflict(opts).insert(*values, &block)
end