def flush(self, timestamp):
        column_names = ["dn"]

        with closing(self.conn.cursor()) as cursor:
            cursor.copy_expert(
                create_copy_from_query('directory.existence_staging', column_names),
                create_copy_from_file(((dn,) for dn in self.dns), ("s",))
            )

            cursor.execute('SELECT directory.transfer_existence(%s)', (timestamp,))

        self.conn.commit()

        self.dns = []
Beispiel #2
0
def store_in_staging_table(conn, tag_links):
    """
    Create temporay table with tag links

    :param conn: Minerva database connection
    :param tag_links: list of tuples like (trend_id, tag_name, taggroup_id)
    """
    table_name = "entity_tag.entitytaglink_staging"
    column_names = ["entity_id", "tag_name", "taggroup_id"]

    copy_from_file = create_copy_from_file(tag_links, ("d", "s", "d"))

    with closing(conn.cursor()) as cursor:
        cursor.copy_from(copy_from_file, table_name, columns=column_names)
Beispiel #3
0
def store_in_temp_table(conn, tag_links):
    """
    Create temporay table with tag links

    :param conn: Minerva database connection
    :param tag_links: list of tuples like (attribute_id, tag_name)
    """

    tmp_table_name = "tmp_attribute_tags"
    columns = [
        ("attribute_id", "integer"),
        ("tag", "varchar")
    ]
    column_names = [col_name for col_name, col_type in columns]
    sql_columns = ["{} {}".format(*column) for column in columns]

    copy_from_file = create_copy_from_file(tag_links, ('d', 's'))
    create_temp_table(conn, tmp_table_name, sql_columns)

    with closing(conn.cursor()) as cursor:
        cursor.copy_from(copy_from_file, tmp_table_name, columns=column_names)

    return tmp_table_name