diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-09-25 22:31:16 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-10-31 13:44:53 -0400 |
commit | 654b462d668a2ced4e87077b9babb2590acbf983 (patch) | |
tree | 8b6023480423e990c9bbca7c280cb1cb58e012fc /doc/build/orm/tutorial.rst | |
parent | 841eb216644202567ebddfc0badc51a3a35e98c3 (diff) | |
download | sqlalchemy-review/mike_bayer/tutorial20.tar.gz |
tutorial 2.0 WIPreview/mike_bayer/tutorial20
Add SelectBase.exists() method as it seems strange this is
not available already. The Exists construct itself does
not provide full SELECT-building capabilities so it makes
sense this should be used more like a scalar_subquery.
Make sure stream_results is getting set up when yield_per
is used, for 2.0 style statements as well. this was
hardcoded inside of Query.yield_per() and is now moved
to take place within QueryContext.
Change-Id: Icafcd4fd9b708772343d56edf40995c9e8f835d6
Diffstat (limited to 'doc/build/orm/tutorial.rst')
-rw-r--r-- | doc/build/orm/tutorial.rst | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/doc/build/orm/tutorial.rst b/doc/build/orm/tutorial.rst index 2025268c9..ae62d256a 100644 --- a/doc/build/orm/tutorial.rst +++ b/doc/build/orm/tutorial.rst @@ -4,6 +4,35 @@ Object Relational Tutorial (1.x API) ==================================== +.. admonition:: About this document + + This tutorial covers the well known SQLAlchemy ORM API + that has been in use for many years. As of SQLAlchemy 1.4, there are two + distinct styles of ORM use known as :term:`1.x style` and :term:`2.0 + style`, the latter of which makes a wide range of changes most prominently + around how ORM queries are constructed and executed. + + The plan is that in SQLAlchemy 2.0, the 1.x style of ORM use will be + considered legacy and no longer featured in documentation and many + aspects of it will be removed. However, the most central element of + :term:`1.x style` ORM use, the :class:`_orm.Query` object, will still + remain available for long-term legacy use cases. + + This tutorial is applicable to users who want to learn how SQLAlchemy has + been used for many years, particularly those users working with existing + applications or related learning material that is in 1.x style. + + For an introduction to SQLAlchemy from the new 1.4/2.0 perspective, + see :ref:`unified_tutorial`. + + .. seealso:: + + :ref:`change_5159` + + :ref:`migration_20_toplevel` + + :ref:`unified_tutorial` + The SQLAlchemy Object Relational Mapper presents a method of associating user-defined Python classes with database tables, and instances of those classes (objects) with rows in their corresponding tables. It includes a @@ -168,7 +197,7 @@ this information for a specific table is called the :class:`_schema.Table` objec one for us. We can see this object by inspecting the ``__table__`` attribute:: >>> User.__table__ # doctest: +NORMALIZE_WHITESPACE - Table('users', MetaData(bind=None), + Table('users', MetaData(), Column('id', Integer(), table=<users>, primary_key=True, nullable=False), Column('name', String(), table=<users>), Column('fullname', String(), table=<users>), @@ -217,8 +246,6 @@ the actual ``CREATE TABLE`` statement: nickname VARCHAR, PRIMARY KEY (id) ) - <BLANKLINE> - <BLANKLINE> [...] () COMMIT @@ -1223,8 +1250,6 @@ already been created: PRIMARY KEY (id), FOREIGN KEY(user_id) REFERENCES users (id) ) - <BLANKLINE> - <BLANKLINE> [...] () COMMIT @@ -2089,10 +2114,7 @@ Create new tables: PRIMARY KEY (id), UNIQUE (keyword) ) - <BLANKLINE> - <BLANKLINE> [...] () - <BLANKLINE> CREATE TABLE posts ( id INTEGER NOT NULL, user_id INTEGER, @@ -2101,10 +2123,7 @@ Create new tables: PRIMARY KEY (id), FOREIGN KEY(user_id) REFERENCES users (id) ) - <BLANKLINE> - <BLANKLINE> [...] () - <BLANKLINE> CREATE TABLE post_keywords ( post_id INTEGER NOT NULL, keyword_id INTEGER NOT NULL, @@ -2112,8 +2131,6 @@ Create new tables: FOREIGN KEY(post_id) REFERENCES posts (id), FOREIGN KEY(keyword_id) REFERENCES keywords (id) ) - <BLANKLINE> - <BLANKLINE> [...] () COMMIT |