aboutsummaryrefslogtreecommitdiff
path: root/qc_app/db_utils.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-12-06 13:00:53 +0300
committerFrederick Muriuki Muriithi2023-12-06 13:00:53 +0300
commit493f8fbe747650a4fbac2e0b153ad0074b4f91e4 (patch)
tree578fce7f9548c4a850a02b5817865e5fcb73d007 /qc_app/db_utils.py
parent968fc27c54099ec1ed5d1770925aed98013ecf55 (diff)
downloadgn-uploader-493f8fbe747650a4fbac2e0b153ad0074b4f91e4.tar.gz
Feature: Upload Samples/Cases
Implements the code enabling the upload of the samples/cases to the database.
Diffstat (limited to 'qc_app/db_utils.py')
-rw-r--r--qc_app/db_utils.py7
1 files changed, 6 insertions, 1 deletions
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)