Ejemplo n.º 1
0
Archivo: tag.py Proyecto: wizzat/s3repo
    def tag_path(cls, path_id, *tag_names):
        tag_ids = Tag.find_or_create_tag_ids(tag_names)

        if tag_names:
            execute(cls.conn, """
                INSERT INTO s3_repo.path_tags (
                    path_id,
                    tag_id,
                    date_tagged
                )
                SELECT
                    %(path_id)s AS path_id,
                    tag_id      AS tag_id,
                    %(now)s     AS date_tagged
                FROM s3_repo.path_tags
                WHERE NOT EXISTS (
                    SELECT 1
                    FROM s3_repo.file_tags
                    WHERE path_id = %(path_id)s
                        and tag_id in %(tag_ids)s
                )
            """,
                path_id = path_id,
                tag_ids = tuple(tag_ids),
                now     = now(),
            )
Ejemplo n.º 2
0
Archivo: tag.py Proyecto: wizzat/s3repo
    def tag_file(cls, file_id, *tag_names):
        tag_ids = Tag.find_or_create_tag_ids(tag_names)

        query = """
            INSERT INTO s3_repo.file_tags (
                file_id,
                tag_id,
                date_tagged
            )
            SELECT
                %(file_id)s AS file_id,
                tag_id      AS tag_id,
                %(now)s     AS date_tagged
            FROM (VALUES {}) AS new_tags(tag_id)
            WHERE NOT EXISTS (
                SELECT 1
                FROM s3_repo.file_tags
                WHERE s3_repo.file_tags.file_id = %(file_id)s
                    AND s3_repo.file_tags.tag_id = new_tags.tag_id
            )
        """.format(', '.join("({})".format(x) for x in tag_ids))

        execute(cls.conn, query,
            file_id = file_id,
            now     = now(),
        )
Ejemplo n.º 3
0
Archivo: tag.py Proyecto: wizzat/s3repo
    def tag_file(cls, file_id, *tag_names):
        tag_ids = Tag.find_or_create_tag_ids(tag_names)

        query = """
            INSERT INTO s3_repo.file_tags (
                file_id,
                tag_id,
                date_tagged
            )
            SELECT
                %(file_id)s AS file_id,
                tag_id      AS tag_id,
                %(now)s     AS date_tagged
            FROM (VALUES {}) AS new_tags(tag_id)
            WHERE NOT EXISTS (
                SELECT 1
                FROM s3_repo.file_tags
                WHERE s3_repo.file_tags.file_id = %(file_id)s
                    AND s3_repo.file_tags.tag_id = new_tags.tag_id
            )
        """.format(', '.join("({})".format(x) for x in tag_ids))

        execute(
            cls.conn,
            query,
            file_id=file_id,
            now=now(),
        )
Ejemplo n.º 4
0
Archivo: tag.py Proyecto: wizzat/s3repo
    def tag_path(cls, path_id, *tag_names):
        tag_ids = Tag.find_or_create_tag_ids(tag_names)

        if tag_names:
            execute(
                cls.conn,
                """
                INSERT INTO s3_repo.path_tags (
                    path_id,
                    tag_id,
                    date_tagged
                )
                SELECT
                    %(path_id)s AS path_id,
                    tag_id      AS tag_id,
                    %(now)s     AS date_tagged
                FROM s3_repo.path_tags
                WHERE NOT EXISTS (
                    SELECT 1
                    FROM s3_repo.file_tags
                    WHERE path_id = %(path_id)s
                        and tag_id in %(tag_ids)s
                )
            """,
                path_id=path_id,
                tag_ids=tuple(tag_ids),
                now=now(),
            )
Ejemplo n.º 5
0
Archivo: tag.py Proyecto: wizzat/s3repo
    def untag_file(cls, file_id, *tag_names):
        tag_ids = Tag.find_tag_ids(tag_names)

        if tag_ids:
            execute(cls.conn, """
                DELETE FROM s3_repo.file_tags
                WHERE file_id = %(file_id)s
                    AND tag_id in %(tag_ids)s
            """,
                file_id = file_id,
                tag_ids = tuple(tag_ids),
            )
Ejemplo n.º 6
0
Archivo: tag.py Proyecto: wizzat/s3repo
    def untag_path(cls, path_id, *tag_names):
        tag_ids = Tag.find_tag_ids(tag_names)

        if tag_ids:
            execute(cls.conn, """
                DELETE FROM s3_repo.path_tags
                WHERE path_id = %(path_id)s
                    AND tag_id in %(tag_ids)s
            """,
                path_id = path_id,
                tag_ids = tuple(tag_ids),
            )
Ejemplo n.º 7
0
Archivo: tag.py Proyecto: wizzat/s3repo
    def untag_file(cls, file_id, *tag_names):
        tag_ids = Tag.find_tag_ids(tag_names)

        if tag_ids:
            execute(
                cls.conn,
                """
                DELETE FROM s3_repo.file_tags
                WHERE file_id = %(file_id)s
                    AND tag_id in %(tag_ids)s
            """,
                file_id=file_id,
                tag_ids=tuple(tag_ids),
            )
Ejemplo n.º 8
0
Archivo: tag.py Proyecto: wizzat/s3repo
    def untag_path(cls, path_id, *tag_names):
        tag_ids = Tag.find_tag_ids(tag_names)

        if tag_ids:
            execute(
                cls.conn,
                """
                DELETE FROM s3_repo.path_tags
                WHERE path_id = %(path_id)s
                    AND tag_id in %(tag_ids)s
            """,
                path_id=path_id,
                tag_ids=tuple(tag_ids),
            )
Ejemplo n.º 9
0
Archivo: tag.py Proyecto: wizzat/s3repo
    def find_or_create_tag_ids(cls, tag_names):
        assert isinstance(tag_names, (list, tuple))

        execute(cls.conn, """
            INSERT INTO s3_repo.tags (
                tag_name
            )
            SELECT tag_name
            FROM (VALUES {}) AS new_tags(tag_name)
            WHERE NOT EXISTS (
                SELECT 1
                FROM s3_repo.tags
                WHERE s3_repo.tags.tag_name = new_tags.tag_name
            )
        """.format(', '.join("('{}')".format(x) for x in tag_names)))

        return cls.find_tag_ids(tag_names)
Ejemplo n.º 10
0
Archivo: tag.py Proyecto: wizzat/s3repo
    def find_or_create_tag_ids(cls, tag_names):
        assert isinstance(tag_names, (list, tuple))

        execute(
            cls.conn, """
            INSERT INTO s3_repo.tags (
                tag_name
            )
            SELECT tag_name
            FROM (VALUES {}) AS new_tags(tag_name)
            WHERE NOT EXISTS (
                SELECT 1
                FROM s3_repo.tags
                WHERE s3_repo.tags.tag_name = new_tags.tag_name
            )
        """.format(', '.join("('{}')".format(x) for x in tag_names)))

        return cls.find_tag_ids(tag_names)