# pk so we just return all shard ids. often, youd want to do some
# kind of round-robin strategy here so that requests are evenly
# distributed among DBs
-def id_chooser(ident):
+def id_chooser(query, ident):
return ['north_america', 'asia', 'europe', 'south_america']
# query_chooser. this also returns a list of shard ids, which can
the future as participating in that shard.
id_chooser
- a callable, passed a tuple of identity values, which should return
- a list of shard ids where the ID might reside. The databases will
- be queried in the order of this listing.
+ a callable, passed a query and a tuple of identity values,
+ which should return a list of shard ids where the ID might
+ reside. The databases will be queried in the order of this
+ listing.
query_chooser
for a given Query, returns the list of shard_ids where the query
if self._shard_id is not None:
return super(ShardedQuery, self).get(ident)
else:
- for shard_id in self.id_chooser(ident):
+ for shard_id in self.id_chooser(self, ident):
o = self.set_shard(shard_id).get(ident, **kwargs)
if o is not None:
return o
if self._shard_id is not None:
return super(ShardedQuery, self).load(ident)
else:
- for shard_id in self.id_chooser(ident):
+ for shard_id in self.id_chooser(self, ident):
o = self.set_shard(shard_id).load(ident, raiseerr=False, **kwargs)
if o is not None:
return o
else:
return shard_chooser(mapper, instance.location)
- def id_chooser(ident):
+ def id_chooser(query, ident):
return ['north_america', 'asia', 'europe', 'south_america']
def query_chooser(query):