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
[Task]: Finish adding Postgres Integration to Analytics Library #72
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b609b91
import SQL methods
aplybeah b6478c3
Merge branch 'main' into export-to-database
aplybeah 3fd7586
Merge branch 'main' into export-to-database
aplybeah e2c36f0
attempt to load vars to settings toml
aplybeah 7768290
working connection
aplybeah 07f1877
update cli method; add suggested setting change
aplybeah a673ce7
update for var access
aplybeah 07f0faf
Merge branch 'main' into export-to-database
aplybeah 62b4bb8
attempt to appease linter; package updates
aplybeah aa36d64
reenable validators
aplybeah 7459c45
update settings vars; fix line length check
aplybeah c4fd3b6
add comment explaining env var override
aplybeah 0eafeef
lint
aplybeah 33ea6ec
update pyproject
aplybeah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiline strings don't turn newlines into spaces by default, so you need to add a trailing space on each line