summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-07-26 16:29:30 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-07-26 16:29:30 -0400
commit7d268d4bcb5e6205d05ace0ea2fd94895bc2efed (patch)
treed54f506599509c8a3f8dd8dfd5fe36e73871e74b
parent2997d3910d36989cb36ab698b7815ceb494ebd9f (diff)
downloadsqlalchemy-7d268d4bcb5e6205d05ace0ea2fd94895bc2efed.tar.gz
- remove "completely raw", whatever that is
-rw-r--r--doc/build/orm/tutorial.rst37
1 files changed, 16 insertions, 21 deletions
diff --git a/doc/build/orm/tutorial.rst b/doc/build/orm/tutorial.rst
index cd062cfbc..527481334 100644
--- a/doc/build/orm/tutorial.rst
+++ b/doc/build/orm/tutorial.rst
@@ -968,23 +968,8 @@ mapper (below illustrated using an asterisk):
('ed',)
{stop}[<User(name='ed', fullname='Ed Jones', password='f8s7ccs')>]
-You can use :meth:`~sqlalchemy.orm.query.Query.from_statement()` to go
-completely "raw", using string names to identify desired columns:
-
-.. sourcecode:: python+sql
-
- {sql}>>> session.query("id", "name", "thenumber12").\
- ... from_statement(text("SELECT id, name, 12 as "
- ... "thenumber12 FROM users where name=:name")).\
- ... params(name='ed').all()
- SELECT id, name, 12 as thenumber12 FROM users where name=?
- ('ed',)
- {stop}[(1, u'ed', 12)]
-
-The :func:`.text` construct also supports the :meth:`.TextClause.columns`
-method, which can be used to associate ORM-mapped columns explicitly.
-This is useful to make an explicit mapping of columns in the string
-statement to those that are mapped:
+Or alternatively, specify how the columns map to the :func:`.text` construct
+explicitly using the :meth:`.TextClause.columns` method:
.. sourcecode:: python+sql
@@ -995,12 +980,17 @@ statement to those that are mapped:
('ed',)
{stop}[<User(name='ed', fullname='Ed Jones', password='f8s7ccs')>]
+We can choose columns to return individually as well, as in any other case:
-.. versionchanged:: 1.0.0
- The :class:`.Query` construct emits warnings when string SQL
- fragments are coerced to :func:`.text`, and :func:`.text` should
- be used explicitly. See :ref:`migration_2992` for background.
+.. sourcecode:: python+sql
+ >>> stmt = text("SELECT name, id FROM users where name=:name")
+ >>> stmt = stmt.columns(User.name, User.id)
+ {sql}>>> session.query(User.id, User.name).\
+ ... from_statement(stmt).params(name='ed').all()
+ SELECT name, id FROM users where name=?
+ ('ed',)
+ {stop}[(1, u'ed')]
.. seealso::
@@ -1009,6 +999,11 @@ statement to those that are mapped:
:func:`.text` and related constructs is very similar to that of the
Core :func:`.select` object.
+.. versionchanged:: 1.0.0
+ The :class:`.Query` construct emits warnings when string SQL
+ fragments are coerced to :func:`.text`, and :func:`.text` should
+ be used explicitly. See :ref:`migration_2992` for background.
+
Counting
--------