mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-22 08:32:09 -04:00
1e1a38e780
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
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
"""
|
|
Illustrates "vertical table" mappings.
|
|
|
|
A "vertical table" refers to a technique where individual attributes
|
|
of an object are stored as distinct rows in a table. The "vertical
|
|
table" technique is used to persist objects which can have a varied
|
|
set of attributes, at the expense of simple query control and brevity.
|
|
It is commonly found in content/document management systems in order
|
|
to represent user-created structures flexibly.
|
|
|
|
Two variants on the approach are given. In the second, each row
|
|
references a "datatype" which contains information about the type of
|
|
information stored in the attribute, such as integer, string, or date.
|
|
|
|
|
|
Example::
|
|
|
|
shrew = Animal(u'shrew')
|
|
shrew[u'cuteness'] = 5
|
|
shrew[u'weasel-like'] = False
|
|
shrew[u'poisonous'] = True
|
|
|
|
session.add(shrew)
|
|
session.flush()
|
|
|
|
q = (session.query(Animal).
|
|
filter(Animal.facts.any(
|
|
and_(AnimalFact.key == u'weasel-like',
|
|
AnimalFact.value == True))))
|
|
print 'weasel-like animals', q.all()
|
|
|
|
.. autosource::
|
|
|
|
"""
|