def __init__(self, url, **kwargs):
"""Initialises a database connection to a given database url.
Parameters
----------
url : url
A sqlalchemy url to connect to a specified database.
kwargs : dict
Additional keys will be passed at create_engine.
"""
super().__init__()
self.url = url
self.log.info("Creating session to db: {}".format(self.url))
self.engine = create_engine(self.url, **kwargs)
try:
self.session_class = sessionmaker(bind=self.engine)
except OperationalError:
self.log.exception(
"Failed to connect db session: {}".format(self.url)
)
raise
评论列表
文章目录