2022-11-03 15:29:09 -04:00
|
|
|
"""
|
|
|
|
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
|
|
|
|
"""
|
|
|
|
|
|
|
|
from persistence.db_config import BaseConfiguration
|
|
|
|
from sqlalchemy import create_engine
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
|
|
|
|
|
|
|
class BaseRepo:
|
2022-11-15 20:48:42 -05:00
|
|
|
|
|
|
|
def __init__(self, db_name, app_env='TEST'):
|
2022-11-25 18:21:09 -05:00
|
|
|
self.config = BaseConfiguration(db_name, app_env)
|
|
|
|
self.engine = create_engine(self.config.conn_string())
|
|
|
|
self.session = Session(self.engine)
|
2022-11-15 20:48:42 -05:00
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
"""
|
|
|
|
Close database sessions
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
self.session.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-25 18:21:09 -05:00
|
|
|
|