Last active
March 14, 2017 16:19
-
-
Save ferbncode/f0a8264560cee4f0ba2e6e7f1df0e713 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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