# SQLAlchemy 0.4 Documentation

Multiple Pages | One Page
Version: 0.4.1 Last Updated: 11/18/07 17:50:18

### module sqlalchemy.orm.shard

### class ShardedQuery(Query)

def __init__(self, *args, **kwargs)

Construct a new `ShardedQuery`.

def get(self, ident, **kwargs)
def load(self, ident, **kwargs)
def set_shard(self, shard_id)

return a new query, limited to a single shard ID.

all subsequent operations with the returned query will be against the single shard regardless of other state.

back to section top

### class ShardedSession(Session)

def __init__(self, shard_chooser, id_chooser, query_chooser, shards=None, **kwargs)

construct a ShardedSession.

shard_chooser
  a callable which, passed a Mapper, a mapped instance, and possibly a SQL clause, returns a shard ID. this id may be based off of the attributes present within the object, or on some round-robin scheme. If the scheme is based on a selection, it should set whatever state on the instance to mark it in the future as participating in that shard.
id_chooser
  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 should be issued. Results from all shards returned will be combined together into a single listing.

def bind_shard(self, shard_id, bind)
def connection(self, mapper=None, instance=None, shard_id=None, **kwargs)
def get_bind(self, mapper, shard_id=None, instance=None, clause=None)
back to section top