~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to examples/beaker_caching/relation_caching.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski, Jakub Wilk, Piotr Ożarowski
  • Date: 2013-07-06 20:53:52 UTC
  • mfrom: (1.4.23) (16.1.17 experimental)
  • Revision ID: package-import@ubuntu.com-20130706205352-ryppl1eto3illd79
Tags: 0.8.2-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Piotr Ożarowski ]
* New upstream release
* Upload to unstable
* Build depend on python3-all instead of -dev, extensions are not built for
  Python 3.X 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""relationship_caching.py
2
 
 
3
 
Load a set of Person and Address objects, specifying that
4
 
related PostalCode, City, Country objects should be pulled from long
5
 
term cache.
6
 
 
7
 
"""
8
 
from environment import Session, root
9
 
from model import Person, Address, cache_address_bits
10
 
from sqlalchemy.orm import joinedload
11
 
import os
12
 
 
13
 
for p in Session.query(Person).options(joinedload(Person.addresses), cache_address_bits):
14
 
    print p.format_full()
15
 
 
16
 
 
17
 
print "\n\nIf this was the first run of relationship_caching.py, SQL was likely emitted to "\
18
 
        "load postal codes, cities, countries.\n"\
19
 
        "If run a second time, only a single SQL statement will run - all "\
20
 
        "related data is pulled from cache.\n"\
21
 
        "To clear the cache, delete the directory %r.  \n"\
22
 
        "This will cause a re-load of cities, postal codes and countries on "\
23
 
        "the next run.\n"\
24
 
        % os.path.join(root, 'container_file')