File: glossary.html

package info (click to toggle)
sqlalchemy 0.9.8%2Bdfsg-0.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,952 kB
  • ctags: 24,534
  • sloc: python: 152,282; ansic: 1,346; makefile: 257; xml: 17
file content (1094 lines) | stat: -rw-r--r-- 93,248 bytes parent folder | download
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        
        <title>
            
    
                Glossary
             &mdash;
    SQLAlchemy 0.9 Documentation

        </title>

        
            <!-- begin iterate through SQLA + sphinx environment css_files -->
                <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
                <link rel="stylesheet" href="_static/docs.css" type="text/css" />
                <link rel="stylesheet" href="_static/sphinx_paramlinks.css" type="text/css" />
                <link rel="stylesheet" href="_static/changelog.css" type="text/css" />
            <!-- end iterate through SQLA + sphinx environment css_files -->
        

        

    

    <!-- begin layout.mako headers -->

    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
          URL_ROOT:    './',
          VERSION:     '0.9.8',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: '.html'
      };
    </script>

    <!-- begin iterate through sphinx environment script_files -->
        <script type="text/javascript" src="_static/jquery.js"></script>
        <script type="text/javascript" src="_static/underscore.js"></script>
        <script type="text/javascript" src="_static/doctools.js"></script>
    <!-- end iterate through sphinx environment script_files -->

    <script type="text/javascript" src="_static/detectmobile.js"></script>
    <script type="text/javascript" src="_static/init.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
        <link rel="copyright" title="Copyright" href="copyright.html" />
    <link rel="top" title="SQLAlchemy 0.9 Documentation" href="index.html" />
    <!-- end layout.mako headers -->


    </head>
    <body>
        















<div id="docs-container">





<div id="docs-top-navigation-container" class="body-background">
<div id="docs-header">
    <div id="docs-version-header">
        Release: <span class="version-num">0.9.8</span> | Release Date: October 13, 2014
    </div>

    <h1>SQLAlchemy 0.9 Documentation</h1>

</div>
</div>

<div id="docs-body-container">

    <div id="fixed-sidebar" class="withsidebar">


        <div id="docs-sidebar-popout">
            <h3><a href="index.html">SQLAlchemy 0.9 Documentation</a></h3>

            <p id="sidebar-paginate">
                    <a href="index.html" title="SQLAlchemy 0.9 Documentation">Up</a> |

            </p>

            <p id="sidebar-topnav">
                <a href="index.html">Contents</a> |
                <a href="genindex.html">Index</a>
            </p>

            <div id="sidebar-search">
                <form class="search" action="search.html" method="get">
                  <input type="text" name="q" size="12" /> <input type="submit" value="Search" />
                  <input type="hidden" name="check_keywords" value="yes" />
                  <input type="hidden" name="area" value="default" />
                </form>
            </div>

        </div>

        <div id="docs-sidebar">

        <h3><a href="#">            
                Glossary
            
        </a></h3>
        <ul>
<li><a class="reference internal" href="#">Glossary</a></li>
</ul>




        </div>

    </div>

    

    <div id="docs-body" class="withsidebar" >
        
<div class="section" id="glossary">
<span id="id1"></span><h1>Glossary<a class="headerlink" href="#glossary" title="Permalink to this headline">ΒΆ</a></h1>
<dl class="glossary docutils">
<dt id="term-acid"><span id="term-acid-model"></span>ACID<br />ACID model</dt>
<dd><p class="first">An acronym for &#8220;Atomicity, Consistency, Isolation,
Durability&#8221;; a set of properties that guarantee that
database transactions are processed reliably.
(via Wikipedia)</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="#term-atomicity"><em class="xref std std-term">atomicity</em></a></p>
<p><a class="reference internal" href="#term-consistency"><em class="xref std std-term">consistency</em></a></p>
<p><a class="reference internal" href="#term-isolation"><em class="xref std std-term">isolation</em></a></p>
<p><a class="reference internal" href="#term-durability"><em class="xref std std-term">durability</em></a></p>
<p class="last"><a class="reference external" href="http://en.wikipedia.org/wiki/ACID_Model">http://en.wikipedia.org/wiki/ACID_Model</a></p>
</div>
</dd>
<dt id="term-annotations">annotations</dt>
<dd><p class="first">Annotations are a concept used internally by SQLAlchemy in order to store
additional information along with <a class="reference internal" href="core/sqlelement.html#sqlalchemy.sql.expression.ClauseElement" title="sqlalchemy.sql.expression.ClauseElement"><tt class="xref py py-class docutils literal"><span class="pre">ClauseElement</span></tt></a> objects.  A Python
dictionary is associated with a copy of the object, which contains key/value
pairs significant to various internal systems, mostly within the ORM:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">some_column</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="s">&#39;some_column&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">)</span>
<span class="n">some_column_annotated</span> <span class="o">=</span> <span class="n">some_column</span><span class="o">.</span><span class="n">_annotate</span><span class="p">({</span><span class="s">&quot;entity&quot;</span><span class="p">:</span> <span class="n">User</span><span class="p">})</span></pre></div>
</div>
<p class="last">The annotation system differs from the public dictionary <a class="reference internal" href="core/metadata.html#sqlalchemy.schema.Column.info" title="sqlalchemy.schema.Column.info"><tt class="xref py py-attr docutils literal"><span class="pre">Column.info</span></tt></a>
in that the above annotation operation creates a <em>copy</em> of the new <a class="reference internal" href="core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a>,
rather than considering all annotation values to be part of a single
unit.  The ORM creates copies of expression objects in order to
apply annotations that are specific to their context, such as to differentiate
columns that should render themselves as relative to a joined-inheritance
entity versus those which should render relative to their immediate parent
table alone, as well as to differentiate columns within the &#8220;join condition&#8221;
of a relationship where the column in some cases needs to be expressed
in terms of one particular table alias or another, based on its position
within the join expression.</p>
</dd>
<dt id="term-association-relationship">association relationship</dt>
<dd><p class="first">A two-tiered <a class="reference internal" href="#term-relationship"><em class="xref std std-term">relationship</em></a> which links two tables
together using an association table in the middle.  The
association relationship differs from a <a class="reference internal" href="#term-many-to-many"><em class="xref std std-term">many to many</em></a>
relationship in that the many-to-many table is mapped
by a full class, rather than invisibly handled by the
<a class="reference internal" href="orm/relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">sqlalchemy.orm.relationship()</span></tt></a> construct as in the case
with many-to-many, so that additional attributes are
explicitly available.</p>
<p>For example, if we wanted to associate employees with
projects, also storing the specific role for that employee
with the project, the relational schema might look like:</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">employee</span> <span class="p">(</span>
    <span class="n">id</span> <span class="nb">INTEGER</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span>
    <span class="n">name</span> <span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="p">)</span>

<span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">project</span> <span class="p">(</span>
    <span class="n">id</span> <span class="nb">INTEGER</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span>
    <span class="n">name</span> <span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="p">)</span>

<span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">employee_project</span> <span class="p">(</span>
    <span class="n">employee_id</span> <span class="nb">INTEGER</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span>
    <span class="n">project_id</span> <span class="nb">INTEGER</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span>
    <span class="n">role_name</span> <span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">30</span><span class="p">),</span>
    <span class="k">FOREIGN</span> <span class="k">KEY</span> <span class="n">employee_id</span> <span class="k">REFERENCES</span> <span class="n">employee</span><span class="p">(</span><span class="n">id</span><span class="p">),</span>
    <span class="k">FOREIGN</span> <span class="k">KEY</span> <span class="n">project_id</span> <span class="k">REFERENCES</span> <span class="n">project</span><span class="p">(</span><span class="n">id</span><span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
<p>A SQLAlchemy declarative mapping for the above might look like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Employee</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;employee&#39;</span>

    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="p">)</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">))</span>


<span class="k">class</span> <span class="nc">Project</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;project&#39;</span>

    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="p">)</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">))</span>


