Пример #1
0
    def _index_by_pk(self, parsed_message):
        for core_name, path in update_map[parsed_message.table_name]:
            # Going through each core/entity that needs to be updated
            # depending on which table we receive a message from.
            entity = SCHEMA[core_name]
            with db_session_ctx(self.db_session) as session:

                if path is None:
                    # If `path` is `None` then we received a message for an entity itself
                    ids = [parsed_message.columns["id"]]
                else:
                    # otherwise it's a different table...
                    logger.info(
                        "Generating SELECT statement for %s with path '%s'" %
                        (entity.model, path))
                    select_query = generate_filtered_query(
                        entity.model, path, parsed_message.columns)
                    if select_query is None:
                        logger.warning("SELECT is `None`")
                        continue
                    else:
                        logger.debug("SQL: %s" % select_query)
                        ids = [
                            row[0] for row in session.execute(
                                select_query).fetchall()
                        ]

                # Retrieving actual data
                self._index_data(core_name, ids)
Пример #2
0
    def _index_by_pk(self, parsed_message):
        for core_name, path in update_map[parsed_message.table_name]:
            # Going through each core/entity that needs to be updated
            # depending on which table we receive a message from.
            entity = SCHEMA[core_name]
            with db_session_ctx(self.db_session) as session:
                select_query = None
                if path is None:
                    # If `path` is `None` then we received a message for an entity itself
                    ids = [parsed_message.columns["id"]]
                else:
                    # otherwise it's a different table...
                    logger.debug("Generating SELECT statement for %s with path '%s'" % (entity.model, path))
                    select_query = generate_filtered_query(entity.model, path, parsed_message.columns)
                    if select_query is None:
                        logger.warning("SELECT is `None`")
                        continue
                    else:
                        logger.debug("SQL: %s" % select_query)
                        ids = [row[0] for row in session.execute(select_query).fetchall()]

                # Retrieving actual data
                extra_data = {'table_name': parsed_message.table_name,
                              'path': path,
                              'select_query': str(select_query),
                              }
                self._index_data(core_name, ids, extra_data)
Пример #3
0
 def validate_selection(core_name, path, expected_sql, emitted_keys):
     select_sql = str(generate_filtered_query(SCHEMA[core_name].model, path, emitted_keys))
     self.assertEqual(select_sql, expected_sql)
Пример #4
0
 def validate_selection(core_name, path, expected_sql, emitted_keys):
     select_sql = str(
         generate_filtered_query(SCHEMA[core_name].model, path,
                                 emitted_keys))
     self.assertEqual(select_sql, expected_sql)