engine = create_engine(SQLALCHEMY_DATABASE_URI, echo=True) # Connect to database # engine = create_engine(SQLALCHEMY_DATABASE_URI) # Connect to database SSMS_DB_Base.metadata.create_all(engine) # Create models
@contextmanager defsession_scope(): """Provide a transactional scope around a series of operations.""" s = sessionmaker(bind=engine)() s.expire_on_commit = False try: yield s s.commit() except: s.rollback() raise finally: s.close()