From 493f8fbe747650a4fbac2e0b153ad0074b4f91e4 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 6 Dec 2023 13:00:53 +0300 Subject: Feature: Upload Samples/Cases Implements the code enabling the upload of the samples/cases to the database. --- qc_app/db_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'qc_app/db_utils.py') diff --git a/qc_app/db_utils.py b/qc_app/db_utils.py index a04c5e1..75b6b73 100644 --- a/qc_app/db_utils.py +++ b/qc_app/db_utils.py @@ -2,7 +2,7 @@ import logging import traceback import contextlib -from typing import Tuple, Optional, Iterator +from typing import Any, Tuple, Optional, Iterator, Callable from urllib.parse import urlparse import MySQLdb as mdb @@ -32,3 +32,8 @@ def database_connection(db_url: Optional[str] = None) -> Iterator[mdb.Connection connection.rollback() finally: connection.close() + +def with_db_connection(func: Callable[[mdb.Connection], Any]) -> Any: + """Call `func` with a MySQDdb database connection.""" + with database_connection(app.config["SQL_URI"]) as conn: + return func(conn) -- cgit v1.2.3