On Nov 24, 2010, at 1:49 PM, Mike Orr wrote: > So do we need multiple sessions? I'm not sure we've defined the use > cases clearly enough, which runs the risk that we'll make an API that > won't be adequate anyway. So I'm inclined to use a single session. We > can always add a multisession object later under a different name, and > share the default session with it.
Indeed, I think to begin with, we can provide a single session you can retrieve with: from pyramid_sqla import get_dbsession DBSession = get_dbsession() When you setup the db sessions with setup_dbsessions, you can provide multiple engine configs if desired, and use get_engine to fetch it by the name you called it. > If people are using the same ORM objects to copy data from one db to > another, I think they can use a 'bind' argument on the specific calls. Yup, so they would do that themselves after fetching the engine they want. I think that keeps it pretty simple still and obvious that pyramid_sqla isn't doing any magic, its just holding onto the engines that were setup, and can bind an engine to a session during 'setup_dbsessions' if desired (ie, using table reflection which requires them to be bound immediately). I unfortunately won't have time to crank this out before Monday as I'm heading out later today for Thanksgiving. Given what I've said about its proposed API though, maybe a quick prototype for the purposes of the tutorial can be built by someone. Here's a quick Python mockup: http://pastie.org/1324151 I haven't tested it, but it should provide enough guidance to illustrate the concept. In your models at module scope you do: from pyramid_sqla import get_dbsession DBsession = get_dbsession() In your __init__.py to configure: from pyramid_sqla import setup_dbsession # in config, assuming all the SQLA settings are under 'sqlalchemy.' setup_dbsession(settings) That's it, its now ready for use. If you look at the function signature, it provides the option of not immediately binding the engine created to the session if desired. Ie. you're going to call setup_dbsession several times to configure additional engines, perhaps: setup_dbsession(settings, name='read_slave', prefix='sqlalchemy.read.') setup_dbsession(settings, name='write_master', prefix='sqlalchemy.write.', immediate_bind=False) Then its up to the user during runtime to use get_dbengine and re-bind the session during the request if they want to change to the write master, etc. Cheers, Ben -- You received this message because you are subscribed to the Google Groups "pylons-devel" group. To post to this group, send email to pylons-de...@googlegroups.com. To unsubscribe from this group, send email to pylons-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-devel?hl=en.