<span class="k">class</span> <span class="nc">EmployeeProject</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;employee_project&#39;</span>

    <span class="n">employee_id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s">&#39;employee.id&#39;</span><span class="p">),</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">project_id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s">&#39;project.id&#39;</span><span class="p">),</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">role_name</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">))</span>

    <span class="n">project</span> <span class="o">=</span> <span class="n">relationship</span><span class="p">(</span><span class="s">&quot;Project&quot;</span><span class="p">,</span> <span class="n">backref</span><span class="o">=</span><span class="s">&quot;project_employees&quot;</span><span class="p">)</span>
    <span class="n">employee</span> <span class="o">=</span> <span class="n">relationship</span><span class="p">(</span><span class="s">&quot;Employee&quot;</span><span class="p">,</span> <span class="n">backref</span><span class="o">=</span><span class="s">&quot;employee_projects&quot;</span><span class="p">)</span></pre></div>
</div>
<p>Employees can be added to a project given a role name:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">proj</span> <span class="o">=</span> <span class="n">Project</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;Client A&quot;</span><span class="p">)</span>

<span class="n">emp1</span> <span class="o">=</span> <span class="n">Employee</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;emp1&quot;</span><span class="p">)</span>
<span class="n">emp2</span> <span class="o">=</span> <span class="n">Employee</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;emp2&quot;</span><span class="p">)</span>

<span class="n">proj</span><span class="o">.</span><span class="n">project_employees</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span>
    <span class="n">EmployeeProject</span><span class="p">(</span><span class="n">employee</span><span class="o">=</span><span class="n">emp1</span><span class="p">,</span> <span class="n">role</span><span class="o">=</span><span class="s">&quot;tech lead&quot;</span><span class="p">),</span>
    <span class="n">EmployeeProject</span><span class="p">(</span><span class="n">employee</span><span class="o">=</span><span class="n">emp2</span><span class="p">,</span> <span class="n">role</span><span class="o">=</span><span class="s">&quot;account executive&quot;</span><span class="p">)</span>
