On Friday, June 21, 2013 2:23:54 PM UTC-4, Michael Bayer wrote: > > fairly recently i wrote up as much as I could come up with on this, which > you can see first in the Session FAQ: > > http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#session-frequently-asked-questions > > > and then regarding scoped_session in: > > http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#using-thread-local-scope-with-web-applications > >
oh this is great thanks. i didn't see that, and then started looking through the wiki's FAQ http://www.sqlalchemy.org/trac/wiki/FAQ I'd add a link to the wiki, but I don't have edit privs. I don't generally bother trying to make a "container" for all these things, > usually they're defined in some module like "myapp.meta". A module in > Python is a namespaced object like any other, so there's no need for a > MyApplication kind of class. Everyone seems to make those. Also the > "sessionmaker" is an element of the scoped_session so I don't have it as > it's own name; if I really want to make a new Session that isn't part of > the usual scoped context I'll say my_scoped_session.session_factory(). > re:container -- I built out my SqlAlchemy management for Pyramid as a 3rd party library. I just pass in a link to the package with my models and a db connection string; it does the rest for me, examining all the objects in the model for applicability and mapping them, setting up the cleanups, etc. It makes rapid prototyping something really easy. > I have the ScopedSession as the facade to the database - the Engine itself > is an element of the session and similarly I don't refer to it anywhere > once it's been set up and assigned to a session. If I want it, I say > my_scoped_session.bind. If I'm binding multiple engines to a single > session maybe I'd have a lookup for those cases where i need it. > My current app has two databases that I refer to individually, so I have > MySessionOne and MySessionTwo (better names in the real app). > ... yes. Though I'll use remove() so that the current Session is discarded > entirely. I use patterns where I attach extra things to a Session as the > request proceeds. > ... > Just use the scoped_session as needed there's no setup to be done, the > close() beforehand makes sure its clean for the next request. > ... > no need, sessions should always be clean when a request ends, that's when > that thread/process/wahtever is about to go dormant and you don't want any > garbage lying around. > ... > Core API should be through Session.execute() in any case so the Session > would have you covered. > thanks for all this. I'm going to go through all the docs you pointed me to, and make sure everything is set nicely. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.