From 971d29e82391cc269405f59b5aad5f31061b633d Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 22 Jun 2023 16:31:18 +0300 Subject: Update calls to `database_connection` function Pass in the database URI at call time. --- scripts/performance/timeit_gn2.py | 3 ++- scripts/sampledata.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/performance/timeit_gn2.py b/scripts/performance/timeit_gn2.py index 1c64e22c..a3e1fb20 100644 --- a/scripts/performance/timeit_gn2.py +++ b/scripts/performance/timeit_gn2.py @@ -14,7 +14,7 @@ class UserSessionSimulator(): def dump_sample_data(dataset_name, trait_id): - with database_connection() as conn, conn.cursor() as cursor: + with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor: sample_data = {"headers": ["Name", "Value", "SE"], "data": []} with app.app_context(): @@ -47,6 +47,7 @@ print(dump_sample_data("HLCPublish", "10001")) from flask import g from wqflask import app +from utility.tools import get_setting from wqflask.database import database_connection from wqflask.show_trait import show_trait """, diff --git a/scripts/sampledata.py b/scripts/sampledata.py index 9e9733bf..34248823 100644 --- a/scripts/sampledata.py +++ b/scripts/sampledata.py @@ -17,6 +17,8 @@ from wqflask.show_trait import show_trait from wqflask.database import database_connection from wqflask.search_results import SearchResultPage +from utility.tools import get_setting + class UserSessionSimulator(): def __init__(self, user_id): @@ -35,7 +37,7 @@ def camel_case(string): def dump_sample_data(dataset_name, trait_id): """Given a DATASET_NAME e.g. 'BXDPublish' and a TRAIT_ID e.g. '10007', dump the sample data as json object""" - with database_connection() as conn, conn.cursor() as cursor: + with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor: sample_data = {"headers": ["Name", "Value", "SE"], "data": []} with app.app_context(): @@ -76,7 +78,7 @@ def fetch_all_traits(species, group, type_, dataset): def get_trait_metadata(dataset_name, trait_id): - with database_connection() as conn, conn.cursor() as cursor: + with database_connection(get_setting("SQL_URI")) as conn, conn.cursor() as cursor: with app.app_context(): g.user_session = UserSessionSimulator(None) data = show_trait.ShowTrait( @@ -138,7 +140,7 @@ Dumping {dataset_name} into {sys.argv[1]}: def main(): # Dump all sampledata into a given directory - with database_connection() as conn: + with database_connection(get_setting("SQL_URI")) as conn: for species, group in gen_dropdown_json(conn).get("datasets").items(): for group_name, type_ in group.items(): for dataset_type, datasets in type_.items(): -- cgit v1.2.3