diff options
author | Frederick Muriuki Muriithi | 2024-01-08 04:50:42 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-01-08 05:46:25 +0300 |
commit | cace7a50a45c6d227bce52569fcfc2944fbcbe92 (patch) | |
tree | bf625ff1467ba808784fa00c0852c35cd9f1d6ce /qc_app/db/species.py | |
parent | 0677b36b2e144b07d7822661129cde0a82115b12 (diff) | |
download | gn-uploader-cace7a50a45c6d227bce52569fcfc2944fbcbe92.tar.gz |
Extract common database functions into a separate package.
Diffstat (limited to 'qc_app/db/species.py')
-rw-r--r-- | qc_app/db/species.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/qc_app/db/species.py b/qc_app/db/species.py new file mode 100644 index 0000000..7006d15 --- /dev/null +++ b/qc_app/db/species.py @@ -0,0 +1,24 @@ +"""Database functions for species.""" +import MySQLdb as mdb +from MySQLdb.cursors import DictCursor + +def species(conn: mdb.Connection) -> tuple: + "Retrieve the species from the database." + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute( + "SELECT SpeciesId, SpeciesName, LOWER(Name) AS Name, MenuName " + "FROM Species") + return tuple(cursor.fetchall()) + + return tuple() + +def species_by_id(conn: mdb.Connection, speciesid) -> dict: + "Retrieve the species from the database by id." + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute( + ( + "SELECT " + "SpeciesId, SpeciesName, LOWER(Name) AS Name, MenuName " + "FROM Species WHERE SpeciesId=%s"), + (speciesid,)) + return cursor.fetchone() |