0.7 now requires a global SQLAlchemy object, like the
following.
There should be only one of this, ideally in the main application file where
you're initializing your tornado.web.Application object.
Once that is in place, the following changes are required.
- Replace the
session_factoryargument with the newly constructedSQLAlchemyinstance.
from tornado.web import Application
from tornado_sqlalchemy import SQLAlchemy
from my_app.handlers import IndexHandler
db = SQLAlchemy(database_url='postgres://user:pass@host/database')
app = Application(((r'/', IndexHandler),), db=db)- Make sure that your database models inherit from
db.Model.
from sqlalchemy import BigInteger, Column, String
db = SQLAlchemy(database_url='postgres://user:pass@host/database')
class User(db.Model):
__tablename__ = 'users'
id = Column(BigInteger, primary_key=True)
username = Column(String(255), unique=True)That should basically be it. If not, please file an issue.