summaryrefslogtreecommitdiff
path: root/examples/dogpile_caching/advanced.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-01-06 01:14:26 -0500
committermike bayer <mike_mp@zzzcomputing.com>2019-01-06 17:34:50 +0000
commit1e1a38e7801f410f244e4bbb44ec795ae152e04e (patch)
tree28e725c5c8188bd0cfd133d1e268dbca9b524978 /examples/dogpile_caching/advanced.py
parent404e69426b05a82d905cbb3ad33adafccddb00dd (diff)
downloadsqlalchemy-1e1a38e7801f410f244e4bbb44ec795ae152e04e.tar.gz
Run black -l 79 against all source files
This is a straight reformat run using black as is, with no edits applied at all. The black run will format code consistently, however in some cases that are prevalent in SQLAlchemy code it produces too-long lines. The too-long lines will be resolved in the following commit that will resolve all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
Diffstat (limited to 'examples/dogpile_caching/advanced.py')
-rw-r--r--examples/dogpile_caching/advanced.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/examples/dogpile_caching/advanced.py b/examples/dogpile_caching/advanced.py
index dc2ed0771..8f395bd7b 100644
--- a/examples/dogpile_caching/advanced.py
+++ b/examples/dogpile_caching/advanced.py
@@ -7,6 +7,7 @@ from .environment import Session
from .model import Person, cache_address_bits
from .caching_query import FromCache, RelationshipCache
+
def load_name_range(start, end, invalidate=False):
"""Load Person objects on a range of names.
@@ -24,10 +25,14 @@ def load_name_range(start, end, invalidate=False):
SQL that emits for unloaded Person objects as well as the distribution
of data within the cache.
"""
- q = Session.query(Person).\
- filter(Person.name.between("person %.2d" % start, "person %.2d" % end)).\
- options(cache_address_bits).\
- options(FromCache("default", "name_range"))
+ q = (
+ Session.query(Person)
+ .filter(
+ Person.name.between("person %.2d" % start, "person %.2d" % end)
+ )
+ .options(cache_address_bits)
+ .options(FromCache("default", "name_range"))
+ )
# have the "addresses" collection cached separately
# each lazyload of Person.addresses loads from cache.
@@ -37,7 +42,7 @@ def load_name_range(start, end, invalidate=False):
# be cached together. This issues a bigger SQL statement and caches
# a single, larger value in the cache per person rather than two
# separate ones.
- #q = q.options(joinedload(Person.addresses))
+ # q = q.options(joinedload(Person.addresses))
# if requested, invalidate the cache on current criterion.
if invalidate:
@@ -45,6 +50,7 @@ def load_name_range(start, end, invalidate=False):
return q.all()
+
print("two through twelve, possibly from cache:\n")
print(", ".join([p.name for p in load_name_range(2, 12)]))
@@ -61,7 +67,9 @@ print(", ".join([p.name for p in load_name_range(25, 40, True)]))
# illustrate the address loading from either cache/already
# on the Person
-print("\n\nPeople plus addresses, two through twelve, addresses possibly from cache")
+print(
+ "\n\nPeople plus addresses, two through twelve, addresses possibly from cache"
+)
for p in load_name_range(2, 12):
print(p.format_full())
@@ -71,5 +79,7 @@ print("\n\nPeople plus addresses, two through twelve, addresses from cache")
for p in load_name_range(2, 12):
print(p.format_full())
-print("\n\nIf this was the first run of advanced.py, try "\
- "a second run. Only one SQL statement will be emitted.")
+print(
+ "\n\nIf this was the first run of advanced.py, try "
+ "a second run. Only one SQL statement will be emitted."
+)