Skip to content

Instantly share code, notes, and snippets.

@ferbncode
Last active March 14, 2017 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferbncode/f0a8264560cee4f0ba2e6e7f1df0e713 to your computer and use it in GitHub Desktop.
Save ferbncode/f0a8264560cee4f0ba2e6e7f1df0e713 to your computer and use it in GitHub Desktop.
from critiquebrainz import mb_db
# from mb_db import db_exceptions
import sys
import sqlalchemy
from brainzutils import cache
def get_tags(id, entity_type, relation, colname):
## Example function for get_tags. Many entities may
## require tags.
query = """SELECT tag.name
FROM {}
INNER JOIN tag
ON {}.tag = tag.id
INNER JOIN {}
ON {}.id = {}.{}
WHERE {}.gid = :id
""".format(relation, relation, entity_type,
entity_type, relation, colname, entity_type)
query = sqlalchemy.text(query)
with mb_db.mb_engine.connect() as connection:
results = connection.execute(query, {"id": id})
tags = results.fetchall()
tags_all = []
if tags:
for tag in tags:
tags_all.append(str(tag[0]))
return tags_all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment