> -----Original Message----- > From: sqlalchemy@googlegroups.com > [mailto:[EMAIL PROTECTED] On Behalf Of lilo > Sent: 10 June 2008 17:23 > To: sqlalchemy > Subject: [sqlalchemy] select db engine with create_session > > > can someone tell me how session chooses the right db engine to insert > records in this example: > http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/exampl > es/sharding/attribute_shard.py#L184? >
(I've never used the sharding support before, so this is a guess) On line 150, the create_session factory function gets configured with the shard_chooser, id_chooser and query_chooser functions. The shard_chooser function is defined on line 111 and looks like this: 111 def shard_chooser(mapper, instance, clause=None): 112 if isinstance(instance, WeatherLocation): 113 return shard_lookup[instance.continent] 114 else: 115 return shard_chooser(mapper, instance.location) So if the instance being saved is a WeatherLocation object, then the shard_lookup dictionary is used to return the appropriate db engine. Otherwise, the instance is assumed to be a Report object, and so it calls itself recursively with the Report's location. I hope that helps - I'm sure someone will correct me if I'm wrong. Simon --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---