Add SQLAlchemy and database boilerplate code
This commit is contained in:
parent
2da6e43797
commit
31df889dcb
15 changed files with 454 additions and 60 deletions
24
tofu_api/dependencies.py
Normal file
24
tofu_api/dependencies.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from sqlalchemy.orm import Session
|
||||
|
||||
from tofu_api.common.database import SQLAlchemy
|
||||
|
||||
|
||||
class Dependencies:
|
||||
"""
|
||||
Container for dependency injection.
|
||||
"""
|
||||
|
||||
_dependency_cache: dict
|
||||
|
||||
def __init__(self):
|
||||
self._dependency_cache = {}
|
||||
|
||||
# Database dependencies
|
||||
|
||||
def get_sqlalchemy(self) -> SQLAlchemy:
|
||||
if SQLAlchemy not in self._dependency_cache:
|
||||
self._dependency_cache[SQLAlchemy] = SQLAlchemy()
|
||||
return self._dependency_cache[SQLAlchemy]
|
||||
|
||||
def get_db_session(self) -> Session:
|
||||
return self.get_sqlalchemy().session
|
||||
Loading…
Add table
Add a link
Reference in a new issue