You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is observed that various plugin includes the following function for working with DB directly.
I think we can provide the same function. The good thing of we providing the function gives us a way to config the scoped_session that is the best fit for cloud deployment and different transport.
import logging
from contextlib import contextmanager
from skygear.utils.db import _get_engine
from sqlalchemy.orm import sessionmaker
log = logging.getLogger(__name__)
Session = sessionmaker()
@contextmanager
def scoped_session(session=None):
if session is None:
session = _create_session()
try:
yield session
session.commit()
except:
log.warn('rollback session')
session.rollback()
raise
finally:
session.close()
# Usage
with scoped_session() as session:
session.add(user)
The text was updated successfully, but these errors were encountered:
It is observed that various plugin includes the following function for working with DB directly.
I think we can provide the same function. The good thing of we providing the function gives us a way to config the scoped_session that is the best fit for cloud deployment and different transport.
The text was updated successfully, but these errors were encountered: