Class: Flydata::QueryBasedSync::ResponseHandler
- Inherits:
-
Object
- Object
- Flydata::QueryBasedSync::ResponseHandler
- Includes:
- PluginSupport::SyncRecordEmittable
- Defined in:
- lib/flydata/query_based_sync/response_handler.rb
Direct Known Subclasses
Constant Summary
Constants included from PluginSupport::SyncRecordEmittable
PluginSupport::SyncRecordEmittable::RESPECT_ORDER, PluginSupport::SyncRecordEmittable::SEQ, PluginSupport::SyncRecordEmittable::SRC_POS, PluginSupport::SyncRecordEmittable::TABLE_NAME, PluginSupport::SyncRecordEmittable::TABLE_REV, PluginSupport::SyncRecordEmittable::TYPE, PluginSupport::SyncRecordEmittable::V
Instance Attribute Summary
Attributes included from PluginSupport::SyncRecordEmittable
Instance Method Summary collapse
- #handle(response) ⇒ Object
-
#initialize(context) ⇒ ResponseHandler
constructor
A new instance of ResponseHandler.
Methods included from PluginSupport::SyncRecordEmittable
Constructor Details
#initialize(context) ⇒ ResponseHandler
Returns a new instance of ResponseHandler.
9 10 11 |
# File 'lib/flydata/query_based_sync/response_handler.rb', line 9 def initialize(context) @context = context end |
Instance Method Details
#handle(response) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/flydata/query_based_sync/response_handler.rb', line 13 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 |