File: __init__.py

package info (click to toggle)
sqlalchemy 2.0.40%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 26,404 kB
  • sloc: python: 410,002; makefile: 230; sh: 7
file content (35 lines) | stat: -rw-r--r-- 1,036 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
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("shrew")
    shrew["cuteness"] = 5
    shrew["weasel-like"] = False
    shrew["poisonous"] = True

    session.add(shrew)
    session.flush()

    q = session.query(Animal).filter(
        Animal.facts.any(
            and_(AnimalFact.key == "weasel-like", AnimalFact.value == True)
        )
    )
    print("weasel-like animals", q.all())

.. autosource::

"""