-
Notifications
You must be signed in to change notification settings - Fork 46
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
base: main
Are you sure you want to change the base?
Conversation
dsn: str | ||
commit_on_exit: bool = True | ||
debug: bool = False | ||
use_queue: bool = False |
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.
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() |
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.
only close pool
if we created it
|
||
@contextlib.contextmanager | ||
def connect(self) -> Connection: |
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.
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() |
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.
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) |
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.
decided not to hold a PgSTACDb object in self
but instead create it within each subcommand
This PR tries to resolve #340 by completely refactoring the PgstacDb class and its usage by other classes/methods