aboutsummaryrefslogtreecommitdiff
path: root/qc_app/db/platforms.py
blob: cb527a75c5f78edf90c3aaf2b44285fbeabb7e4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""Handle db interactions for platforms."""
from typing import Optional

import MySQLdb as mdb
from MySQLdb.cursors import DictCursor

def platforms_by_species(
        conn: mdb.Connection, speciesid: int) -> tuple[dict, ...]:
    """Retrieve platforms by the species"""
    with conn.cursor(cursorclass=DictCursor) as cursor:
        cursor.execute("SELECT * FROM GeneChip WHERE SpeciesId=%s "
                       "ORDER BY GeneChipName ASC",
                       (speciesid,))
        return tuple(dict(row) for row in cursor.fetchall())

def platform_by_id(conn: mdb.Connection, platformid: int) -> Optional[dict]:
    """Retrieve a platform by its ID"""
    with conn.cursor(cursorclass=DictCursor) as cursor:
        cursor.execute("SELECT * FROM GeneChip WHERE Id=%s",
                       (platformid,))
        result = cursor.fetchone()
        if bool(result):
            return dict(result)

    return None