blob: 54ca44ac2a8ced171aa23971e5ed6cbbd40485bf (
plain)
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
|
.. highlight:: pycon+sql
.. |prev| replace:: :doc:`api`
.. |tutorial_title| replace:: ORM Querying Guide
.. topic:: |tutorial_title|
This page is part of the :doc:`index`.
Previous: |prev|
.. currentmodule:: sqlalchemy.orm
.. _query_api_toplevel:
================
Legacy Query API
================
.. admonition:: About the Legacy Query API
This page contains the Python generated documentation for the
:class:`_query.Query` construct, which for many years was the sole SQL
interface when working with the SQLAlchemy ORM. As of version 2.0, an all
new way of working is now the standard approach, where the same
:func:`_sql.select` construct that works for Core works just as well for the
ORM, providing a consistent interface for building queries.
For any application that is built on the SQLAlchemy ORM prior to the
2.0 API, the :class:`_query.Query` API will usually represents the vast
majority of database access code within an application, and as such the
majority of the :class:`_query.Query` API is
**not being removed from SQLAlchemy**. The :class:`_query.Query` object
behind the scenes now translates itself into a 2.0 style :func:`_sql.select`
object when the :class:`_query.Query` object is executed, so it now is
just a very thin adapter API.
For a guide to migrating an application based on :class:`_query.Query`
to 2.0 style, see :ref:`migration_20_query_usage`.
For an introduction to writing SQL for ORM objects in the 2.0 style,
start with the :ref:`unified_tutorial`. Additional reference for 2.0 style
querying is at :ref:`queryguide_toplevel`.
The Query Object
================
:class:`_query.Query` is produced in terms of a given :class:`~.Session`, using the :meth:`~.Session.query` method::
q = session.query(SomeMappedClass)
Following is the full interface for the :class:`_query.Query` object.
.. autoclass:: sqlalchemy.orm.Query
:members:
:inherited-members:
ORM-Specific Query Constructs
=============================
This section has moved to :ref:`queryguide_additional`.
|