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(), )
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(), )
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(), )
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(), )
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), )
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), )
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), )
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), )
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)
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)