require 'flydata/plugin_support/sync_record_emittable' module Flydata module QueryBasedSync class ResponseHandler include Flydata::PluginSupport::SyncRecordEmittable def initialize(context) @context = context end def handle(response) records = response.records.collect{|r| {row: r} } emit_sync_records(records, type: :update, # upsert only src_pos: response.new_source_pos.to_s, table: response.table_name) # TODO: Revisit and check if transaction management is needed # However, since we use 'upsert' for query based sync, # duplicate event will not cause an issue. context.table_src_pos_files[response.table_name.to_sym]. save(response.new_source_pos) end end end end