city_retrofit/hub/persistence/repository.py

22 lines
682 B
Python
Raw Normal View History

"""
Base repository class to establish db connection
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project Coder Peter Yefi peteryefi@gmail.com
"""
2023-02-01 06:05:12 -05:00
from hub.persistence.configuration import Configuration
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
2023-02-01 06:05:12 -05:00
class Repository:
2022-12-07 19:06:17 -05:00
def __init__(self, db_name, dotenv_path: str, app_env='TEST'):
try:
2023-02-01 06:05:12 -05:00
self.configuration = Configuration(db_name, dotenv_path, app_env)
self.engine = create_engine(self.configuration.conn_string())
2022-12-07 19:06:17 -05:00
self.session = Session(self.engine)
except ValueError as err:
print(f'Missing value for credentials: {err}')