SQLAlchemy 0.4 Documentation
Version: 0.4.6 Last Updated: 06/08/08 21:47:23
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 set_shard(self, shard_id)
back to section top
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.
class ShardedSession(Session)
def __init__(self, shard_chooser, id_chooser, query_chooser, shards=None, **kwargs)
back to section top
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.
Up: API Documentation
|
Previous: module sqlalchemy.orm.session
|
Next: module sqlalchemy.ext.declarative
