Skip to content

refactor pgstacDb class #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

vincentsarago
Copy link
Member

This PR tries to resolve #340 by completely refactoring the PgstacDb class and its usage by other classes/methods

dsn: str
commit_on_exit: bool = True
debug: bool = False
use_queue: bool = False
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed possibility to pass a Connection object which adds to much complexity

if self.pool is not None:
self.pool.close()
if self._pool is not None:
self._pool.close()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only close pool if we created it


@contextlib.contextmanager
def connect(self) -> Connection:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connect() should be use in a context manager

with PgstacDb(dsn=...) as db:
    with db.connect() as conn:
         ...


conn: Connection = None
try:
conn = pool.getconn()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also switch to

with pool.connection() as conn:

@@ -28,7 +29,9 @@ def __init__(
sys.exit(0)

self.dsn = dsn
self._db = PgstacDB(dsn=dsn, debug=debug, use_queue=usequeue)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided not to hold a PgSTACDb object in self but instead create it within each subcommand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Database connections are never closed
1 participant