summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorEric Atkin <eatkin@certusllc.us>2018-02-28 16:00:38 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2018-03-05 21:42:49 -0500
commit611f7f4e94026926c8c85717e1a2d481bd2c5657 (patch)
tree79dae4d5f30eb59e2395ab4f4dce8335ddca9f81 /lib/sqlalchemy
parent0e146706058c8e4920c675644623601f2c4930d7 (diff)
downloadsqlalchemy-611f7f4e94026926c8c85717e1a2d481bd2c5657.tar.gz
Add Query.enable_single_entity()
Added new feature :meth:`.Query.only_return_tuples`. Causes the :class:`.Query` object to return keyed tuple objects unconditionally even if the query is against a single entity. Pull request courtesy Eric Atkin. Change-Id: Ib0b7f5f78431aa68082e5b200ed577daa4222336 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/425
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/loading.py3
-rw-r--r--lib/sqlalchemy/orm/query.py11
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py
index 2628093e0..3599aa3e7 100644
--- a/lib/sqlalchemy/orm/loading.py
+++ b/lib/sqlalchemy/orm/loading.py
@@ -37,7 +37,8 @@ def instances(query, cursor, context):
filtered = query._has_mapper_entities
- single_entity = len(query._entities) == 1 and \
+ single_entity = not query._only_return_tuples and \
+ len(query._entities) == 1 and \
query._entities[0].supports_single_entity
if filtered:
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 1e7f8a266..043be5539 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -70,6 +70,7 @@ class Query(object):
"""
+ _only_return_tuples = False
_enable_eagerloads = True
_enable_assertions = True
_with_labels = False
@@ -604,6 +605,16 @@ class Query(object):
return self.enable_eagerloads(False).with_labels().statement
@_generative()
+ def only_return_tuples(self, value):
+ """When set to True, the query results will always be a tuple,
+ specifically for single element queries. The default is False.
+
+ . .. versionadded:: 1.2.5
+
+ """
+ self._only_return_tuples = value
+
+ @_generative()
def enable_eagerloads(self, value):
"""Control whether or not eager joins and subqueries are
rendered.