<span class="p">])</span></pre></div>
</div>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#term-many-to-many"><em class="xref std std-term">many to many</em></a></p>
</div>
</dd>
<dt id="term-atomicity">atomicity</dt>
<dd><p class="first">Atomicity is one of the components of the <a class="reference internal" href="#term-acid"><em class="xref std std-term">ACID</em></a> model,
and requires that each transaction is &#8220;all or nothing&#8221;:
if one part of the transaction fails, the entire transaction
fails, and the database state is left unchanged. An atomic
system must guarantee atomicity in each and every situation,
including power failures, errors, and crashes.
(via Wikipedia)</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="#term-acid"><em class="xref std std-term">ACID</em></a></p>
<p class="last"><a class="reference external" href="http://en.wikipedia.org/wiki/Atomicity_(database_systems">http://en.wikipedia.org/wiki/Atomicity_(database_systems</a>)</p>
</div>
</dd>
<dt id="term-backref"><span id="term-bidirectional-relationship"></span>backref<br />bidirectional relationship</dt>
<dd><p class="first">An extension to the <a class="reference internal" href="#term-relationship"><em class="xref std std-term">relationship</em></a> system whereby two
distinct <a class="reference internal" href="orm/relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> objects can be
mutually associated with each other, such that they coordinate
in memory as changes occur to either side.   The most common
way these two relationships are constructed is by using
the <a class="reference internal" href="orm/relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> function explicitly
for one side and specifying the <tt class="docutils literal"><span class="pre">backref</span></tt> keyword to it so that
the other <a class="reference internal" href="orm/relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> is created
automatically.  We can illustrate this against the example we&#8217;ve
used in <a class="reference internal" href="#term-one-to-many"><em class="xref std std-term">one to many</em></a> as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Department</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;department&#39;</span>
    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">))</span>
    <span class="n">employees</span> <span class="o">=</span> <span class="n">relationship</span><span class="p">(</span><span class="s">&quot;Employee&quot;</span><span class="p">,</span> <span class="n">backref</span><span class="o">=</span><span class="s">&quot;department&quot;</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">Employee</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;employee&#39;</span>
    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">))</span>
    <span class="n">dep_id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s">&#39;department.id&#39;</span><span class="p">))</span></pre></div>
</div>
<p>A backref can be applied to any relationship, including one to many,
many to one, and <a class="reference internal" href="#term-many-to-many"><em class="xref std std-term">many to many</em></a>.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="#term-relationship"><em class="xref std std-term">relationship</em></a></p>
<p><a class="reference internal" href="#term-one-to-many"><em class="xref std std-term">one to many</em></a></p>
<p><a class="reference internal" href="#term-many-to-one"><em class="xref std std-term">many to one</em></a></p>
<p class="last"><a class="reference internal" href="#term-many-to-many"><em class="xref std std-term">many to many</em></a></p>
</div>
</dd>
<dt id="term-candidate-key">candidate key</dt>
<dd><p class="first">A <em class="xref std std-term">relational algebra</em> term referring to an attribute or set
of attributes that form a uniquely identifying key for a
row.  A row may have more than one candidate key, each of which
is suitable for use as the primary key of that row.
The primary key of a table is always a candidate key.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="#term-primary-key"><em class="xref std std-term">primary key</em></a></p>
<p class="last"><a class="reference external" href="http://en.wikipedia.org/wiki/Candidate_key">http://en.wikipedia.org/wiki/Candidate_key</a></p>
</div>
</dd>
<dt id="term-check-constraint">check constraint</dt>
<dd><p class="first">A check constraint is a
condition that defines valid data when adding or updating an
entry in a table of a relational database. A check constraint
is applied to each row in the table.</p>
<p>(via Wikipedia)</p>
<p>A check constraint can be added to a table in standard
SQL using <a class="reference internal" href="#term-ddl"><em class="xref std std-term">DDL</em></a> like the following:</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">ALTER</span> <span class="k">TABLE</span> <span class="n">distributors</span> <span class="k">ADD</span> <span class="k">CONSTRAINT</span> <span class="n">zipchk</span> <span class="k">CHECK</span> <span class="p">(</span><span class="k">char_length</span><span class="p">(</span><span class="n">zipcode</span><span class="p">)</span> <span class="o">=</span> <span class="mi">5</span><span class="p">);</span></pre></div>
</div>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference external" href="http://en.wikipedia.org/wiki/Check_constraint">http://en.wikipedia.org/wiki/Check_constraint</a></p>
</div>
</dd>
<dt id="term-columns-clause">columns clause</dt>
<dd><p class="first">The portion of the <tt class="docutils literal"><span class="pre">SELECT</span></tt> statement which enumerates the
SQL expressions to be returned in the result set.  The expressions
follow the <tt class="docutils literal"><span class="pre">SELECT</span></tt> keyword directly and are a comma-separated
list of individual expressions.</p>
<p>E.g.:</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">SELECT</span> <span class="n">user_account</span><span class="p">.</span><span class="n">name</span><span class="p">,</span> <span class="n">user_account</span><span class="p">.</span><span class="n">email</span>
<span class="k">FROM</span> <span class="n">user_account</span> <span class="k">WHERE</span> <span class="n">user_account</span><span class="p">.</span><span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;fred&#39;</span></pre></div>
</div>
<p class="last">Above, the list of columns <tt class="docutils literal"><span class="pre">user_acount.name</span></tt>,
<tt class="docutils literal"><span class="pre">user_account.email</span></tt> is the columns clause of the <tt class="docutils literal"><span class="pre">SELECT</span></tt>.</p>
</dd>
<dt id="term-consistency">consistency</dt>
<dd><p class="first">Consistency is one of the compoments of the <a class="reference internal" href="#term-acid"><em class="xref std std-term">ACID</em></a> model,
and ensures that any transaction will
bring the database from one valid state to another. Any data
written to the database must be valid according to all defined
rules, including but not limited to <a class="reference internal" href="#term-constraints"><em class="xref std std-term">constraints</em></a>, cascades,
triggers, and any combination thereof.
(via Wikipedia)</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="#term-acid"><em class="xref std std-term">ACID</em></a></p>
<p class="last"><a class="reference external" href="http://en.wikipedia.org/wiki/Consistency_(database_systems">http://en.wikipedia.org/wiki/Consistency_(database_systems</a>)</p>
</div>
</dd>
<dt id="term-constraint"><span id="term-constraints"></span><span id="term-constrained"></span>constraint<br />constraints<br />constrained</dt>
<dd>Rules established within a relational database that ensure
the validity and consistency of data.   Common forms
of constraint include <a class="reference internal" href="#term-primary-key-constraint"><em class="xref std std-term">primary key constraint</em></a>,
<a class="reference internal" href="#term-foreign-key-constraint"><em class="xref std std-term">foreign key constraint</em></a>, and <a class="reference internal" href="#term-check-constraint"><em class="xref std std-term">check constraint</em></a>.</dd>
<dt id="term-correlates"><span id="term-correlated-subquery"></span><span id="term-correlated-subqueries"></span>correlates<br />correlated subquery<br />correlated subqueries</dt>
<dd><p class="first">A <a class="reference internal" href="#term-subquery"><em class="xref std std-term">subquery</em></a> is correlated if it depends on data in the
enclosing <tt class="docutils literal"><span class="pre">SELECT</span></tt>.</p>
<p>Below, a subquery selects the aggregate value <tt class="docutils literal"><span class="pre">MIN(a.id)</span></tt>
from the <tt class="docutils literal"><span class="pre">email_address</span></tt> table, such that
it will be invoked for each value of <tt class="docutils literal"><span class="pre">user_account.id</span></tt>, correlating
the value of this column against the <tt class="docutils literal"><span class="pre">email_address.user_account_id</span></tt>
column:</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">SELECT</span> <span class="n">user_account</span><span class="p">.</span><span class="n">name</span><span class="p">,</span> <span class="n">email_address</span><span class="p">.</span><span class="n">email</span>
 <span class="k">FROM</span> <span class="n">user_account</span>
 <span class="k">JOIN</span> <span class="n">email_address</span> <span class="k">ON</span> <span class="n">user_account</span><span class="p">.</span><span class="n">id</span><span class="o">=</span><span class="n">email_address</span><span class="p">.</span><span class="n">user_account_id</span>
 <span class="k">WHERE</span> <span class="n">email_address</span><span class="p">.</span><span class="n">id</span> <span class="o">=</span> <span class="p">(</span>
    <span class="k">SELECT</span> <span class="k">MIN</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">id</span><span class="p">)</span> <span class="k">FROM</span> <span class="n">email_address</span> <span class="k">AS</span> <span class="n">a</span>
    <span class="k">WHERE</span> <span class="n">a</span><span class="p">.</span><span class="n">user_account_id</span><span class="o">=</span><span class="n">user_account</span><span class="p">.</span><span class="n">id</span>
 <span class="p">)</span></pre></div>
</div>
<p>The above subquery refers to the <tt class="docutils literal"><span class="pre">user_account</span></tt> table, which is not itself
in the <tt class="docutils literal"><span class="pre">FROM</span></tt> clause of this nested query.   Instead, the <tt class="docutils literal"><span class="pre">user_account</span></tt>
table is received from the enclosing query, where each row selected from
<tt class="docutils literal"><span class="pre">user_account</span></tt> results in a distinct execution of the subquery.</p>
<p>A correlated subquery is in most cases present in the <a class="reference internal" href="#term-where-clause"><em class="xref std std-term">WHERE clause</em></a>
or <a class="reference internal" href="#term-columns-clause"><em class="xref std std-term">columns clause</em></a> of the immediately enclosing <tt class="docutils literal"><span class="pre">SELECT</span></tt>
statement, as well as in the ORDER BY or HAVING clause.</p>
<p>In less common cases, a correlated subquery may be present in the
<a class="reference internal" href="#term-from-clause"><em class="xref std std-term">FROM clause</em></a> of an enclosing <tt class="docutils literal"><span class="pre">SELECT</span></tt>; in these cases the
correlation is typically due to the enclosing <tt class="docutils literal"><span class="pre">SELECT</span></tt> itself being
enclosed in the WHERE,
ORDER BY, columns or HAVING clause of another <tt class="docutils literal"><span class="pre">SELECT</span></tt>, such as:</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">SELECT</span> <span class="n">parent</span><span class="p">.</span><span class="n">id</span> <span class="k">FROM</span> <span class="n">parent</span>
<span class="k">WHERE</span> <span class="k">EXISTS</span> <span class="p">(</span>
    <span class="k">SELECT</span> <span class="o">*</span> <span class="k">FROM</span> <span class="p">(</span>
        <span class="k">SELECT</span> <span class="n">child</span><span class="p">.</span><span class="n">id</span> <span class="k">AS</span> <span class="n">id</span><span class="p">,</span> <span class="n">child</span><span class="p">.</span><span class="n">parent_id</span> <span class="k">AS</span> <span class="n">parent_id</span><span class="p">,</span> <span class="n">child</span><span class="p">.</span><span class="n">pos</span> <span class="k">AS</span> <span class="n">pos</span>
        <span class="k">FROM</span> <span class="n">child</span>
        <span class="k">WHERE</span> <span class="n">child</span><span class="p">.</span><span class="n">parent_id</span> <span class="o">=</span> <span class="n">parent</span><span class="p">.</span><span class="n">id</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">child</span><span class="p">.</span><span class="n">pos</span>
    <span class="k">LIMIT</span> <span class="mi">3</span><span class="p">)</span>
<span class="k">WHERE</span> <span class="n">id</span> <span class="o">=</span> <span class="mi">7</span><span class="p">)</span></pre></div>
</div>
<p class="last">Correlation from one <tt class="docutils literal"><span class="pre">SELECT</span></tt> directly to one which encloses the correlated
query via its <tt class="docutils literal"><span class="pre">FROM</span></tt>
clause is not possible, because the correlation can only proceed once the
original source rows from the enclosing statement&#8217;s FROM clause are available.</p>
</dd>
<dt id="term-crud">crud</dt>
<dd>An acronym meaning &#8220;Create, Update, Delete&#8221;.  The term in SQL refers to the
set of operations that create, modify and delete data from the database,
also known as <em class="xref std std-term">DML</em>, and typically refers to the <tt class="docutils literal"><span class="pre">INSERT</span></tt>,
<tt class="docutils literal"><span class="pre">UPDATE</span></tt>, and <tt class="docutils literal"><span class="pre">DELETE</span></tt> statements.</dd>
<dt id="term-dbapi">DBAPI</dt>
<dd><p class="first">DBAPI is shorthand for the phrase &#8220;Python Database API
Specification&#8221;.  This is a widely used specification
within Python to define common usage patterns for all
database connection packages.   The DBAPI is a &#8220;low level&#8221;
API which is typically the lowest level system used
in a Python application to talk to a database.  SQLAlchemy&#8217;s
<em class="xref std std-term">dialect</em> system is constructed around the
operation of the DBAPI, providing individual dialect
classes which service a specific DBAPI on top of a
specific database engine; for example, the <a class="reference internal" href="core/engines.html#sqlalchemy.create_engine" title="sqlalchemy.create_engine"><tt class="xref py py-func docutils literal"><span class="pre">create_engine()</span></tt></a>
URL <tt class="docutils literal"><span class="pre">postgresql+psycopg2://&#64;localhost/test</span></tt>
refers to the <a class="reference internal" href="dialects/postgresql.html#module-sqlalchemy.dialects.postgresql.psycopg2" title="sqlalchemy.dialects.postgresql.psycopg2"><tt class="xref py py-mod docutils literal"><span class="pre">psycopg2</span></tt></a>
DBAPI/dialect combination, whereas the URL <tt class="docutils literal"><span class="pre">mysql+mysqldb://&#64;localhost/test</span></tt>
refers to the <a class="reference internal" href="dialects/mysql.html#module-sqlalchemy.dialects.mysql.mysqldb" title="sqlalchemy.dialects.mysql.mysqldb"><tt class="xref py py-mod docutils literal"><span class="pre">MySQL</span> <span class="pre">for</span> <span class="pre">Python</span></tt></a>
DBAPI DBAPI/dialect combination.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference external" href="http://www.python.org/dev/peps/pep-0249/">PEP 249 - Python Database API Specification v2.0</a></p>
</div>
</dd>
<dt id="term-ddl">DDL</dt>
<dd><p class="first">An acronym for <em>Data Definition Language</em>.  DDL is the subset
of SQL that relational databases use to configure tables, constraints,
and other permanent objects within a database schema.  SQLAlchemy
provides a rich API for constructing and emitting DDL expressions.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="core/metadata.html"><em>Describing Databases with MetaData</em></a></p>
<p class="last"><a class="reference external" href="http://en.wikipedia.org/wiki/Data_definition_language">DDL (via Wikipedia)</a></p>
</div>
</dd>
<dt id="term-descriptor"><span id="term-descriptors"></span>descriptor<br />descriptors</dt>
<dd><p class="first">In Python, a descriptor is an object attribute with β€œbinding behavior”, one whose attribute access has been overridden by methods in the <a class="reference external" href="http://docs.python.org/howto/descriptor.html">descriptor protocol</a>.
Those methods are __get__(), __set__(), and __delete__(). If any of those methods are defined
for an object, it is said to be a descriptor.</p>
<p>In SQLAlchemy, descriptors are used heavily in order to provide attribute behavior
on mapped classes.   When a class is mapped as such:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyClass</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;foo&#39;</span>

    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">data</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">)</span></pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">MyClass</span></tt> class will be <a class="reference internal" href="#term-mapped"><em class="xref std std-term">mapped</em></a> when its definition
