-
-
Notifications
You must be signed in to change notification settings - Fork 87
SQL Upsert Destination
Kiba Pro SQLUpsert
destination provides a way to easily "insert or update" rows, one by one (no batching).
Currently tested against: PostgreSQL 9.5+ (requires ON CONFLICT UPDATE
), Ruby 2.4-2.7.
Requirements: make sure to add those to your Gemfile
:
-
sequel
gem -
pg
gem
Here we will insert products if their SKU isn't present yet and will update them otherwise:
require 'kiba-pro/destinations/sql_upsert'
Sequel.connect(connection_config) do |db|
Kiba.run(Kiba.parse do
# SNIP
destination Kiba::Pro::Destination::SQLUpsert,
database: db,
table: :products,
unique_key: :sku
end)
end
To provide different data in the case the record is updated (vs inserted), use the update_row_pre_processor
parameter:
require 'active_support/core_ext/hash/except'
destination Kiba::Pro::Destination::SQLUpsert,
update_row_pre_processor: -> (row) { row.except(:created_at) }
Home | Core Concepts | Defining jobs | Running jobs | Writing sources | Writing transforms | Writing destinations | Implementation Guidelines | Kiba Pro
This wiki is tracked by git and publicly editable. You are welcome to fix errors and typos. Any defacing or vandalism of content will result in your changes being reverted and you being blocked.