diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-10-21 16:54:42 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-10-21 16:54:42 -0400 |
| commit | 39d17c76df542d0040c2c8db2d2e3dc897b5cce5 (patch) | |
| tree | f5aeba8be0f61c0db8d5ba0e76efdaa593cd85c4 /examples/dogpile_caching/fixture_data.py | |
| parent | f2bc0ddcb496e6a0cb0a0ad88c7c055dbf0c11a7 (diff) | |
| download | sqlalchemy-39d17c76df542d0040c2c8db2d2e3dc897b5cce5.tar.gz | |
- converted beaker demo to dogpile.cache, [ticket:2589]
Diffstat (limited to 'examples/dogpile_caching/fixture_data.py')
| -rw-r--r-- | examples/dogpile_caching/fixture_data.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/examples/dogpile_caching/fixture_data.py b/examples/dogpile_caching/fixture_data.py new file mode 100644 index 000000000..1db75ea05 --- /dev/null +++ b/examples/dogpile_caching/fixture_data.py @@ -0,0 +1,52 @@ +"""fixture_data.py + +Installs some sample data. Here we have a handful of postal codes for a few US/ +Canadian cities. Then, 100 Person records are installed, each with a +randomly selected postal code. + +""" +from environment import Session, Base +from model import City, Country, PostalCode, Person, Address +import random + +def install(): + Base.metadata.create_all(Session().bind) + + data = [ + ('Chicago', 'United States', ('60601', '60602', '60603', '60604')), + ('Montreal', 'Canada', ('H2S 3K9', 'H2B 1V4', 'H7G 2T8')), + ('Edmonton', 'Canada', ('T5J 1R9', 'T5J 1Z4', 'T5H 1P6')), + ('New York', 'United States', + ('10001', '10002', '10003', '10004', '10005', '10006')), + ('San Francisco', 'United States', + ('94102', '94103', '94104', '94105', '94107', '94108')) + ] + + countries = {} + all_post_codes = [] + for city, country, postcodes in data: + try: + country = countries[country] + except KeyError: + countries[country] = country = Country(country) + + city = City(city, country) + pc = [PostalCode(code, city) for code in postcodes] + Session.add_all(pc) + all_post_codes.extend(pc) + + for i in xrange(1, 51): + person = Person( + "person %.2d" % i, + Address( + street="street %.2d" % i, + postal_code=all_post_codes[ + random.randint(0, len(all_post_codes) - 1)] + ) + ) + Session.add(person) + + Session.commit() + + # start the demo fresh + Session.remove()
\ No newline at end of file |
