From e49b4367f1dab1c3acb3cd5d71ba09359c5ab4ee Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 29 Aug 2024 15:21:27 -0500 Subject: Initialise package for dealing with Species. --- uploader/species/models.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 uploader/species/models.py (limited to 'uploader/species/models.py') diff --git a/uploader/species/models.py b/uploader/species/models.py new file mode 100644 index 0000000..98337a3 --- /dev/null +++ b/uploader/species/models.py @@ -0,0 +1,22 @@ +"""Database functions for species.""" +import MySQLdb as mdb +from MySQLdb.cursors import DictCursor + +def all_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, " + "FullName, TaxonomyId 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, " + "FullName FROM Species WHERE SpeciesId=%s", + (speciesid,)) + return cursor.fetchone() -- cgit v1.2.3