Code for the Common Python Package to include logging, environment checking,
and database connections and query. This package contains an extensible
Database metaclass with a generic query function that is usable out of the box.
Everything is configurable with environmental variables.
Code for the pyGARDEN (**G**eneral **A**pplication **R**esource **D**evelopment **E**nvironment **N**etwork) Python Package to include easy injectable and rich logging, environment checking, and database
connections and query. By default, only SQLite is available as a mixin, but other mixin types to the `Database` class
are Postgres (`[postgres]` extra) or Microsoft SQL Server (`[mssql]` extra). See the [extras](#Extras) section for more
information on how to install these extras, when to choose them, and how to use them.
Some highlights from `pyGARDEN`:
* This package contains an extensible `Database` metaclass with a generic query function that is usable out of the box.
* Everything is configurable with environmental variables -- including email sending, logging, and database connections.
*
### Installation via pip
@@ -34,7 +39,7 @@ Below is a list of environmental variables and what they do:
- DATABASE_PORT, PG_PORT: an integer representing the port to connect to the database on
- DATABASE_SCHEMA, PG_SCHEMA: a string representing the schema to default to when creating a database connection
These evironmental variables have been assigned default values for the Docker container in the file `envfile`, which is called in `docker-compose.yaml` and `docker-compose.test.yaml`
These environmental variables have been assigned default values for the Docker container in the file `envfile`, which is called in `docker-compose.yaml` and `docker-compose.test.yaml`
### Creating an extensible Database Python Class
Some `Database` methods such as `query` and `open` rely on
@@ -44,8 +49,8 @@ additional functionality not provided by the `Database` class. Below is an
example of how to create a Database class that uses the PostgresMixin:
```python
fromcommon.mixins.postgresimportPostgresMixin
fromcommon.databaseimportDatabase
frompygarden.mixins.postgresimportPostgresMixin
frompygarden.databaseimportDatabase
classPostgresDatabase(Database,PostgresMixin):
@@ -58,13 +63,13 @@ with PostgresDatabase() as db:
### Creating a CRUD table with crud_table.py
```python
fromcommon.mixins.postgresimportPostgresMixin
fromcommon.databaseimportDatabase
fromcommon.crud_tableimportCRUDTable
frompygarden.mixins.postgresimportPostgresMixin
frompygarden.databaseimportDatabase
frompygarden.crud_tableimportCRUDTable
# PLEASE NOTE: the name of class MUST be consistent with the name of the
RUN apt-get -yqq update && apt-get install-yqq postgresql-client
RUN pip install common-package[all]==$COMMON_VERSION--index-url https://__token__:$GITLAB_TOKEN@code.ornl.gov/api/v4/projects/10568/packages/pypi/simple
RUN pip install common-package[$COMMON_EXTRAS]==$COMMON_VERSION--index-url https://__token__:$GITLAB_TOKEN@code.ornl.gov/api/v4/projects/10568/packages/pypi/simple