-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from bluelabsio/use-composition-in-RM-87-Upgr…
…ade-to-SQLAlchemy-2.0 use composition in RM-87
- Loading branch information
Showing
7 changed files
with
59 additions
and
78 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
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,23 @@ | ||
import logging | ||
import sqlalchemy | ||
from typing import Optional | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def composable_get_db_conn(self) -> sqlalchemy.engine.Connection: | ||
if self._db_conn is None: | ||
self._db_conn = self.db_engine.connect() | ||
self.conn_opened_here = True | ||
logger.debug(f"Opened connection to database within {self} because none was provided.") | ||
return self._db_conn | ||
|
||
|
||
def composable_set_db_conn(self, db_conn: Optional[sqlalchemy.engine.Connection]) -> None: | ||
self._db_conn = db_conn | ||
|
||
|
||
def composable_del_db_conn(self) -> None: | ||
if self.conn_opened_here: | ||
self.db_conn.close() | ||
self.db_conn = None |
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
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