Loading COMMON_VERSION +1 −1 Original line number Diff line number Diff line 0.3.4 0.3.5 README.md +2 −2 Original line number Diff line number Diff line Loading @@ -7,9 +7,9 @@ Everything is configurable with environmental variables. ### Installation via pip Run this command to install version 0.3.4 (latest) via pip: Run this command to install version 0.3.5 (latest) via pip: `python3 -m pip --no-cache-dir install common==0.3.4 --index-url https://code.ornl.gov/api/v4/projects/10568/packages/pypi/simple --trusted-host code.ornl.gov` `python3 -m pip --no-cache-dir install common==0.3.5 --index-url https://code.ornl.gov/api/v4/projects/10568/packages/pypi/simple --trusted-host code.ornl.gov` This will install latest (not recommended): `python3 -m pip --no-cache-dir install common --index-url https://code.ornl.gov/api/v4/projects/10568/packages/pypi/simple --trusted-host code.ornl.gov` Loading src/common/crud_table.py +7 −6 Original line number Diff line number Diff line Loading @@ -58,7 +58,7 @@ def convert_to_update(dictionary): class CRUDTable(ABC): """Defines a database table with standard CRUD operations""" def __init__(self, columns, schema, db): def __init__(self, columns, schema, db, table_name=None): """__init__. :param columns: dictionary like {'id': int, 'email': str} Loading @@ -66,6 +66,7 @@ class CRUDTable(ABC): self.columns = columns self.db = db self.schema = schema self.name = table_name if table_name is not None else self.__class__.__name__.lower() self.logger = create_logger() def create(self, **kwargs): Loading @@ -82,7 +83,7 @@ class CRUDTable(ABC): column_names = str(list(kwargs.keys()))[1:-1].replace("'", "") # build the query with the class's name and the kwargs that were passed query = ( f"INSERT INTO {self.schema}.{self.__class__.__name__} " f"INSERT INTO {self.schema}.{self.name} " f"({column_names}) " f"VALUES ({', '.join(['%s']*len(kwargs.keys()))})" ) Loading Loading @@ -172,7 +173,7 @@ class CRUDTable(ABC): if where_clause is None: try: # make a query to select the columns with no where clause query = f"SELECT {select_clause} " + f"FROM {self.schema}.{self.__class__.__name__}" query = f"SELECT {select_clause} " + f"FROM {self.schema}.{self.name}" # inform the user we are executing the query.. self.logger.info(f"Executing query: {query}") # if the db is not already opened.. Loading @@ -193,7 +194,7 @@ class CRUDTable(ABC): # make a query to select the columns with the where clause query = ( f"SELECT {select_clause} " + f"FROM {self.schema}.{self.__class__.__name__} " + f"FROM {self.schema}.{self.name} " + f"{where_clause[0]}" ) # tell the user we are executing their query Loading Loading @@ -264,7 +265,7 @@ class CRUDTable(ABC): params = tuple([*update_clause[1], *where_clause[1]]) # build a query to update the specified values in the db query = ( f"UPDATE {self.schema}.{self.__class__.__name__} " f"UPDATE {self.schema}.{self.name} " + f"SET {update_clause[0]} " + f"{where_clause[0]}" ) Loading Loading @@ -304,7 +305,7 @@ class CRUDTable(ABC): # construct the where clause with the conversion method where_clause = convert_to_where(kwargs) # build a delete query with the specified values query = f"DELETE FROM {self.schema}.{self.__class__.__name__} " + f"{where_clause[0]}" query = f"DELETE FROM {self.schema}.{self.name} " + f"{where_clause[0]}" # tell the user that we are executing their query self.logger.info(f"Executing query: {query}, " + f"params: {where_clause[1]}") # if the db is not open.. Loading src/common/mixins/influx.py +12 −1 Original line number Diff line number Diff line """Scratch file for showing how the mixins get used.""" try: from influxdb import InfluxDBClient except ImportError: import sys from common.logz import create_logger logger = create_logger() logger.warn( "Influx extra must be installed to use influx mixin. " ) sys.exit(1) from common.env import check_environment as ce Loading src/common/mixins/pandas_mixin.py +12 −2 Original line number Diff line number Diff line #!/usr/bin/env python3 # -*- coding: utf-8 -*- """Provide a `pandas` mixin for the Database class.""" try: import pandas as pd import sqlalchemy except ImportError: import sys from common.logz import create_logger logger = create_logger() logger.warn("db-pandas extra must be installed to use mixin. ") sys.exit(1) class PandasMixin: Loading Loading
README.md +2 −2 Original line number Diff line number Diff line Loading @@ -7,9 +7,9 @@ Everything is configurable with environmental variables. ### Installation via pip Run this command to install version 0.3.4 (latest) via pip: Run this command to install version 0.3.5 (latest) via pip: `python3 -m pip --no-cache-dir install common==0.3.4 --index-url https://code.ornl.gov/api/v4/projects/10568/packages/pypi/simple --trusted-host code.ornl.gov` `python3 -m pip --no-cache-dir install common==0.3.5 --index-url https://code.ornl.gov/api/v4/projects/10568/packages/pypi/simple --trusted-host code.ornl.gov` This will install latest (not recommended): `python3 -m pip --no-cache-dir install common --index-url https://code.ornl.gov/api/v4/projects/10568/packages/pypi/simple --trusted-host code.ornl.gov` Loading
src/common/crud_table.py +7 −6 Original line number Diff line number Diff line Loading @@ -58,7 +58,7 @@ def convert_to_update(dictionary): class CRUDTable(ABC): """Defines a database table with standard CRUD operations""" def __init__(self, columns, schema, db): def __init__(self, columns, schema, db, table_name=None): """__init__. :param columns: dictionary like {'id': int, 'email': str} Loading @@ -66,6 +66,7 @@ class CRUDTable(ABC): self.columns = columns self.db = db self.schema = schema self.name = table_name if table_name is not None else self.__class__.__name__.lower() self.logger = create_logger() def create(self, **kwargs): Loading @@ -82,7 +83,7 @@ class CRUDTable(ABC): column_names = str(list(kwargs.keys()))[1:-1].replace("'", "") # build the query with the class's name and the kwargs that were passed query = ( f"INSERT INTO {self.schema}.{self.__class__.__name__} " f"INSERT INTO {self.schema}.{self.name} " f"({column_names}) " f"VALUES ({', '.join(['%s']*len(kwargs.keys()))})" ) Loading Loading @@ -172,7 +173,7 @@ class CRUDTable(ABC): if where_clause is None: try: # make a query to select the columns with no where clause query = f"SELECT {select_clause} " + f"FROM {self.schema}.{self.__class__.__name__}" query = f"SELECT {select_clause} " + f"FROM {self.schema}.{self.name}" # inform the user we are executing the query.. self.logger.info(f"Executing query: {query}") # if the db is not already opened.. Loading @@ -193,7 +194,7 @@ class CRUDTable(ABC): # make a query to select the columns with the where clause query = ( f"SELECT {select_clause} " + f"FROM {self.schema}.{self.__class__.__name__} " + f"FROM {self.schema}.{self.name} " + f"{where_clause[0]}" ) # tell the user we are executing their query Loading Loading @@ -264,7 +265,7 @@ class CRUDTable(ABC): params = tuple([*update_clause[1], *where_clause[1]]) # build a query to update the specified values in the db query = ( f"UPDATE {self.schema}.{self.__class__.__name__} " f"UPDATE {self.schema}.{self.name} " + f"SET {update_clause[0]} " + f"{where_clause[0]}" ) Loading Loading @@ -304,7 +305,7 @@ class CRUDTable(ABC): # construct the where clause with the conversion method where_clause = convert_to_where(kwargs) # build a delete query with the specified values query = f"DELETE FROM {self.schema}.{self.__class__.__name__} " + f"{where_clause[0]}" query = f"DELETE FROM {self.schema}.{self.name} " + f"{where_clause[0]}" # tell the user that we are executing their query self.logger.info(f"Executing query: {query}, " + f"params: {where_clause[1]}") # if the db is not open.. Loading
src/common/mixins/influx.py +12 −1 Original line number Diff line number Diff line """Scratch file for showing how the mixins get used.""" try: from influxdb import InfluxDBClient except ImportError: import sys from common.logz import create_logger logger = create_logger() logger.warn( "Influx extra must be installed to use influx mixin. " ) sys.exit(1) from common.env import check_environment as ce Loading
src/common/mixins/pandas_mixin.py +12 −2 Original line number Diff line number Diff line #!/usr/bin/env python3 # -*- coding: utf-8 -*- """Provide a `pandas` mixin for the Database class.""" try: import pandas as pd import sqlalchemy except ImportError: import sys from common.logz import create_logger logger = create_logger() logger.warn("db-pandas extra must be installed to use mixin. ") sys.exit(1) class PandasMixin: Loading