is complete, at which point the <tt class="docutils literal"><span class="pre">id</span></tt> and <tt class="docutils literal"><span class="pre">data</span></tt> attributes,
starting out as <a class="reference internal" href="core/metadata.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects, will be replaced
by the <a class="reference internal" href="#term-instrumentation"><em class="xref std std-term">instrumentation</em></a> system with instances
of <a class="reference internal" href="orm/internals.html#sqlalchemy.orm.attributes.InstrumentedAttribute" title="sqlalchemy.orm.attributes.InstrumentedAttribute"><tt class="xref py py-class docutils literal"><span class="pre">InstrumentedAttribute</span></tt></a>, which are descriptors that
provide the above mentioned <tt class="docutils literal"><span class="pre">__get__()</span></tt>, <tt class="docutils literal"><span class="pre">__set__()</span></tt> and
<tt class="docutils literal"><span class="pre">__delete__()</span></tt> methods.   The <a class="reference internal" href="orm/internals.html#sqlalchemy.orm.attributes.InstrumentedAttribute" title="sqlalchemy.orm.attributes.InstrumentedAttribute"><tt class="xref py py-class docutils literal"><span class="pre">InstrumentedAttribute</span></tt></a>
will generate a SQL expression when used at the class level:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="n">MyClass</span><span class="o">.</span><span class="n">data</span> <span class="o">==</span> <span class="mi">5</span>
<span class="go">data = :data_1</span></pre></div>
</div>
<p>and at the instance level, keeps track of changes to values,
and also <a class="reference internal" href="#term-lazy-loads"><em class="xref std std-term">lazy loads</em></a> unloaded attributes
from the database:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">m1</span> <span class="o">=</span> <span class="n">MyClass</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m1</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m1</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s">&quot;some data&quot;</span>

<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">inspect</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">inspect</span><span class="p">(</span><span class="n">m1</span><span class="p">)</span><span class="o">.</span><span class="n">attrs</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">added</span>
<span class="go">&quot;some data&quot;</span></pre></div>
</div>
</dd>
<dt id="term-detached">detached</dt>
<dd><p class="first">This describes one of the four major object states which
an object can have within a <a class="reference internal" href="#term-session"><em class="xref std std-term">session</em></a>; a detached object
is an object that has a database identity (i.e. a primary key)
but is not associated with any session.  An object that
was previously <a class="reference internal" href="#term-persistent"><em class="xref std std-term">persistent</em></a> and was removed from its
session either because it was expunged, or the owning
session was closed, moves into the detached state.
The detached state is generally used when objects are being
moved between sessions or when being moved to/from an external
object cache.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="orm/session.html#session-object-states"><em>Quickie Intro to Object States</em></a></p>
</div>
</dd>
<dt id="term-discriminator">discriminator</dt>
<dd><p class="first">A result-set column which is used during <a class="reference internal" href="#term-polymorphic"><em class="xref std std-term">polymorphic</em></a> loading
to determine what kind of mapped class should be applied to a particular
incoming result row.   In SQLAlchemy, the classes are always part
of a hierarchy mapping using inheritance mapping.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="orm/inheritance.html"><em>Mapping Class Inheritance Hierarchies</em></a></p>
</div>
</dd>
<dt id="term-domain-model">domain model</dt>
<dd><p class="first">A domain model in problem solving and software engineering is a conceptual model of all the topics related to a specific problem. It describes the various entities, their attributes, roles, and relationships, plus the constraints that govern the problem domain.</p>
<p>(via Wikipedia)</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference external" href="http://en.wikipedia.org/wiki/Domain_model">Domain Model (wikipedia)</a></p>
</div>
</dd>
<dt id="term-durability">durability</dt>
<dd><p class="first">Durability is a property of the <a class="reference internal" href="#term-acid"><em class="xref std std-term">ACID</em></a> model
which means that once a transaction has been committed,
it will remain so, even in the event of power loss, crashes,
or errors. In a relational database, for instance, once a
group of SQL statements execute, the results need to be stored
permanently (even if the database crashes immediately
thereafter).
(via Wikipedia)</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="#term-acid"><em class="xref std std-term">ACID</em></a></p>
<p class="last"><a class="reference external" href="http://en.wikipedia.org/wiki/Durability_(database_systems">http://en.wikipedia.org/wiki/Durability_(database_systems</a>)</p>
</div>
</dd>
<dt id="term-expire"><span id="term-expires"></span><span id="term-expiring"></span>expire<br />expires<br />expiring</dt>
<dd><p class="first">In the SQLAlchemy ORM, refers to when the data in a <a class="reference internal" href="#term-persistent"><em class="xref std std-term">persistent</em></a>
or sometimes <a class="reference internal" href="#term-detached"><em class="xref std std-term">detached</em></a> object is erased, such that when
the object&#8217;s attributes are next accessed, a <a class="reference internal" href="#term-lazy-load"><em class="xref std std-term">lazy load</em></a> SQL
query will be emitted in order to refresh the data for this object
as stored in the current ongoing transaction.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="orm/session.html#session-expire"><em>Refreshing / Expiring</em></a></p>
</div>
</dd>
<dt id="term-foreign-key-constraint">foreign key constraint</dt>
<dd><p class="first">A referential constraint between two tables.  A foreign key is a field or set of fields in a
relational table that matches a <a class="reference internal" href="#term-candidate-key"><em class="xref std std-term">candidate key</em></a> of another table.
The foreign key can be used to cross-reference tables.
(via Wikipedia)</p>
<p>A foreign key constraint can be added to a table in standard
SQL using <a class="reference internal" href="#term-ddl"><em class="xref std std-term">DDL</em></a> like the following:</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">ALTER</span> <span class="k">TABLE</span> <span class="n">employee</span> <span class="k">ADD</span> <span class="k">CONSTRAINT</span> <span class="n">dep_id_fk</span>
<span class="k">FOREIGN</span> <span class="k">KEY</span> <span class="p">(</span><span class="n">employee</span><span class="p">)</span> <span class="k">REFERENCES</span> <span class="n">department</span> <span class="p">(</span><span class="n">dep_id</span><span class="p">)</span></pre></div>
</div>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference external" href="http://en.wikipedia.org/wiki/Foreign_key_constraint">http://en.wikipedia.org/wiki/Foreign_key_constraint</a></p>
</div>
</dd>
<dt id="term-from-clause">FROM clause</dt>
<dd><p class="first">The portion of the <tt class="docutils literal"><span class="pre">SELECT</span></tt> statement which incicates the initial
source of rows.</p>
<p>A simple <tt class="docutils literal"><span class="pre">SELECT</span></tt> will feature one or more table names in its
FROM clause.  Multiple sources are separated by a comma:</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">SELECT</span> <span class="k">user</span><span class="p">.</span><span class="n">name</span><span class="p">,</span> <span class="n">address</span><span class="p">.</span><span class="n">email_address</span>
<span class="k">FROM</span> <span class="k">user</span><span class="p">,</span> <span class="n">address</span>
<span class="k">WHERE</span> <span class="k">user</span><span class="p">.</span><span class="n">id</span><span class="o">=</span><span class="n">address</span><span class="p">.</span><span class="n">user_id</span></pre></div>
</div>
<p>The FROM clause is also where explicit joins are specified.  We can
rewrite the above <tt class="docutils literal"><span class="pre">SELECT</span></tt> using a single <tt class="docutils literal"><span class="pre">FROM</span></tt> element which consists
of a <tt class="docutils literal"><span class="pre">JOIN</span></tt> of the two tables:</p>
<div class="last highlight-sql"><div class="highlight"><pre><span class="k">SELECT</span> <span class="k">user</span><span class="p">.</span><span class="n">name</span><span class="p">,</span> <span class="n">address</span><span class="p">.</span><span class="n">email_address</span>
<span class="k">FROM</span> <span class="k">user</span> <span class="k">JOIN</span> <span class="n">address</span> <span class="k">ON</span> <span class="k">user</span><span class="p">.</span><span class="n">id</span><span class="o">=</span><span class="n">address</span><span class="p">.</span><span class="n">user_id</span></pre></div>
</div>
</dd>
<dt id="term-generative">generative</dt>
<dd>A term that SQLAlchemy uses to refer what&#8217;s normally known
as <a class="reference internal" href="#term-method-chaining"><em class="xref std std-term">method chaining</em></a>; see that term for details.</dd>
<dt id="term-identity-map">identity map</dt>
<dd><p class="first">A mapping between Python objects and their database identities.
The identity map is a collection that&#8217;s associated with an
ORM <a class="reference internal" href="#term-session"><em class="xref std std-term">session</em></a> object, and maintains a single instance
of every database object keyed to its identity.   The advantage
to this pattern is that all operations which occur for a particular
database identity are transparently coordinated onto a single
object instance.  When using an identity map in conjunction with
an <a class="reference internal" href="#term-isolated"><em class="xref std std-term">isolated</em></a> transaction, having a reference
to an object that&#8217;s known to have a particular primary key can
be considered from a practical standpoint to be a
proxy to the actual database row.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last">Martin Fowler - Identity Map - <a class="reference external" href="http://martinfowler.com/eaaCatalog/identityMap.html">http://martinfowler.com/eaaCatalog/identityMap.html</a></p>
</div>
</dd>
<dt id="term-instrumentation"><span id="term-instrumented"></span>instrumentation<br />instrumented</dt>
<dd>Instrumentation refers to the process of augmenting the functionality
and attribute set of a particular class.   Ideally, the
behavior of the class should remain close to a regular
class, except that additional behviors and features are
made available.  The SQLAlchemy <a class="reference internal" href="#term-mapping"><em class="xref std std-term">mapping</em></a> process,
among other things, adds database-enabled <a class="reference internal" href="#term-descriptors"><em class="xref std std-term">descriptors</em></a>
to a mapped
class which each represent a particular database column
or relationship to a related class.</dd>
<dt id="term-isolation"><span id="term-isolated"></span>isolation<br />isolated</dt>
<dd><p class="first">The isolation property of the <a class="reference internal" href="#term-acid"><em class="xref std std-term">ACID</em></a> model
ensures that the concurrent execution
of transactions results in a system state that would be
obtained if transactions were executed serially, i.e. one
after the other. Each transaction must execute in total
isolation i.e. if T1 and T2 execute concurrently then each
should remain independent of the other.
(via Wikipedia)</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="#term-acid"><em class="xref std std-term">ACID</em></a></p>
<p class="last"><a class="reference external" href="http://en.wikipedia.org/wiki/Isolation_(database_systems">http://en.wikipedia.org/wiki/Isolation_(database_systems</a>)</p>
</div>
</dd>
<dt id="term-lazy-load"><span id="term-lazy-loads"></span><span id="term-lazy-loading"></span>lazy load<br />lazy loads<br />lazy loading</dt>
<dd><p class="first">In object relational mapping, a &#8220;lazy load&#8221; refers to an
attribute that does not contain its database-side value
for some period of time, typically when the object is
first loaded.  Instead, the attribute receives a
<em>memoization</em> that causes it to go out to the database
and load its data when it&#8217;s first used.   Using this pattern,
the complexity and time spent within object fetches can
sometimes be reduced, in that
attributes for related tables don&#8217;t need to be addressed
immediately.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference external" href="http://martinfowler.com/eaaCatalog/lazyLoad.html">Lazy Load (on Martin Fowler)</a></p>
<p><a class="reference internal" href="#term-n-plus-one-problem"><em class="xref std std-term">N plus one problem</em></a></p>
<p class="last"><a class="reference internal" href="orm/loading.html"><em>Relationship Loading Techniques</em></a></p>
</div>
</dd>
<dt id="term-many-to-many">many to many</dt>
<dd><p class="first">A style of <a class="reference internal" href="orm/relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">sqlalchemy.orm.relationship()</span></tt></a> which links two tables together
via an intermediary table in the middle.   Using this configuration,
any number of rows on the left side may refer to any number of
rows on the right, and vice versa.</p>
<p>A schema where employees can be associated with projects:</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">employee</span> <span class="p">(</span>
    <span class="n">id</span> <span class="nb">INTEGER</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span>
    <span class="n">name</span> <span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="p">)</span>

