diff options
author | Frederick Muriuki Muriithi | 2024-11-22 12:16:28 -0600 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-11-22 12:16:28 -0600 |
commit | 8a84c4d6762446e5fdf9f9121f539c89419ae6a0 (patch) | |
tree | 0c4d175767bdfb24d83a7f0c15e0ab677e00ebba /uploader | |
parent | 82fb92db448f1985b821193bcfdee72d512e27bb (diff) | |
download | gn-uploader-8a84c4d6762446e5fdf9f9121f539c89419ae6a0.tar.gz |
Use gn-libs code for db connection.
Use the code in gn-libs to connect to the database, rather than a
local module.
Diffstat (limited to 'uploader')
-rw-r--r-- | uploader/check_connections.py | 3 | ||||
-rw-r--r-- | uploader/expression_data/dbinsert.py | 3 | ||||
-rw-r--r-- | uploader/expression_data/views.py | 3 | ||||
-rw-r--r-- | uploader/genotypes/models.py | 7 | ||||
-rw-r--r-- | uploader/genotypes/views.py | 2 | ||||
-rw-r--r-- | uploader/phenotypes/models.py | 9 | ||||
-rw-r--r-- | uploader/phenotypes/views.py | 2 | ||||
-rw-r--r-- | uploader/platforms/views.py | 2 | ||||
-rw-r--r-- | uploader/population/rqtl2.py | 3 | ||||
-rw-r--r-- | uploader/population/views.py | 2 | ||||
-rw-r--r-- | uploader/request_checks.py | 2 | ||||
-rw-r--r-- | uploader/species/views.py | 2 |
12 files changed, 22 insertions, 18 deletions
diff --git a/uploader/check_connections.py b/uploader/check_connections.py index 2561e55..c9b9aa3 100644 --- a/uploader/check_connections.py +++ b/uploader/check_connections.py @@ -4,8 +4,7 @@ import traceback import redis import MySQLdb - -from uploader.db_utils import database_connection +from gn_libs.mysqldb import database_connection def check_redis(uri: str): "Check the redis connection" diff --git a/uploader/expression_data/dbinsert.py b/uploader/expression_data/dbinsert.py index 32ca359..6d8ce80 100644 --- a/uploader/expression_data/dbinsert.py +++ b/uploader/expression_data/dbinsert.py @@ -7,16 +7,17 @@ from datetime import datetime from redis import Redis from MySQLdb.cursors import DictCursor +from gn_libs.mysqldb import database_connection from flask import ( flash, request, url_for, Blueprint, redirect, render_template, current_app as app) from uploader import jobs from uploader.authorisation import require_login +from uploader.db_utils import with_db_connection from uploader.population.models import populations_by_species from uploader.species.models import all_species, species_by_id from uploader.platforms.models import platform_by_species_and_id -from uploader.db_utils import with_db_connection, database_connection dbinsertbp = Blueprint("dbinsert", __name__) diff --git a/uploader/expression_data/views.py b/uploader/expression_data/views.py index bbe6538..7629f3e 100644 --- a/uploader/expression_data/views.py +++ b/uploader/expression_data/views.py @@ -8,6 +8,7 @@ from zipfile import ZipFile, is_zipfile import jsonpickle from redis import Redis from werkzeug.utils import secure_filename +from gn_libs.mysqldb import database_connection from flask import (flash, request, url_for, @@ -21,8 +22,8 @@ from uploader import jobs from uploader.datautils import order_by_family from uploader.ui import make_template_renderer from uploader.authorisation import require_login +from uploader.db_utils import with_db_connection from uploader.species.models import all_species, species_by_id -from uploader.db_utils import with_db_connection, database_connection from uploader.population.models import (populations_by_species, population_by_species_and_id) diff --git a/uploader/genotypes/models.py b/uploader/genotypes/models.py index 44c98b1..4c3e634 100644 --- a/uploader/genotypes/models.py +++ b/uploader/genotypes/models.py @@ -4,8 +4,9 @@ from datetime import datetime import MySQLdb as mdb from MySQLdb.cursors import Cursor, DictCursor +from flask import current_app as app -from uploader.db_utils import debug_query +from gn_libs.mysqldb import debug_query def genocode_by_population( conn: mdb.Connection, population_id: int) -> tuple[dict, ...]: @@ -38,7 +39,7 @@ def genotype_markers( with conn.cursor(cursorclass=DictCursor) as cursor: cursor.execute(_query, (species_id,)) - debug_query(cursor) + debug_query(cursor, app.logger) return tuple(dict(row) for row in cursor.fetchall()) @@ -64,7 +65,7 @@ def genotype_dataset( with conn.cursor(cursorclass=DictCursor) as cursor: cursor.execute(_query, _params) - debug_query(cursor) + debug_query(cursor, app.logger) result = cursor.fetchone() if bool(result): return dict(result) diff --git a/uploader/genotypes/views.py b/uploader/genotypes/views.py index 0821eca..e6b1ba7 100644 --- a/uploader/genotypes/views.py +++ b/uploader/genotypes/views.py @@ -1,5 +1,6 @@ """Views for the genotypes.""" from MySQLdb.cursors import DictCursor +from gn_libs.mysqldb import database_connection from flask import (flash, request, url_for, @@ -11,7 +12,6 @@ from flask import (flash, from uploader.ui import make_template_renderer from uploader.oauth2.client import oauth2_post from uploader.authorisation import require_login -from uploader.db_utils import database_connection from uploader.species.models import all_species, species_by_id from uploader.monadic_requests import make_either_error_handler from uploader.request_checks import with_species, with_population diff --git a/uploader/phenotypes/models.py b/uploader/phenotypes/models.py index 9324601..73b1cce 100644 --- a/uploader/phenotypes/models.py +++ b/uploader/phenotypes/models.py @@ -5,8 +5,9 @@ from datetime import datetime import MySQLdb as mdb from MySQLdb.cursors import Cursor, DictCursor +from flask import current_app as app -from uploader.db_utils import debug_query +from gn_libs.mysqldb import debug_query def datasets_by_population( conn: mdb.Connection, @@ -68,7 +69,7 @@ def dataset_phenotypes(conn: mdb.Connection, f" LIMIT {limit} OFFSET {offset}" if bool(limit) else "") with conn.cursor(cursorclass=DictCursor) as cursor: cursor.execute(_query, (population_id, dataset_id)) - debug_query(cursor) + debug_query(cursor, app.logger) return tuple(dict(row) for row in cursor.fetchall()) @@ -201,7 +202,7 @@ def phenotypes_data(conn: mdb.Connection, f" LIMIT {limit} OFFSET {offset}" if bool(limit) else "") with conn.cursor(cursorclass=DictCursor) as cursor: cursor.execute(_query, (population_id, dataset_id)) - debug_query(cursor) + debug_query(cursor, app.logger) return tuple(dict(row) for row in cursor.fetchall()) @@ -228,5 +229,5 @@ def save_new_dataset(cursor: Cursor, "%(created)s, %(public)s, %(population_id)s, %(confidentiality)s, " "%(users)s)", params) - debug_query(cursor) + debug_query(cursor, app.logger) return {**params, "Id": cursor.lastrowid} diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py index 02e8078..79aab81 100644 --- a/uploader/phenotypes/views.py +++ b/uploader/phenotypes/views.py @@ -8,6 +8,7 @@ from functools import wraps from redis import Redis from requests.models import Response from MySQLdb.cursors import DictCursor +from gn_libs.mysqldb import database_connection from flask import (flash, request, url_for, @@ -24,7 +25,6 @@ from uploader import jobs from uploader.files import save_file#, fullpath from uploader.oauth2.client import oauth2_post from uploader.authorisation import require_login -from uploader.db_utils import database_connection from uploader.species.models import all_species, species_by_id from uploader.monadic_requests import make_either_error_handler from uploader.request_checks import with_species, with_population diff --git a/uploader/platforms/views.py b/uploader/platforms/views.py index 2d61b6a..c20ab44 100644 --- a/uploader/platforms/views.py +++ b/uploader/platforms/views.py @@ -1,5 +1,6 @@ """The endpoints for the platforms""" from MySQLdb.cursors import DictCursor +from gn_libs.mysqldb import database_connection from flask import ( flash, request, @@ -10,7 +11,6 @@ from flask import ( from uploader.ui import make_template_renderer from uploader.authorisation import require_login -from uploader.db_utils import database_connection from uploader.species.models import all_species, species_by_id from uploader.datautils import safe_int, order_by_family, enumerate_sequence diff --git a/uploader/population/rqtl2.py b/uploader/population/rqtl2.py index 9968bd6..436eca0 100644 --- a/uploader/population/rqtl2.py +++ b/uploader/population/rqtl2.py @@ -12,6 +12,7 @@ import MySQLdb as mdb from redis import Redis from MySQLdb.cursors import DictCursor from werkzeug.utils import secure_filename +from gn_libs.mysqldb import database_connection from flask import ( flash, escape, @@ -29,7 +30,7 @@ from r_qtl import r_qtl2 from uploader import jobs from uploader.files import save_file, fullpath from uploader.species.models import all_species -from uploader.db_utils import with_db_connection, database_connection +from uploader.db_utils import with_db_connection from uploader.authorisation import require_login from uploader.platforms.models import platform_by_id, platforms_by_species diff --git a/uploader/population/views.py b/uploader/population/views.py index 36201ba..4f985f5 100644 --- a/uploader/population/views.py +++ b/uploader/population/views.py @@ -3,6 +3,7 @@ import json import base64 from MySQLdb.cursors import DictCursor +from gn_libs.mysqldb import database_connection from flask import (flash, request, url_for, @@ -15,7 +16,6 @@ from uploader.oauth2.client import oauth2_post from uploader.ui import make_template_renderer from uploader.authorisation import require_login from uploader.genotypes.views import genotypesbp -from uploader.db_utils import database_connection from uploader.datautils import enumerate_sequence from uploader.phenotypes.views import phenotypesbp from uploader.expression_data.views import exprdatabp diff --git a/uploader/request_checks.py b/uploader/request_checks.py index a24b2f7..f1d8027 100644 --- a/uploader/request_checks.py +++ b/uploader/request_checks.py @@ -4,10 +4,10 @@ These are useful for reusability, and hence maintainability of the code. """ from functools import wraps +from gn_libs.mysqldb import database_connection from flask import flash, url_for, redirect, current_app as app from uploader.species.models import species_by_id -from uploader.db_utils import database_connection from uploader.population.models import population_by_species_and_id def with_species(redirect_uri: str): diff --git a/uploader/species/views.py b/uploader/species/views.py index 10715a5..fee5c75 100644 --- a/uploader/species/views.py +++ b/uploader/species/views.py @@ -1,5 +1,6 @@ """Endpoints handling species.""" from pymonad.either import Left, Right, Either +from gn_libs.mysqldb import database_connection from flask import (flash, request, url_for, @@ -10,7 +11,6 @@ from flask import (flash, from uploader.population import popbp from uploader.platforms import platformsbp from uploader.ui import make_template_renderer -from uploader.db_utils import database_connection from uploader.oauth2.client import oauth2_get, oauth2_post from uploader.authorisation import require_login, require_token from uploader.datautils import order_by_family, enumerate_sequence |