This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
forked from HHS/simpler-grants-gov
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Task]: Finish adding Postgres Integration to Analytics Library (#72)
Fixes #45 * update `config.py` database url * add function in `cli.py` * updated packages in `poetry.lock` N/A Row created manually in the database alongside a row created via `test_connection` ![Screen Shot 2024-06-11 at 1 49 53 PM](https://github.com/navapbc/simpler-grants-gov/assets/37313082/b83afad8-5fe1-404f-adf3-c94945740bbe)
- Loading branch information
Showing
7 changed files
with
804 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
POSTGRES_NAME = "app" | ||
POSTGRES_HOST = "0.0.0.0" | ||
POSTGRES_USER = "app" | ||
POSTGRES_PORT = 5432 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# pylint: disable=invalid-name, line-too-long | ||
"""Get a connection to the database using a SQLAlchemy engine object.""" | ||
|
||
from sqlalchemy import Engine, create_engine | ||
|
||
from config import settings | ||
|
||
|
||
# The variables used in the connection url are set in settings.toml and | ||
# .secrets.toml. These can be overridden with the custom prefix defined in config.py: "ANALYTICS". | ||
# e.g. `export ANALYTICS_POSTGRES_USER=new_usr`. | ||
# Docs: https://www.dynaconf.com/envvars/ | ||
def get_db() -> Engine: | ||
""" | ||
Get a connection to the database using a SQLAlchemy engine object. | ||
This function retrieves the database connection URL from the configuration | ||
and creates a SQLAlchemy engine object. | ||
Yields | ||
------ | ||
sqlalchemy.engine.Engine | ||
A SQLAlchemy engine object representing the connection to the database. | ||
""" | ||
return create_engine( | ||
f"postgresql+psycopg://{settings.postgres_user}:{settings.postgres_password}@{settings.postgres_host}:{settings.postgres_port}", | ||
pool_pre_ping=True, | ||
hide_parameters=True, | ||
) |