<span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">project</span> <span class="p">(</span>
    <span class="n">id</span> <span class="nb">INTEGER</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span>
    <span class="n">name</span> <span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="p">)</span>

<span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">employee_project</span> <span class="p">(</span>
    <span class="n">employee_id</span> <span class="nb">INTEGER</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span>
    <span class="n">project_id</span> <span class="nb">INTEGER</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span>
    <span class="k">FOREIGN</span> <span class="k">KEY</span> <span class="n">employee_id</span> <span class="k">REFERENCES</span> <span class="n">employee</span><span class="p">(</span><span class="n">id</span><span class="p">),</span>
    <span class="k">FOREIGN</span> <span class="k">KEY</span> <span class="n">project_id</span> <span class="k">REFERENCES</span> <span class="n">project</span><span class="p">(</span><span class="n">id</span><span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
<p>Above, the <tt class="docutils literal"><span class="pre">employee_project</span></tt> table is the many-to-many table,
which naturally forms a composite primary key consisting
of the primary key from each related table.</p>
<p>In SQLAlchemy, the <a class="reference internal" href="orm/relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">sqlalchemy.orm.relationship()</span></tt></a> function
can represent this style of relationship in a mostly
transparent fashion, where the many-to-many table is
specified using plain table metadata:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Employee</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;employee&#39;</span>

    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="p">)</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">))</span>

    <span class="n">projects</span> <span class="o">=</span> <span class="n">relationship</span><span class="p">(</span>
        <span class="s">&quot;Project&quot;</span><span class="p">,</span>
        <span class="n">secondary</span><span class="o">=</span><span class="n">Table</span><span class="p">(</span><span class="s">&#39;employee_project&#39;</span><span class="p">,</span> <span class="n">Base</span><span class="o">.</span><span class="n">metadata</span><span class="p">,</span>
                    <span class="n">Column</span><span class="p">(</span><span class="s">&quot;employee_id&quot;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s">&#39;employee.id&#39;</span><span class="p">),</span>
                                <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
                    <span class="n">Column</span><span class="p">(</span><span class="s">&quot;project_id&quot;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s">&#39;project.id&#39;</span><span class="p">),</span>
                                <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
                <span class="p">),</span>
        <span class="n">backref</span><span class="o">=</span><span class="s">&quot;employees&quot;</span>
        <span class="p">)</span>

<span class="k">class</span> <span class="nc">Project</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;project&#39;</span>

    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="p">)</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">))</span></pre></div>
</div>
<p>Above, the <tt class="docutils literal"><span class="pre">Employee.projects</span></tt> and back-referencing <tt class="docutils literal"><span class="pre">Project.employees</span></tt>
collections are defined:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">proj</span> <span class="o">=</span> <span class="n">Project</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;Client A&quot;</span><span class="p">)</span>

<span class="n">emp1</span> <span class="o">=</span> <span class="n">Employee</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;emp1&quot;</span><span class="p">)</span>
<span class="n">emp2</span> <span class="o">=</span> <span class="n">Employee</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&quot;emp2&quot;</span><span class="p">)</span>

