SQLAlchemy 2.0 Documentation
SQLAlchemy ORM
- ORM Quick Start
- ORM Mapped Class Configuration
- Relationship Configuration
- ORM Querying Guide¶
- Using the Session
- Events and Internals
- ORM Extensions
- ORM Examples
Project Versions
- Previous: Relationships API
- Next: Writing SELECT statements for ORM Mapped Classes
- Up: Home
- On this page:
ORM Querying Guide¶
This section provides an overview of emitting queries with the SQLAlchemy ORM using 2.0 style usage.
Readers of this section should be familiar with the SQLAlchemy overview at SQLAlchemy Unified Tutorial, and in particular most of the content here expands upon the content at Using SELECT Statements.
For users of SQLAlchemy 1.x
In the SQLAlchemy 2.x series, SQL SELECT statements for the ORM are
constructed using the same select()
construct as is used in
Core, which is then invoked in terms of a Session
using the
Session.execute()
method (as are the update()
and
delete()
constructs now used for the
ORM-Enabled INSERT, UPDATE, and DELETE statements feature). However, the legacy
Query
object, which performs these same steps as more of an
“all-in-one” object, continues to remain available as a thin facade over
this new system, to support applications that were built on the 1.x series
without the need for wholesale replacement of all queries. For reference on
this object, see the section Legacy Query API.
- Writing SELECT statements for ORM Mapped Classes
- Selecting ORM Entities and Attributes
- Selecting ORM Entities
- Selecting Multiple ORM Entities Simultaneously
- Selecting Individual Attributes
- Grouping Selected Attributes with Bundles
- Selecting ORM Aliases
- Getting ORM Results from Textual Statements
- Selecting Entities from Subqueries
- Selecting Entities from UNIONs and other set operations
- Joins
- Simple Relationship Joins
- Chaining Multiple Joins
- Joins to a Target Entity
- Joins to a Target with an ON Clause
- Combining Relationship with Custom ON Criteria
- Using Relationship to join between aliased targets
- Joining to Subqueries
- Joining to Subqueries along Relationship paths
- Subqueries that Refer to Multiple Entities
- Setting the leftmost FROM clause in a join
- Relationship WHERE Operators
- Selecting ORM Entities and Attributes
- Writing SELECT statements for Inheritance Mappings
- ORM-Enabled INSERT, UPDATE, and DELETE statements
- Column Loading Options
- Relationship Loading Techniques
- Summary of Relationship Loading Styles
- Configuring Loader Strategies at Mapping Time
- Relationship Loading with Loader Options
- Lazy Loading
- Joined Eager Loading
- Select IN loading
- Subquery Eager Loading
- What Kind of Loading to Use ?
- Polymorphic Eager Loading
- Wildcard Loading Strategies
- Routing Explicit Joins/Statements into Eagerly Loaded Collections
- Relationship Loader API
- ORM API Features for Querying
- Legacy Query API
flambé! the dragon and The Alchemist image designs created and generously donated by Rotem Yaari.
Created using Sphinx 7.2.6. Documentation last generated: Sat 09 Nov 2024 12:10:24 PM EST