Example #1
0
 def delete(cls, model: str, pk: int, *args, session: Session,
            base: Type[Base], **kwargs) -> DBRes:
     if settings.FSQLFLY_SAVE_MODE_DISABLE:
         obj = session.query(base).get(pk)
         session.delete(obj)
         return DBRes(data=obj.id)
     else:
         return DBRes.sever_error(
             'Not Support Delete when FSQLFLY_SAVE_MODE_DISABLE not set')
Example #2
0
 def _add_session(*args, **kwargs):
     session = kwargs[
         'session'] if 'session' in kwargs else DBSession.get_session()
     new_kwargs = {k: v for k, v in kwargs.items() if k != 'session'}
     try:
         res = func(*args, session=session, **new_kwargs)
         session.commit()
         return res
     except Exception as error:
         session.rollback()
         if settings.FSQLFLY_DEBUG:
             raise error
         err = traceback.format_exc()
         return DBRes.sever_error(msg=f'meet {err}')
     finally:
         if 'session' not in kwargs:
             session.close()