32 lines
748 B
Python
32 lines
748 B
Python
from contextlib import contextmanager
|
|
from flask.ext.sqlalchemy import SQLAlchemy
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import scoped_session, sessionmaker
|
|
|
|
db = SQLAlchemy()
|
|
|
|
@contextmanager
|
|
def session_scope(engine):
|
|
if engine:
|
|
session = scoped_session(sessionmaker(autocommit = False, autoflush = False, bind = engine))
|
|
#Base.query = session.query_property()
|
|
|
|
try:
|
|
yield session
|
|
session.commit()
|
|
except:
|
|
session.rollback()
|
|
raise
|
|
finally:
|
|
session.close()
|
|
|
|
import pkgutil
|
|
|
|
__all__ = []
|
|
|
|
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
|
|
__all__.append(module_name)
|
|
|
|
from . import *
|
|
|