Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_engines_cache(self):
from aldjemy.core import Cache, get_engine
self.assertEqual(get_engine('default'), Cache.engines['default'])
self.assertEqual(get_engine('logs'), Cache.engines['logs'])
self.assertEqual(get_engine(), Cache.engines['default'])
self.assertNotEqual(get_engine('default'), get_engine('logs'))
def get_aldjemy_session():
"""
Use aldjemy to make a session
.. note:
Use only in this case. In normal production mode
it is safer make session explictly because it is more robust
"""
from aldjemy.core import get_engine
engine = get_engine()
_Session = sessionmaker(bind=engine)
return _Session()
def get_session(alias='default'):
connection = connections[alias]
if not hasattr(connection, 'sa_session'):
session = orm.sessionmaker(bind=get_engine(alias))
connection.sa_session = session()
return connection.sa_session
def get_session(alias='default', recreate=False):
connection = connections[alias]
if not hasattr(connection, 'sa_session') or recreate:
engine = get_engine(alias)
session = orm.sessionmaker(bind=engine)
connection.sa_session = session()
return connection.sa_session
def get_aldjemy_session():
"""
Use aldjemy to make a session
.. note:
Use only in this case. In normal production mode
it is safer make session explictly because it is more robust
"""
from aldjemy.core import get_engine
engine = get_engine()
_Session = sessionmaker(bind=engine)
return _Session()