def insert_topic_data(topic_name, mapping_result, pipeline_uid): collection_name = build_collection_name(topic_name) codec_options = build_code_options() collection = db.get_collection(collection_name, codec_options=codec_options) add_audit_columns(mapping_result, INSERT) add_trace_columns(mapping_result, "insert_row", pipeline_uid) collection.insert(mapping_result) trigger_pipeline(topic_name, {pipeline_constants.NEW: mapping_result, pipeline_constants.OLD: None}, TriggerType.insert)
def update_topic_data(topic_name, mapping_result, target_data, pipeline_uid): collection_name = build_collection_name(topic_name) codec_options = build_code_options() collection = db.get_collection(collection_name, codec_options=codec_options) old_data = find_topic_data_by_id(collection, target_data["_id"]) add_audit_columns(mapping_result, UPDATE) add_trace_columns(mapping_result, "update_row", pipeline_uid) collection.update_one({"_id": target_data["_id"]}, {"$set": mapping_result}) data = {**target_data, **mapping_result} trigger_pipeline(topic_name, {pipeline_constants.NEW: data, pipeline_constants.OLD: old_data}, TriggerType.update)
def update_topic_data(topic_name, mapping_result, target_data, pipeline_uid, mongo_query): ''' collection_name = build_collection_name(topic_name) codec_options = build_code_options() collection = db.get_collection(collection_name, codec_options=codec_options) old_data = find_topic_data_by_id(collection, target_data["_id"]) ''' old_data = topic_data_find_by_id(target_data[__get_key()], topic_name) add_audit_columns(mapping_result, UPDATE) add_trace_columns(mapping_result, "update_row", pipeline_uid) ''' collection.update_one({"_id": target_data["_id"]}, {"$set": mapping_result}) ''' topic_data_update_(topic_name, mongo_query, mapping_result) data = {**target_data, **mapping_result} return __build_trigger_pipeline_data(topic_name, {pipeline_constants.NEW: data, pipeline_constants.OLD: old_data}, TriggerType.update)