blob: ebf24fd899a1bb40659a66846ea490a1297cfe42 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
|