def __init__(self, db_url):
"""
Initialize the Peekaboo database handler.
:param db_url: An RFC 1738 URL that points to the database.
"""
self.__engine = create_engine(db_url)
self.__db_con = None
session_factory = sessionmaker(bind=self.__engine)
self.__Session = scoped_session(session_factory)
self.__lock = threading.RLock()
try:
self.__db_con = self.__engine.connect()
except SQLAlchemyError as e:
raise PeekabooDatabaseError(
'Unable to connect to the database: %s' % e
)
if not self.__db_con.dialect.has_table(self.__engine, '_meta'):
self._init_db()
logger.debug('Database schema created.')
else:
self.clear_in_progress()
评论列表
文章目录