diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-01-13 20:00:25 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-01-13 20:00:25 +0000 |
commit | 2d65e9772d9b96d0392e253e5fb9433e71e18393 (patch) | |
tree | 44e26df71ac6be95bc5e60ed97ef8ecacb3c0ca5 /examples/beaker_caching/relation_caching.py | |
parent | db4af57e206b059a8d3e78a971834982fa8aa062 (diff) | |
download | sqlalchemy-2d65e9772d9b96d0392e253e5fb9433e71e18393.tar.gz |
add more examples, start basic
Diffstat (limited to 'examples/beaker_caching/relation_caching.py')
-rw-r--r-- | examples/beaker_caching/relation_caching.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/beaker_caching/relation_caching.py b/examples/beaker_caching/relation_caching.py new file mode 100644 index 000000000..b4508ba1e --- /dev/null +++ b/examples/beaker_caching/relation_caching.py @@ -0,0 +1,25 @@ +"""relation_caching.py + +Load a set of Person and Address objects, specifying that +related PostalCode, City, Country objects should be pulled from long +term cache. + +""" +import __init__ # if running as a script +from model import Person, Address, cache_address_bits +from meta import Session +from sqlalchemy.orm import eagerload +import os + +for p in Session.query(Person).options(eagerload(Person.addresses), cache_address_bits): + print p.format_full() + + +print "\n\nIf this was the first run of relation_caching.py, SQL was likely emitted to "\ + "load postal codes, cities, countries.\n"\ + "If run a second time, only a single SQL statement will run - all "\ + "related data is pulled from cache.\n"\ + "To clear the cache, delete the directory %r. \n"\ + "This will cause a re-load of cities, postal codes and countries on "\ + "the next run.\n"\ + % os.path.join(__init__.root, 'container_file') |