On Feb 14, 6:02 pm, Jonathan Vanasco <[email protected]> wrote: > 3. i haven't figured out yet if its possible to handle multiple db > connections in pyramid. in pylons i have "sqlalchemy.write.url" and > "sqlalchemy.read.url" and handle multiple databases due to master/ > slave clustering. in order to get widespread appeal, something like > this needs to be very apparent and easy to do - Rails accomplishes > this in a few lines of configs.
Turns out to be really easy. I had nearly figured it out myself in about 20 minutes of poking around but was still slightly stuck, when I happened to re-read Mike's "Pyramid Migration Guide" : https://bytebucket.org/sluggo/pyramid-docs/wiki/html/migration.html. In your config file you just add additional prefixes. For example the default sqlalchemy prefix is "sqlalchemy." You could have a two- engine scenario by making up any two prefixes, say, "sqlalchemy1." and "sqlalchemy2." ... or "spam." and "eggs." You also set up multiple db URIs instead of just one, so there's where you prepare to point your different engines at different databases, potentially even with different user accounts, etc. Then in the place where the basic pyramid template instantiates a database engine, you instantiate two or more, as needed. And where the basic template initializes one set of model classes, you go ahead and import two or more sets of model classes, whatever you need to do to tie down whatever ORM or other database handling code that is needed. All in all it was like 30 minutes from when I asked myself that same question - "so how do I open two DBs at once with this so I can get some transitional and migration work done?" - to the time I had both my old and new databases running side by side. And I'm not exactly the quickest on picking up new paradigms, often needing more examples that I would like to admit. -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