<span class="n">proj</span><span class="o">.</span><span class="n">employees</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="n">emp1</span><span class="p">,</span> <span class="n">emp2</span><span class="p">])</span></pre></div>
</div>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="#term-association-relationship"><em class="xref std std-term">association relationship</em></a></p>
<p><a class="reference internal" href="#term-relationship"><em class="xref std std-term">relationship</em></a></p>
<p><a class="reference internal" href="#term-one-to-many"><em class="xref std std-term">one to many</em></a></p>
<p class="last"><a class="reference internal" href="#term-many-to-one"><em class="xref std std-term">many to one</em></a></p>
</div>
</dd>
<dt id="term-many-to-one">many to one</dt>
<dd><p class="first">A style of <a class="reference internal" href="orm/relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> which links
a foreign key in the parent mapper&#8217;s table to the primary
key of a related table.   Each parent object can
then refer to exactly zero or one related object.</p>
<p>The related objects in turn will have an implicit or
explicit <a class="reference internal" href="#term-one-to-many"><em class="xref std std-term">one to many</em></a> relationship to any number
of parent objects that refer to them.</p>
<p>An example many to one schema (which, note, is identical
to the <a class="reference internal" href="#term-one-to-many"><em class="xref std std-term">one to many</em></a> schema):</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">department</span> <span class="p">(</span>
    <span class="n">id</span> <span class="nb">INTEGER</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span>
    <span class="n">name</span> <span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="p">)</span>

