diff options
Diffstat (limited to 'qc_app/db/tissues.py')
-rw-r--r-- | qc_app/db/tissues.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/qc_app/db/tissues.py b/qc_app/db/tissues.py new file mode 100644 index 0000000..ebf24fd --- /dev/null +++ b/qc_app/db/tissues.py @@ -0,0 +1,22 @@ +"""Handle db interactions for tissue.""" +from typing import Optional + +import MySQLdb as mdb +from MySQLdb.cursors import DictCursor + +def all_tissues(conn: mdb.Connection) -> tuple[dict, ...]: + """All available tissue.""" + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute("SELECT * FROM Tissue ORDER BY TissueName") + return tuple(dict(row) for row in cursor.fetchall()) + +def tissue_by_id(conn: mdb.Connection, tissueid: int) -> Optional[dict]: + """Retrieve a tissue by its ID""" + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute("SELECT * FROM Tissue WHERE Id=%s", + (tissueid,)) + result = cursor.fetchone() + if bool(result): + return dict(result) + + return None |