| | | |
Offset 215, 23 lines modified | Offset 215, 23 lines modified |
215 | </div> | 215 | </div> |
216 | <div·class="section"·id="module-examples.association"> | 216 | <div·class="section"·id="module-examples.association"> |
217 | <span·id="associations"></span><span·id="examples-associations"></span><h3>Associations<a·class="headerlink"·href="#module-examples.association"·title="Permalink·to·this·headline">¶</a></h3> | 217 | <span·id="associations"></span><span·id="examples-associations"></span><h3>Associations<a·class="headerlink"·href="#module-examples.association"·title="Permalink·to·this·headline">¶</a></h3> |
218 | <p>Examples·illustrating·the·usage·of·the·“association·object”·pattern, | 218 | <p>Examples·illustrating·the·usage·of·the·“association·object”·pattern, |
219 | where·an·intermediary·class·mediates·the·relationship·between·two | 219 | where·an·intermediary·class·mediates·the·relationship·between·two |
220 | classes·that·are·associated·in·a·many-to-many·pattern.</p> | 220 | classes·that·are·associated·in·a·many-to-many·pattern.</p> |
221 | <p>Listing·of·files:<ul·class="simple"> | 221 | <p>Listing·of·files:<ul·class="simple"> |
| 222 | <li><p><p><a·class="reference·external"·href="../_modules/examples/association/basic_association.html">basic_association.py</a>·-·Illustrate·a·many-to-many·relationship·between·an |
| 223 | “Order”·and·a·collection·of·“Item”·objects,·associating·a·purchase·price |
| 224 | with·each·via·an·association·object·called·“OrderItem”</p> |
| 225 | </p></li> |
222 | <li><p><p><a·class="reference·external"·href="../_modules/examples/association/dict_of_sets_with_default.html">dict_of_sets_with_default.py</a>·-·An·advanced·association·proxy·example·which | 226 | <li><p><p><a·class="reference·external"·href="../_modules/examples/association/dict_of_sets_with_default.html">dict_of_sets_with_default.py</a>·-·An·advanced·association·proxy·example·which |
223 | illustrates·nesting·of·association·proxies·to·produce·multi-level·Python | 227 | illustrates·nesting·of·association·proxies·to·produce·multi-level·Python |
224 | collections,·in·this·case·a·dictionary·with·string·keys·and·sets·of·integers | 228 | collections,·in·this·case·a·dictionary·with·string·keys·and·sets·of·integers |
225 | as·values,·which·conceal·the·underlying·mapped·classes.</p> | 229 | as·values,·which·conceal·the·underlying·mapped·classes.</p> |
226 | </p></li> | 230 | </p></li> |
227 | <li><p><p><a·class="reference·external"·href="../_modules/examples/association/basic_association.html">basic_association.py</a>·-·Illustrate·a·many-to-many·relationship·between·an | |
228 | “Order”·and·a·collection·of·“Item”·objects,·associating·a·purchase·price | |
229 | with·each·via·an·association·object·called·“OrderItem”</p> | |
230 | </p></li> | |
231 | <li><p><p><a·class="reference·external"·href="../_modules/examples/association/proxied_association.html">proxied_association.py</a>·-·Same·example·as·basic_association,·adding·in | 231 | <li><p><p><a·class="reference·external"·href="../_modules/examples/association/proxied_association.html">proxied_association.py</a>·-·Same·example·as·basic_association,·adding·in |
232 | usage·of·<a·class="reference·internal"·href="extensions/associationproxy.html#module-sqlalchemy.ext.associationproxy"·title="sqlalchemy.ext.associationproxy"><code·class="xref·py·py-mod·docutils·literal·notranslate"><span·class="pre">sqlalchemy.ext.associationproxy</span></code></a>·to·make·explicit·references | 232 | usage·of·<a·class="reference·internal"·href="extensions/associationproxy.html#module-sqlalchemy.ext.associationproxy"·title="sqlalchemy.ext.associationproxy"><code·class="xref·py·py-mod·docutils·literal·notranslate"><span·class="pre">sqlalchemy.ext.associationproxy</span></code></a>·to·make·explicit·references |
233 | to·<code·class="docutils·literal·notranslate"><span·class="pre">OrderItem</span></code>·optional.</p> | 233 | to·<code·class="docutils·literal·notranslate"><span·class="pre">OrderItem</span></code>·optional.</p> |
234 | </p></li> | 234 | </p></li> |
235 | </ul> | 235 | </ul> |
236 | </p> | 236 | </p> |
237 | </div> | 237 | </div> |
Offset 279, 29 lines modified | Offset 279, 29 lines modified |
279 | <li><p><p><a·class="reference·external"·href="../_modules/examples/generic_associations/discriminator_on_association.html">discriminator_on_association.py</a>·-·Illustrates·a·mixin·which·provides·a·generic·association | 279 | <li><p><p><a·class="reference·external"·href="../_modules/examples/generic_associations/discriminator_on_association.html">discriminator_on_association.py</a>·-·Illustrates·a·mixin·which·provides·a·generic·association |
280 | using·a·single·target·table·and·a·single·association·table, | 280 | using·a·single·target·table·and·a·single·association·table, |
281 | referred·to·by·all·parent·tables.··The·association·table | 281 | referred·to·by·all·parent·tables.··The·association·table |
282 | contains·a·“discriminator”·column·which·determines·what·type·of | 282 | contains·a·“discriminator”·column·which·determines·what·type·of |
283 | parent·object·associates·to·each·particular·row·in·the·association | 283 | parent·object·associates·to·each·particular·row·in·the·association |
284 | table.</p> | 284 | table.</p> |
285 | </p></li> | 285 | </p></li> |
286 | <li><p><p><a·class="reference·external"·href="../_modules/examples/generic_associations/table_per_association.html">table_per_association.py</a>·-·Illustrates·a·mixin·which·provides·a·generic·association | 286 | <li><p><p><a·class="reference·external"·href="../_modules/examples/generic_associations/table_per_related.html">table_per_related.py</a>·-·Illustrates·a·generic·association·which·persists·association |
| 287 | objects·within·individual·tables,·each·one·generated·to·persist |
| 288 | those·objects·on·behalf·of·a·particular·parent·class.</p> |
287 | via·a·individually·generated·association·tables·for·each·parent·class. | |
288 | The·associated·objects·themselves·are·persisted·in·a·single·table | |
289 | shared·among·all·parents.</p> | |
290 | </p></li> | 289 | </p></li> |
291 | <li><p><p><a·class="reference·external"·href="../_modules/examples/generic_associations/generic_fk.html">generic_fk.py</a>·-·Illustrates·a·so-called·“generic·foreign·key”,·in·a·similar·fashion | 290 | <li><p><p><a·class="reference·external"·href="../_modules/examples/generic_associations/generic_fk.html">generic_fk.py</a>·-·Illustrates·a·so-called·“generic·foreign·key”,·in·a·similar·fashion |
292 | to·that·of·popular·frameworks·such·as·Django,·ROR,·etc.··This | 291 | to·that·of·popular·frameworks·such·as·Django,·ROR,·etc.··This |
293 | approach·bypasses·standard·referential·integrity | 292 | approach·bypasses·standard·referential·integrity |
294 | practices,·in·that·the·“foreign·key”·column·is·not·actually | 293 | practices,·in·that·the·“foreign·key”·column·is·not·actually |
295 | constrained·to·refer·to·any·particular·table;·instead, | 294 | constrained·to·refer·to·any·particular·table;·instead, |
296 | in-application·logic·is·used·to·determine·which·table·is·referenced.</p> | 295 | in-application·logic·is·used·to·determine·which·table·is·referenced.</p> |
297 | </p></li> | 296 | </p></li> |
298 | <li><p><p><a·class="reference·external"·href="../_modules/examples/generic_associations/table_per_related.html">table_per_related.py</a>·-·Illustrates·a·generic·association·which·persists·association | |
299 | objects·within·individual·tables,·each·one·generated·to·persist | |
300 | those·objects·on·behalf·of·a·particular·parent·class.</p> | 297 | <li><p><p><a·class="reference·external"·href="../_modules/examples/generic_associations/table_per_association.html">table_per_association.py</a>·-·Illustrates·a·mixin·which·provides·a·generic·association |
| 298 | via·a·individually·generated·association·tables·for·each·parent·class. |
| 299 | The·associated·objects·themselves·are·persisted·in·a·single·table |
| 300 | shared·among·all·parents.</p> |
301 | </p></li> | 301 | </p></li> |
302 | </ul> | 302 | </ul> |
303 | </p> | 303 | </p> |
304 | </div> | 304 | </div> |
305 | <div·class="section"·id="module-examples.large_collection"> | 305 | <div·class="section"·id="module-examples.large_collection"> |
306 | <span·id="large-collections"></span><h3>Large·Collections<a·class="headerlink"·href="#module-examples.large_collection"·title="Permalink·to·this·headline">¶</a></h3> | 306 | <span·id="large-collections"></span><h3>Large·Collections<a·class="headerlink"·href="#module-examples.large_collection"·title="Permalink·to·this·headline">¶</a></h3> |
307 | <p>Large·collection·example.</p> | 307 | <p>Large·collection·example.</p> |
Offset 389, 24 lines modified | Offset 389, 24 lines modified |
389 | <div·class="admonition·seealso"> | 389 | <div·class="admonition·seealso"> |
390 | <p·class="admonition-title">See·also</p> | 390 | <p·class="admonition-title">See·also</p> |
391 | <p><a·class="reference·internal"·href="../faq/performance.html#faq-how-to-profile"><span·class="std·std-ref">How·can·I·profile·a·SQLAlchemy·powered·application?</span></a></p> | 391 | <p><a·class="reference·internal"·href="../faq/performance.html#faq-how-to-profile"><span·class="std·std-ref">How·can·I·profile·a·SQLAlchemy·powered·application?</span></a></p> |
392 | </div> | 392 | </div> |
393 | <div·class="section"·id="file-listing"> | 393 | <div·class="section"·id="file-listing"> |
394 | <h4>File·Listing<a·class="headerlink"·href="#file-listing"·title="Permalink·to·this·headline">¶</a></h4> | 394 | <h4>File·Listing<a·class="headerlink"·href="#file-listing"·title="Permalink·to·this·headline">¶</a></h4> |
395 | <p>Listing·of·files:<ul·class="simple"> | 395 | <p>Listing·of·files:<ul·class="simple"> |
396 | <li><p><p><a·class="reference·external"·href="../_modules/examples/performance/__main__.html">__main__.py</a>·-·Allows·the·examples/performance·package·to·be·run·as·a·script.</p> | |
397 | </p></li> | |
398 | <li><p><p><a·class="reference·external"·href="../_modules/examples/performance/short_selects.html">short_selects.py</a>·-·This·series·of·tests·illustrates·different·ways·to·SELECT·a·single | |
399 | record·by·primary·key</p> | |
400 | </p></li> | |
401 | <li><p><p><a·class="reference·external"·href="../_modules/examples/performance/single_inserts.html">single_inserts.py</a>·-·In·this·series·of·tests,·we’re·looking·at·a·method·that·inserts·a·row | 396 | <li><p><p><a·class="reference·external"·href="../_modules/examples/performance/single_inserts.html">single_inserts.py</a>·-·In·this·series·of·tests,·we’re·looking·at·a·method·that·inserts·a·row |
402 | within·a·distinct·transaction,·and·afterwards·returns·to·essentially·a | 397 | within·a·distinct·transaction,·and·afterwards·returns·to·essentially·a |
403 | “closed”·state.···This·would·be·analogous·to·an·API·call·that·starts·up | 398 | “closed”·state.···This·would·be·analogous·to·an·API·call·that·starts·up |
404 | a·database·connection,·inserts·the·row,·commits·and·closes.</p> | 399 | a·database·connection,·inserts·the·row,·commits·and·closes.</p> |
405 | </p></li> | 400 | </p></li> |
| 401 | <li><p><p><a·class="reference·external"·href="../_modules/examples/performance/short_selects.html">short_selects.py</a>·-·This·series·of·tests·illustrates·different·ways·to·SELECT·a·single |
| 402 | record·by·primary·key</p> |
| 403 | </p></li> |
| 404 | <li><p><p><a·class="reference·external"·href="../_modules/examples/performance/__main__.html">__main__.py</a>·-·Allows·the·examples/performance·package·to·be·run·as·a·script.</p> |
| 405 | </p></li> |
406 | <li><p><p><a·class="reference·external"·href="../_modules/examples/performance/bulk_inserts.html">bulk_inserts.py</a>·-·This·series·of·tests·illustrates·different·ways·to·INSERT·a·large·number | 406 | <li><p><p><a·class="reference·external"·href="../_modules/examples/performance/bulk_inserts.html">bulk_inserts.py</a>·-·This·series·of·tests·illustrates·different·ways·to·INSERT·a·large·number |
407 | of·rows·in·bulk.</p> | 407 | of·rows·in·bulk.</p> |
408 | </p></li> | 408 | </p></li> |
409 | <li><p><p><a·class="reference·external"·href="../_modules/examples/performance/large_resultsets.html">large_resultsets.py</a>·-·In·this·series·of·tests,·we·are·looking·at·time·to·load·a·large·number | 409 | <li><p><p><a·class="reference·external"·href="../_modules/examples/performance/large_resultsets.html">large_resultsets.py</a>·-·In·this·series·of·tests,·we·are·looking·at·time·to·load·a·large·number |
410 | of·very·small·and·simple·rows.</p> | 410 | of·very·small·and·simple·rows.</p> |
411 | </p></li> | 411 | </p></li> |
412 | <li><p><p><a·class="reference·external"·href="../_modules/examples/performance/bulk_updates.html">bulk_updates.py</a>·-·This·series·of·tests·illustrates·different·ways·to·UPDATE·a·large·number | 412 | <li><p><p><a·class="reference·external"·href="../_modules/examples/performance/bulk_updates.html">bulk_updates.py</a>·-·This·series·of·tests·illustrates·different·ways·to·UPDATE·a·large·number |
Offset 557, 22 lines modified | Offset 557, 22 lines modified |
557 | </div> | 557 | </div> |
558 | <div·class="section"·id="module-examples.join_conditions"> | 558 | <div·class="section"·id="module-examples.join_conditions"> |
559 | <span·id="relationship-join-conditions"></span><span·id="examples-relationships"></span><h3>Relationship·Join·Conditions<a·class="headerlink"·href="#module-examples.join_conditions"·title="Permalink·to·this·headline">¶</a></h3> | 559 | <span·id="relationship-join-conditions"></span><span·id="examples-relationships"></span><h3>Relationship·Join·Conditions<a·class="headerlink"·href="#module-examples.join_conditions"·title="Permalink·to·this·headline">¶</a></h3> |
560 | <p>Examples·of·various·<a·class="reference·internal"·href="relationship_api.html#sqlalchemy.orm.relationship"·title="sqlalchemy.orm.relationship"><code·class="xref·py·py-func·docutils·literal·notranslate"><span·class="pre">relationship()</span></code></a>·configurations, | 560 | <p>Examples·of·various·<a·class="reference·internal"·href="relationship_api.html#sqlalchemy.orm.relationship"·title="sqlalchemy.orm.relationship"><code·class="xref·py·py-func·docutils·literal·notranslate"><span·class="pre">relationship()</span></code></a>·configurations, |
561 | which·make·use·of·the·<code·class="docutils·literal·notranslate"><span·class="pre">primaryjoin</span></code>·argument·to·compose·special·types | 561 | which·make·use·of·the·<code·class="docutils·literal·notranslate"><span·class="pre">primaryjoin</span></code>·argument·to·compose·special·types |
562 | of·join·conditions.</p> | 562 | of·join·conditions.</p> |
563 | <p>Listing·of·files:<ul·class="simple"> | 563 | <p>Listing·of·files:<ul·class="simple"> |
564 | <li><p><p><a·class="reference·external"·href="../_modules/examples/join_conditions/cast.html">cast.py</a>·-·Illustrate·a·<a·class="reference·internal"·href="relationship_api.html#sqlalchemy.orm.relationship"·title="sqlalchemy.orm.relationship"><code·class="xref·py·py-func·docutils·literal·notranslate"><span·class="pre">relationship()</span></code></a>·that·joins·two·columns·where·those | |
565 | columns·are·not·of·the·same·type,·and·a·CAST·must·be·used·on·the·SQL | |
566 | side·in·order·to·match·them.</p> | |
567 | </p></li> | |
568 | <li><p><p><a·class="reference·external"·href="../_modules/examples/join_conditions/threeway.html">threeway.py</a>·-·Illustrate·a·“three·way·join”·-·where·a·primary·table·joins·to·a·remote | 564 | <li><p><p><a·class="reference·external"·href="../_modules/examples/join_conditions/threeway.html">threeway.py</a>·-·Illustrate·a·“three·way·join”·-·where·a·primary·table·joins·to·a·remote |
569 | table·via·an·association·table,·but·then·the·primary·table·also·needs | 565 | table·via·an·association·table,·but·then·the·primary·table·also·needs |
570 | to·refer·to·some·columns·in·the·remote·table·directly.</p> | 566 | to·refer·to·some·columns·in·the·remote·table·directly.</p> |
571 | </p></li> | 567 | </p></li> |
| 568 | <li><p><p><a·class="reference·external"·href="../_modules/examples/join_conditions/cast.html">cast.py</a>·-·Illustrate·a·<a·class="reference·internal"·href="relationship_api.html#sqlalchemy.orm.relationship"·title="sqlalchemy.orm.relationship"><code·class="xref·py·py-func·docutils·literal·notranslate"><span·class="pre">relationship()</span></code></a>·that·joins·two·columns·where·those |
| 569 | columns·are·not·of·the·same·type,·and·a·CAST·must·be·used·on·the·SQL |
| 570 | side·in·order·to·match·them.</p> |
| 571 | </p></li> |
572 | </ul> | 572 | </ul> |
573 | </p> | 573 | </p> |
574 | </div> | 574 | </div> |
575 | <div·class="section"·id="module-examples.space_invaders"> | 575 | <div·class="section"·id="module-examples.space_invaders"> |
576 | <span·id="space-invaders"></span><span·id="examples-spaceinvaders"></span><h3>Space·Invaders<a·class="headerlink"·href="#module-examples.space_invaders"·title="Permalink·to·this·headline">¶</a></h3> | 576 | <span·id="space-invaders"></span><span·id="examples-spaceinvaders"></span><h3>Space·Invaders<a·class="headerlink"·href="#module-examples.space_invaders"·title="Permalink·to·this·headline">¶</a></h3> |
577 | <p>A·Space·Invaders·game·using·SQLite·as·the·state·machine.</p> | 577 | <p>A·Space·Invaders·game·using·SQLite·as·the·state·machine.</p> |
578 | <p>Originally·developed·in·2012.··Adapted·to·work·in·Python·3.</p> | 578 | <p>Originally·developed·in·2012.··Adapted·to·work·in·Python·3.</p> |
Offset 719, 31 lines modified | Offset 719, 31 lines modified |
719 | <p>Several·examples·that·illustrate·the·technique·of·intercepting·changes | 719 | <p>Several·examples·that·illustrate·the·technique·of·intercepting·changes |
720 | that·would·be·first·interpreted·as·an·UPDATE·on·a·row,·and·instead·turning | 720 | that·would·be·first·interpreted·as·an·UPDATE·on·a·row,·and·instead·turning |
721 | it·into·an·INSERT·of·a·new·row,·leaving·the·previous·row·intact·as | 721 | it·into·an·INSERT·of·a·new·row,·leaving·the·previous·row·intact·as |
722 | a·historical·version.</p> | 722 | a·historical·version.</p> |
723 | <p>Compare·to·the·<a·class="reference·internal"·href="#examples-versioned-history"><span·class="std·std-ref">Versioning·with·a·History·Table</span></a>·example·which·writes·a | 723 | <p>Compare·to·the·<a·class="reference·internal"·href="#examples-versioned-history"><span·class="std·std-ref">Versioning·with·a·History·Table</span></a>·example·which·writes·a |
724 | history·row·to·a·separate·history·table.</p> | 724 | history·row·to·a·separate·history·table.</p> |
725 | <p>Listing·of·files:<ul·class="simple"> | 725 | <p>Listing·of·files:<ul·class="simple"> |
Max diff block lines reached; 7747/19405 bytes (39.92%) of diff not shown.
|