<span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">employee</span> <span class="p">(</span>
    <span class="n">id</span> <span class="nb">INTEGER</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span>
    <span class="n">name</span> <span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">30</span><span class="p">),</span>
    <span class="n">dep_id</span> <span class="nb">INTEGER</span> <span class="k">REFERENCES</span> <span class="n">department</span><span class="p">(</span><span class="n">id</span><span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
<p>The relationship from <tt class="docutils literal"><span class="pre">employee</span></tt> to <tt class="docutils literal"><span class="pre">department</span></tt> is
many to one, since many employee records can be associated with a
single department.  A SQLAlchemy mapping might look like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Department</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;department&#39;</span>
    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">))</span>

<span class="k">class</span> <span class="nc">Employee</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;employee&#39;</span>
    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">))</span>
    <span class="n">dep_id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s">&#39;department.id&#39;</span><span class="p">))</span>
    <span class="n">department</span> <span class="o">=</span> <span class="n">relationship</span><span class="p">(</span><span class="s">&quot;Department&quot;</span><span class="p">)</span></pre></div>
</div>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="#term-relationship"><em class="xref std std-term">relationship</em></a></p>
<p><a class="reference internal" href="#term-one-to-many"><em class="xref std std-term">one to many</em></a></p>
<p class="last"><a class="reference internal" href="#term-backref"><em class="xref std std-term">backref</em></a></p>
</div>
</dd>
<dt id="term-mapping"><span id="term-mapped"></span>mapping<br />mapped</dt>
<dd>We say a class is &#8220;mapped&#8221; when it has been passed through the
<a class="reference internal" href="orm/mapper_config.html#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">orm.mapper()</span></tt></a> function.   This process associates the
class with a database table or other <em class="xref std std-term">selectable</em>
construct, so that instances of it can be persisted
using a <a class="reference internal" href="orm/session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> as well as loaded using a
<a class="reference internal" href="orm/query.html#sqlalchemy.orm.query.Query" title="sqlalchemy.orm.query.Query"><tt class="xref py py-class docutils literal"><span class="pre">Query</span></tt></a>.</dd>
<dt id="term-method-chaining">method chaining</dt>
<dd><p class="first">An object-oriented technique whereby the state of an object
is constructed by calling methods on the object.   The
object features any number of methods, each of which return
a new object (or in some cases the same object) with
additional state added to the object.</p>
<p>The two SQLAlchemy objects that make the most use of
method chaining are the <a class="reference internal" href="core/selectable.html#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a>
object and the <a class="reference internal" href="orm/query.html#sqlalchemy.orm.query.Query" title="sqlalchemy.orm.query.Query"><tt class="xref py py-class docutils literal"><span class="pre">Query</span></tt></a> object.
For example, a <a class="reference internal" href="core/selectable.html#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> object can
be assigned two expressions to its WHERE clause as well
as an ORDER BY clause by calling upon the <a class="reference internal" href="core/selectable.html#sqlalchemy.sql.expression.Select.where" title="sqlalchemy.sql.expression.Select.where"><tt class="xref py py-meth docutils literal"><span class="pre">where()</span></tt></a>
and <a class="reference internal" href="core/selectable.html#sqlalchemy.sql.expression.Select.order_by" title="sqlalchemy.sql.expression.Select.order_by"><tt class="xref py py-meth docutils literal"><span class="pre">order_by()</span></tt></a> methods:</p>
<div class="highlight-python"><pre>stmt = select([user.c.name]).\
            where(user.c.id &gt; 5).\
            where(user.c.name.like('e%').\
            order_by(user.c.name)</pre>
</div>
<p>Each method call above returns a copy of the original
<a class="reference internal" href="core/selectable.html#sqlalchemy.sql.expression.Select" title="sqlalchemy.sql.expression.Select"><tt class="xref py py-class docutils literal"><span class="pre">Select</span></tt></a> object with additional qualifiers
added.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#term-generative"><em class="xref std std-term">generative</em></a></p>
</div>
</dd>
<dt id="term-n-plus-one-problem">N plus one problem</dt>
<dd><p class="first">The N plus one problem is a common side effect of the
<a class="reference internal" href="#term-lazy-load"><em class="xref std std-term">lazy load</em></a> pattern, whereby an application wishes
to iterate through a related attribute or collection on
each member of a result set of objects, where that
attribute or collection is set to be loaded via the lazy
load pattern.   The net result is that a SELECT statement
is emitted to load the initial result set of parent objects;
then, as the application iterates through each member,
an additional SELECT statement is emitted for each member
in order to load the related attribute or collection for
that member.  The end result is that for a result set of
N parent objects, there will be N + 1 SELECT statements emitted.</p>
<p>The N plus one problem is alleviated using <em class="xref std std-term">eager loading</em>.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="orm/loading.html"><em>Relationship Loading Techniques</em></a></p>
</div>
</dd>
<dt id="term-one-to-many">one to many</dt>
<dd><p class="first">A style of <a class="reference internal" href="orm/relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> which links
the primary key of the parent mapper&#8217;s table to the foreign
key of a related table.   Each unique parent object can
then refer to zero or more unique related objects.</p>
<p>The related objects in turn will have an implicit or
explicit <a class="reference internal" href="#term-many-to-one"><em class="xref std std-term">many to one</em></a> relationship to their parent
object.</p>
<p>An example one to many schema (which, note, is identical
to the <a class="reference internal" href="#term-many-to-one"><em class="xref std std-term">many to one</em></a> schema):</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">department</span> <span class="p">(</span>
    <span class="n">id</span> <span class="nb">INTEGER</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span>
    <span class="n">name</span> <span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="p">)</span>

<span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">employee</span> <span class="p">(</span>
    <span class="n">id</span> <span class="nb">INTEGER</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span>
    <span class="n">name</span> <span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">30</span><span class="p">),</span>
    <span class="n">dep_id</span> <span class="nb">INTEGER</span> <span class="k">REFERENCES</span> <span class="n">department</span><span class="p">(</span><span class="n">id</span><span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
<p>The relationship from <tt class="docutils literal"><span class="pre">department</span></tt> to <tt class="docutils literal"><span class="pre">employee</span></tt> is
one to many, since many employee records can be associated with a
single department.  A SQLAlchemy mapping might look like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Department</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;department&#39;</span>
    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">))</span>
    <span class="n">employees</span> <span class="o">=</span> <span class="n">relationship</span><span class="p">(</span><span class="s">&quot;Employee&quot;</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">Employee</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
    <span class="n">__tablename__</span> <span class="o">=</span> <span class="s">&#39;employee&#39;</span>
    <span class="nb">id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">(</span><span class="mi">30</span><span class="p">))</span>
    <span class="n">dep_id</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s">&#39;department.id&#39;</span><span class="p">))</span></pre></div>
</div>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="#term-relationship"><em class="xref std std-term">relationship</em></a></p>
<p><a class="reference internal" href="#term-many-to-one"><em class="xref std std-term">many to one</em></a></p>
<p class="last"><a class="reference internal" href="#term-backref"><em class="xref std std-term">backref</em></a></p>
</div>
</dd>
<dt id="term-pending">pending</dt>
<dd><p class="first">This describes one of the four major object states which
an object can have within a <a class="reference internal" href="#term-session"><em class="xref std std-term">session</em></a>; a pending object
is a new object that doesn&#8217;t have any database identity,
but has been recently associated with a session.   When
the session emits a flush and the row is inserted, the
object moves to the <a class="reference internal" href="#term-persistent"><em class="xref std std-term">persistent</em></a> state.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="orm/session.html#session-object-states"><em>Quickie Intro to Object States</em></a></p>
</div>
</dd>
<dt id="term-persistent">persistent</dt>
<dd><p class="first">This describes one of the four major object states which
an object can have within a <a class="reference internal" href="#term-session"><em class="xref std std-term">session</em></a>; a persistent object
is an object that has a database identity (i.e. a primary key)
and is currently associated with a session.   Any object
that was previously <a class="reference internal" href="#term-pending"><em class="xref std std-term">pending</em></a> and has now been inserted
is in the persistent state, as is any object that&#8217;s
been loaded by the session from the database.   When a
persistent object is removed from a session, it is known
as <a class="reference internal" href="#term-detached"><em class="xref std std-term">detached</em></a>.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="orm/session.html#session-object-states"><em>Quickie Intro to Object States</em></a></p>
</div>
</dd>
<dt id="term-polymorphic"><span id="term-polymorphically"></span>polymorphic<br />polymorphically</dt>
<dd><p class="first">Refers to a function that handles several types at once.  In SQLAlchemy,
the term is usually applied to the concept of an ORM mapped class
whereby a query operation will return different subclasses
based on information in the result set, typically by checking the
value of a particular column in the result known as the <a class="reference internal" href="#term-discriminator"><em class="xref std std-term">discriminator</em></a>.</p>
<p class="last">Polymorphic loading in SQLAlchemy implies that a one or a
combination of three different schemes are used to map a hierarchy
of classes; &#8220;joined&#8221;, &#8220;single&#8221;, and &#8220;concrete&#8221;.   The section
<a class="reference internal" href="orm/inheritance.html"><em>Mapping Class Inheritance Hierarchies</em></a> describes inheritance mapping fully.</p>
</dd>
<dt id="term-primary-key"><span id="term-primary-key-constraint"></span>primary key<br />primary key constraint</dt>
<dd><p class="first">A <a class="reference internal" href="#term-constraint"><em class="xref std std-term">constraint</em></a> that uniquely defines the characteristics
of each <em class="xref std std-term">row</em>. The primary key has to consist of
characteristics that cannot be duplicated by any other row.
The primary key may consist of a single attribute or
multiple attributes in combination.
(via Wikipedia)</p>
<p>The primary key of a table is typically, though not always,
defined within the <tt class="docutils literal"><span class="pre">CREATE</span> <span class="pre">TABLE</span></tt> <a class="reference internal" href="#term-ddl"><em class="xref std std-term">DDL</em></a>:</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">employee</span> <span class="p">(</span>
     <span class="n">emp_id</span> <span class="nb">INTEGER</span><span class="p">,</span>
     <span class="n">emp_name</span> <span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">30</span><span class="p">),</span>
     <span class="n">dep_id</span> <span class="nb">INTEGER</span><span class="p">,</span>
     <span class="k">PRIMARY</span> <span class="k">KEY</span> <span class="p">(</span><span class="n">emp_id</span><span class="p">)</span>
<span class="p">)</span></pre></div>
</div>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference external" href="http://en.wikipedia.org/wiki/Primary_Key">http://en.wikipedia.org/wiki/Primary_Key</a></p>
</div>
</dd>
<dt id="term-relationship"><span id="term-relationships"></span>relationship<br />relationships</dt>
<dd><p class="first">A connecting unit between two mapped classes, corresponding
to some relationship between the two tables in the database.</p>
<p>The relationship is defined using the SQLAlchemy function
<a class="reference internal" href="orm/relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a>.   Once created, SQLAlchemy
inspects the arguments and underlying mappings involved
in order to classify the relationship as one of three types:
<a class="reference internal" href="#term-one-to-many"><em class="xref std std-term">one to many</em></a>, <a class="reference internal" href="#term-many-to-one"><em class="xref std std-term">many to one</em></a>, or <a class="reference internal" href="#term-many-to-many"><em class="xref std std-term">many to many</em></a>.
With this classification, the relationship construct
handles the task of persisting the appropriate linkages
in the database in response to in-memory object associations,
as well as the job of loading object references and collections
into memory based on the current linkages in the
database.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="orm/relationships.html"><em>Relationship Configuration</em></a></p>
</div>
</dd>
<dt id="term-release"><span id="term-releases"></span><span id="term-released"></span>release<br />releases<br />released</dt>
<dd><p class="first">In the context of SQLAlchemy, the term &#8220;released&#8221;
refers to the process of ending the usage of a particular
database connection.    SQLAlchemy features the usage
of connection pools, which allows configurability as to
the lifespan of database connections.   When using a pooled
connection, the process of &#8220;closing&#8221; it, i.e. invoking
a statement like <tt class="docutils literal"><span class="pre">connection.close()</span></tt>, may have the effect
of the connection being returned to an existing pool,
or it may have the effect of actually shutting down the
underlying TCP/IP connection referred to by that connection -
which one takes place depends on configuration as well
as the current state of the pool.  So we used the term
<em>released</em> instead, to mean &#8220;do whatever it is you do
with connections when we&#8217;re done using them&#8221;.</p>
<p>The term will sometimes be used in the phrase, &#8220;release
transactional resources&#8221;, to indicate more explicitly that
what we are actually &#8220;releasing&#8221; is any transactional
state which as accumulated upon the connection.  In most
situations, the proces of selecting from tables, emitting
updates, etc. acquires <a class="reference internal" href="#term-isolated"><em class="xref std std-term">isolated</em></a> state upon
that connection as well as potential row or table locks.
This state is all local to a particular transaction
on the connection, and is released when we emit a rollback.
An important feature of the connection pool is that when
we return a connection to the pool, the <tt class="docutils literal"><span class="pre">connection.rollback()</span></tt>
method of the DBAPI is called as well, so that as the
connection is set up to be used again, it&#8217;s in a &#8220;clean&#8221;
state with no references held to the previous series
of operations.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="core/pooling.html"><em>Connection Pooling</em></a></p>
</div>
</dd>
<dt id="term-returning">RETURNING</dt>
<dd><p class="first">This is a non-SQL standard clause provided in various forms by
certain backends, which provides the service of returning a result
set upon execution of an INSERT, UPDATE or DELETE statement.  Any set
of columns from the matched rows can be returned, as though they were
produced from a SELECT statement.</p>
<p>The RETURNING clause provides both a dramatic performance boost to
common update/select scenarios, including retrieval of inline- or
default- generated primary key values and defaults at the moment they
were created, as well as a way to get at server-generated
default values in an atomic way.</p>
<p>An example of RETURNING, idiomatic to Postgresql, looks like:</p>
<div class="highlight-python"><pre>INSERT INTO user_account (name) VALUES ('new name') RETURNING id, timestamp</pre>
</div>
<p>Above, the INSERT statement will provide upon execution a result set
which includes the values of the columns <tt class="docutils literal"><span class="pre">user_account.id</span></tt> and
<tt class="docutils literal"><span class="pre">user_account.timestamp</span></tt>, which above should have been generated as default
values as they are not included otherwise (but note any series of columns
or SQL expressions can be placed into RETURNING, not just default-value columns).</p>
<p>The backends that currently support
RETURNING or a similar construct are Postgresql, SQL Server, Oracle,
and Firebird.    The Postgresql and Firebird implementations are generally
full featured, whereas the implementations of SQL Server and Oracle
have caveats. On SQL Server, the clause is known as &#8220;OUTPUT INSERTED&#8221;
for INSERT and UPDATE statements and &#8220;OUTPUT DELETED&#8221; for DELETE statements;
the key caveat is that triggers are not supported in conjunction with this
keyword.  On Oracle, it is known as &#8220;RETURNING...INTO&#8221;, and requires that the
value be placed into an OUT paramter, meaning not only is the syntax awkward,
but it can also only be used for one row at a time.</p>
<p class="last">SQLAlchemy&#8217;s <a class="reference internal" href="core/dml.html#sqlalchemy.sql.expression.UpdateBase.returning" title="sqlalchemy.sql.expression.UpdateBase.returning"><tt class="xref py py-meth docutils literal"><span class="pre">UpdateBase.returning()</span></tt></a> system provides a layer of abstraction
on top of the RETURNING systems of these backends to provide a consistent
interface for returning columns.  The ORM also includes many optimizations
that make use of RETURNING when available.</p>
</dd>
<dt id="term-session">Session</dt>
<dd><p class="first">The container or scope for ORM database operations. Sessions
load instances from the database, track changes to mapped
instances and persist changes in a single unit of work when
flushed.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="orm/session.html"><em>Using the Session</em></a></p>
</div>
</dd>
<dt id="term-subquery">subquery</dt>
<dd><p class="first">Refers to a <tt class="docutils literal"><span class="pre">SELECT</span></tt> statement that is embedded within an enclosing
<tt class="docutils literal"><span class="pre">SELECT</span></tt>.</p>
<p>A subquery comes in two general flavors, one known as a &#8220;scalar select&#8221;
which specifically must return exactly one row and one column, and the
other form which acts as a &#8220;derived table&#8221; and serves as a source of
rows for the FROM clause of another select.  A scalar select is eligible
to be placed in the <a class="reference internal" href="#term-where-clause"><em class="xref std std-term">WHERE clause</em></a>, <a class="reference internal" href="#term-columns-clause"><em class="xref std std-term">columns clause</em></a>,
ORDER BY clause or HAVING clause of the enclosing select, whereas the
derived table form is eligible to be placed in the FROM clause of the
enclosing <tt class="docutils literal"><span class="pre">SELECT</span></tt>.</p>
<p>Examples:</p>
<ol class="last arabic">
<li><p class="first">a scalar subquery placed in the <a class="reference internal" href="#term-columns-clause"><em class="xref std std-term">columns clause</em></a> of an enclosing
<tt class="docutils literal"><span class="pre">SELECT</span></tt>.  The subquery in this example is a <a class="reference internal" href="#term-correlated-subquery"><em class="xref std std-term">correlated subquery</em></a> because part
of the rows which it selects from are given via the enclosing statement.</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">SELECT</span> <span class="n">id</span><span class="p">,</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">name</span> <span class="k">FROM</span> <span class="n">address</span> <span class="k">WHERE</span> <span class="n">address</span><span class="p">.</span><span class="n">user_id</span><span class="o">=</span><span class="k">user</span><span class="p">.</span><span class="n">id</span><span class="p">)</span>
<span class="k">FROM</span> <span class="k">user</span></pre></div>
</div>
</li>
<li><p class="first">a scalar subquery placed in the <a class="reference internal" href="#term-where-clause"><em class="xref std std-term">WHERE clause</em></a> of an enclosing
<tt class="docutils literal"><span class="pre">SELECT</span></tt>.  This subquery in this example is not correlated as it selects a fixed result.</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">SELECT</span> <span class="n">id</span><span class="p">,</span> <span class="n">name</span> <span class="k">FROM</span> <span class="k">user</span>
<span class="k">WHERE</span> <span class="n">status</span><span class="o">=</span><span class="p">(</span><span class="k">SELECT</span> <span class="n">status_id</span> <span class="k">FROM</span> <span class="n">status_code</span> <span class="k">WHERE</span> <span class="n">code</span><span class="o">=</span><span class="s1">&#39;C&#39;</span><span class="p">)</span></pre></div>
</div>
</li>
<li><p class="first">a derived table subquery placed in the <a class="reference internal" href="#term-from-clause"><em class="xref std std-term">FROM clause</em></a> of an enclosing
<tt class="docutils literal"><span class="pre">SELECT</span></tt>.   Such a subquery is almost always given an alias name.</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">SELECT</span> <span class="k">user</span><span class="p">.</span><span class="n">id</span><span class="p">,</span> <span class="k">user</span><span class="p">.</span><span class="n">name</span><span class="p">,</span> <span class="n">ad_subq</span><span class="p">.</span><span class="n">email_address</span>
<span class="k">FROM</span>
    <span class="k">user</span> <span class="k">JOIN</span>
    <span class="p">(</span><span class="k">select</span> <span class="n">user_id</span><span class="p">,</span> <span class="n">email_address</span> <span class="k">FROM</span> <span class="n">address</span> <span class="k">WHERE</span> <span class="n">address_type</span><span class="o">=</span><span class="s1">&#39;Q&#39;</span><span class="p">)</span> <span class="k">AS</span> <span class="n">ad_subq</span>
    <span class="k">ON</span> <span class="k">user</span><span class="p">.</span><span class="n">id</span> <span class="o">=</span> <span class="n">ad_subq</span><span class="p">.</span><span class="n">user_id</span></pre></div>
</div>
</li>
</ol>
</dd>
<dt id="term-transient">transient</dt>
<dd><p class="first">This describes one of the four major object states which
an object can have within a <a class="reference internal" href="#term-session"><em class="xref std std-term">session</em></a>; a transient object
is a new object that doesn&#8217;t have any database identity
and has not been associated with a session yet.  When the
object is added to the session, it moves to the
<a class="reference internal" href="#term-pending"><em class="xref std std-term">pending</em></a> state.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="orm/session.html#session-object-states"><em>Quickie Intro to Object States</em></a></p>
</div>
</dd>
<dt id="term-unique-constraint"><span id="term-unique-key-index"></span>unique constraint<br />unique key index</dt>
<dd><p class="first">A unique key index can uniquely identify each row of data
values in a database table. A unique key index comprises a
single column or a set of columns in a single database table.
No two distinct rows or data records in a database table can
have the same data value (or combination of data values) in
those unique key index columns if NULL values are not used.
Depending on its design, a database table may have many unique
key indexes but at most one primary key index.</p>
<p>(via Wikipedia)</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference external" href="http://en.wikipedia.org/wiki/Unique_key#Defining_unique_keys">http://en.wikipedia.org/wiki/Unique_key#Defining_unique_keys</a></p>
</div>
</dd>
<dt id="term-unit-of-work">unit of work</dt>
<dd><p class="first">This pattern is where the system transparently keeps
track of changes to objects and periodically flushes all those
pending changes out to the database. SQLAlchemy&#8217;s Session
implements this pattern fully in a manner similar to that of
Hibernate.</p>
<div class="last admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference external" href="http://martinfowler.com/eaaCatalog/unitOfWork.html">Unit of Work by Martin Fowler</a></p>
<p class="last"><a class="reference internal" href="orm/session.html"><em>Using the Session</em></a></p>
</div>
</dd>
<dt id="term-where-clause">WHERE clause</dt>
<dd><p class="first">The portion of the <tt class="docutils literal"><span class="pre">SELECT</span></tt> statement which indicates criteria
by which rows should be filtered.   It is a single SQL expression
which follows the keyword <tt class="docutils literal"><span class="pre">WHERE</span></tt>.</p>
<div class="highlight-sql"><div class="highlight"><pre><span class="k">SELECT</span> <span class="n">user_account</span><span class="p">.</span><span class="n">name</span><span class="p">,</span> <span class="n">user_account</span><span class="p">.</span><span class="n">email</span>
<span class="k">FROM</span> <span class="n">user_account</span>
<span class="k">WHERE</span> <span class="n">user_account</span><span class="p">.</span><span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;fred&#39;</span> <span class="k">AND</span> <span class="n">user_account</span><span class="p">.</span><span class="n">status</span> <span class="o">=</span> <span class="s1">&#39;E&#39;</span></pre></div>
</div>
<p class="last">Above, the phrase <tt class="docutils literal"><span class="pre">WHERE</span> <span class="pre">user_account.name</span> <span class="pre">=</span> <span class="pre">'fred'</span> <span class="pre">AND</span> <span class="pre">user_account.status</span> <span class="pre">=</span> <span class="pre">'E'</span></tt>
comprises the WHERE clause of the <tt class="docutils literal"><span class="pre">SELECT</span></tt>.</p>
</dd>
</dl>
</div>

    </div>

</div>

<div id="docs-bottom-navigation" class="docs-navigation-links">

    <div id="docs-copyright">
        &copy; <a href="copyright.html">Copyright</a> 2007-2014, the SQLAlchemy authors and contributors.
        Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2b1.
    </div>
</div>

</div>

        
    </body>
</html>