Loading src/README.md +23 −2 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ Set variables in the script to match: - DB_PORT: an integer representing the port to connect to the database on (default 5432) - DB_DB: a string representing the database to connect to (default postgres) - MAX_RETRIES: an integer representing the maximum number of times to retry the connection (default 60) Usage: `test-db-conn -d <DB_DB> -h <DB_HOST> -p <DB_PORT> -r <MAX_RETRIES>` - Usage: `test-db-conn -d <DB_DB> -h <DB_HOST> -p <DB_PORT> -r <MAX_RETRIES>` ## Classes Loading @@ -18,9 +18,30 @@ DATABASE_TIMEOUT, DATABASE_DB, DATABASE_USER, DATABASE_PW, DATABASE_HOST, DATABASE_PORT, DATABASE_SCHEMA These environmental variables are read in using `env.py` function check_environment and have default values assigned. Best practice is to use `with` to enter the database, i.e. `with Database as db:` This will "silently" open the database from the `__enter__` function. ## Mixins Mixins for the Database class found in `database.py` can be found in `./common/mixins/`. A postgres mixin that uses psycopg2 can be found in `./common/mixins/postgres.py`. Usage with the Database class would look like: `class PostgresDatabase(Database, PostgresMixin)`. Similary, a pandas mixin can be found in `./common/mixins/pandas.py`. Usage with the Database class would look like: `class PostgresDatabase(Database, PandasMixin)`. ## Mixins ## Functions Within `database.py`: `is_open` Determines if the database is open or not, returns True if open and False if closed. `override_connection` Overrides the default connection, useful for using other connections than `psycopg2` for downstream development `modify_connection_info` Modify a `variable` and set it to `value` in the connection_info attribute. Within `postgres.py`: `open` Explicitly open the database connection and tests a cursor `query` Passes a user defined SQL query through the psycopg2 interface, extensive error catching. Within `pandas.py`: `query_pandas` Return a query as a pandas table. Provided a query, uses the default cursor assumming a PostgreSQL connection. `make_dataframe` Create a pandas dataframe from a query. No newline at end of file Loading
src/README.md +23 −2 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ Set variables in the script to match: - DB_PORT: an integer representing the port to connect to the database on (default 5432) - DB_DB: a string representing the database to connect to (default postgres) - MAX_RETRIES: an integer representing the maximum number of times to retry the connection (default 60) Usage: `test-db-conn -d <DB_DB> -h <DB_HOST> -p <DB_PORT> -r <MAX_RETRIES>` - Usage: `test-db-conn -d <DB_DB> -h <DB_HOST> -p <DB_PORT> -r <MAX_RETRIES>` ## Classes Loading @@ -18,9 +18,30 @@ DATABASE_TIMEOUT, DATABASE_DB, DATABASE_USER, DATABASE_PW, DATABASE_HOST, DATABASE_PORT, DATABASE_SCHEMA These environmental variables are read in using `env.py` function check_environment and have default values assigned. Best practice is to use `with` to enter the database, i.e. `with Database as db:` This will "silently" open the database from the `__enter__` function. ## Mixins Mixins for the Database class found in `database.py` can be found in `./common/mixins/`. A postgres mixin that uses psycopg2 can be found in `./common/mixins/postgres.py`. Usage with the Database class would look like: `class PostgresDatabase(Database, PostgresMixin)`. Similary, a pandas mixin can be found in `./common/mixins/pandas.py`. Usage with the Database class would look like: `class PostgresDatabase(Database, PandasMixin)`. ## Mixins ## Functions Within `database.py`: `is_open` Determines if the database is open or not, returns True if open and False if closed. `override_connection` Overrides the default connection, useful for using other connections than `psycopg2` for downstream development `modify_connection_info` Modify a `variable` and set it to `value` in the connection_info attribute. Within `postgres.py`: `open` Explicitly open the database connection and tests a cursor `query` Passes a user defined SQL query through the psycopg2 interface, extensive error catching. Within `pandas.py`: `query_pandas` Return a query as a pandas table. Provided a query, uses the default cursor assumming a PostgreSQL connection. `make_dataframe` Create a pandas dataframe from a query. No newline at end of file