On Aug 22, 2012, at 5:33 PM, David McKeone wrote: > I suppose I should be more clear. This is really a long term question, I was > just looking for some kind of answer now because I don't want to code myself > into a corner in the short term. Currently I can make requests outside of a > flask request context by using the app.test_request_context() context > manager, and it seems to do the right thing. > > In the long term I'm looking for 2 (maybe 3) things that I already get from > Flask-SQLAlchemy: > 1) Session teardown for every request (looks like that is done with a call to > session.remove() in the request teardown)
you can use the Session provided by flask-sqlalchemy, which has the nice quality that it aligns itself with the current request. He can make that feature more open-ended though. I should be able to say flask_sqlalchemy.request_scope(some_sessionmaker) to set that up with any sessionmaker of my choosing. > 2) Debug query tracking for use with Flask-DebugToolbar (Plus compatibility > with other plug-ins that may expect Flask-SQLAlchemy) the logic i see in flask-sqlalchemy related to debug tracking has no connection to the "db.Model" class at all. its just some connection events which are ultimately established via the "SQLAlchemy" class. Your existing non-flask SQLA models will participate in the Session/Engine used by Flask without impacting this functionaltiy. > 3) The Model.query behaviour (it's nice, but I could live without it, since > its really just syntactic) scoped_session has a query_property available, so you can pull that from Flask's scoped_session using SQLAlchemy public APIs like this: sa = SQLAlchemy(db) # API: http://docs.sqlalchemy.org/en/rel_0_7/orm/session.html#sqlalchemy.orm.scoping.ScopedSession.query_property Base.query = sa.session.query_property or to get exactly flask's, which appears to add three methods get_or_404, first_or_404, paginate: Base.query = flask_sqlalchemy._QueryProperty(sa) > > > Didn't say this explicitly; for now I will do what you say and forge ahead > with things. I think I see the path, but I'll make sure to let you (the > list) know if I run into trouble. good luck ! -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.