Esempio n. 1
0
 def __new__(cls, name, bases, attrs):
     SessionClass = type.__new__(cls, name, bases, attrs)
     if hasattr(SessionClass, 'engine'):
         assert hasattr(SessionClass, 'BaseClass'), 'no BaseClass specified and @declarative_base was never invoked'
         if not hasattr(SessionClass, 'session_factory'):
             SessionClass.session_factory = sessionmaker(bind=SessionClass.engine, autoflush=False, autocommit=False)
         SessionClass.initialize_db()
         SessionClass.crud = make_crud_service(SessionClass)
     return SessionClass
Esempio n. 2
0
 def __new__(cls, name, bases, attrs):
     SessionClass = type.__new__(cls, name, bases, attrs)
     if hasattr(SessionClass, 'engine'):
         if not hasattr(SessionClass, 'BaseClass'):
             for module, bc in _SessionInitializer._base_classes.items():
                 if module == SessionClass.__module__:
                     SessionClass.BaseClass = bc
                     break
             else:
                 raise AssertionError('no BaseClass specified and @declarative_base was never invoked in {}'.format(SessionClass.__module__))
         if not hasattr(SessionClass, 'session_factory'):
             SessionClass.session_factory = sessionmaker(bind=SessionClass.engine, autoflush=False, autocommit=False,
                                                         query_cls=SessionClass.QuerySubclass)
         SessionClass.initialize_db()
         SessionClass.crud = make_crud_service(SessionClass)
     return SessionClass
Esempio n. 3
0
 def __new__(cls, name, bases, attrs):
     SessionClass = type.__new__(cls, name, bases, attrs)
     if hasattr(SessionClass, 'engine'):
         if not hasattr(SessionClass, 'BaseClass'):
             for module, bc in _SessionInitializer._base_classes.items():
                 if module == SessionClass.__module__:
                     SessionClass.BaseClass = bc
                     break
             else:
                 raise AssertionError(
                     'no BaseClass specified and @declarative_base was never invoked in {}'
                     .format(SessionClass.__module__))
         if not hasattr(SessionClass, 'session_factory'):
             SessionClass.session_factory = sessionmaker(
                 bind=SessionClass.engine,
                 autoflush=False,
                 autocommit=False,
                 query_cls=SessionClass.QuerySubclass)
         SessionClass.initialize_db()
         SessionClass.crud = make_crud_service(SessionClass)
     return SessionClass