On Tue, Nov 4, 2008 at 02:29, Lenn0x <[EMAIL PROTECTED]> wrote: > > Hi > > I was wondering if someone might be able to point me in the right > direction. I am aware of the sharding capabilities of SQLAlchemy and > was wondering if anyone has done this using Elixir? Let me give an > example of what I am trying to accomplish: > > def setShard(id): > # do code that will fetch the shard ID based on the input ID > supplied) > # set the connection to the correct database server > # ... set ? > pass > > def find_by_id(user_id): > setShard(user_id) > User.query.filter_by(user_id = user_id) > > I do not want to build logic in each model of how to determine the > shard, it would be much easier if i could just set the connection > before hand, so models like (User) that I use after that would use > that database server. > > I was thinking about just setting metadata.bind = db2_server > > But since this is an RPC like application, it seems to be this could > have race conditions since metadata is a global yes?
Indeed. This doesn't seem like a good idea. I'd recommend you do exactly as you would in plain SQLAlchemy. That is, provide a special "session factory", and bind through the shard mechanism. See http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/examples/sharding/attribute_shard.py -- Gaƫtan de Menten http://openhex.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "SQLElixir" 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/sqlelixir?hl=en -~----------~----~----~----~------~----~------~--~---
