summaryrefslogtreecommitdiff
path: root/examples/sharding/attribute_shard.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-08-03 19:54:16 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-08-03 19:54:16 +0000
commitd3971e8a3a8e29b1b0390a77c670306db36eda4c (patch)
treeec469f460d0359a24754d9a280e2f048241d7867 /examples/sharding/attribute_shard.py
parente7c83bb37133af7b0deaef2fbc0d0fae8a179dfc (diff)
downloadsqlalchemy-d3971e8a3a8e29b1b0390a77c670306db36eda4c.tar.gz
- added hooks for alternate session classes into sessionmaker
- moved shard example/unittest over to sessionmaker
Diffstat (limited to 'examples/sharding/attribute_shard.py')
-rw-r--r--examples/sharding/attribute_shard.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/examples/sharding/attribute_shard.py b/examples/sharding/attribute_shard.py
index e95b978ae..6e4732989 100644
--- a/examples/sharding/attribute_shard.py
+++ b/examples/sharding/attribute_shard.py
@@ -34,13 +34,15 @@ db4 = create_engine('sqlite:///shard4.db', echo=echo)
# step 3. create session function. this binds the shard ids
# to databases within a ShardedSession and returns it.
-def create_session():
- s = ShardedSession(shard_chooser, id_chooser, query_chooser)
- s.bind_shard('north_america', db1)
- s.bind_shard('asia', db2)
- s.bind_shard('europe', db3)
- s.bind_shard('south_america', db4)
- return s
+create_session = sessionmaker(class_=ShardedSession)
+
+create_session.configure(shards={
+ 'north_america':db1,
+ 'asia':db2,
+ 'europe':db3,
+ 'south_america':db4
+})
+
# step 4. table setup.
meta = MetaData()
@@ -143,6 +145,9 @@ def query_chooser(query):
else:
return ids
+# further configure create_session to use these functions
+create_session.configure(shard_chooser=shard_chooser, id_chooser=id_chooser, query_chooser=query_chooser)
+
# step 6. mapped classes.
class WeatherLocation(object):
def __init__(self, continent, city):