SQLAlchemy 0.4 Documentation

Multiple Pages | One Page
Version: 0.4.3 Last Updated: 02/14/08 18:54:07

module sqlalchemy.orm.shard

Defines a rudimental 'horizontal sharding' system which allows a Session to distribute queries and persistence operations across multiple databases.

For a usage example, see the example examples/sharding/attribute_shard.py.

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
Up: API Documentation | Previous: module sqlalchemy.orm.session | Next: module sqlalchemy.ext.associationproxy