summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-12-16 17:06:43 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-07-03 23:39:51 -0400
commit3dc9a4a2392d033f9d1bd79dd6b6ecea6281a61c (patch)
tree1041bccb37422f526dccb5b1e57ffad1c702549b /lib/sqlalchemy/engine
parent5060043e8e95ab0aab5f63ed288c1426c46da66e (diff)
downloadsqlalchemy-3dc9a4a2392d033f9d1bd79dd6b6ecea6281a61c.tar.gz
introduce deferred lambdas
The coercions system allows us to add in lambdas as arguments to Core and ORM elements without changing them at all. By allowing the lambda to produce a deterministic cache key where we can also cheat and yank out literal parameters means we can move towards having 90% of "baked" functionality in a clearer way right in Core / ORM. As a second step, we can have whole statements inside the lambda, and can then add generation with __add__(), so then we have 100% of "baked" functionality with full support of ad-hoc literal values. Adds some more short_selects tests for the moment for comparison. Other tweaks inside cache key generation as we're trying to approach a certain level of performance such that we can remove the use of "baked" from the loader strategies. As we have not yet closed #4639, however the caching feature has been fully integrated as of b0cfa7379cf8513a821a3dbe3028c4965d9f85bd, we will also add complete caching documentation here and close that issue as well. Closes: #4639 Fixes: #5380 Change-Id: If91f61527236fd4d7ae3cad1f24c38be921c90ba
Diffstat (limited to 'lib/sqlalchemy/engine')
-rw-r--r--lib/sqlalchemy/engine/base.py1
-rw-r--r--lib/sqlalchemy/engine/create.py3
-rw-r--r--lib/sqlalchemy/engine/default.py2
-rw-r--r--lib/sqlalchemy/engine/result.py7
4 files changed, 8 insertions, 5 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index ed4133dbb..9ac61fe12 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -1046,6 +1046,7 @@ class Connection(Connectable):
distilled_parameters,
_EMPTY_EXECUTION_OPTS,
)
+
try:
meth = object_._execute_on_connection
except AttributeError as err:
diff --git a/lib/sqlalchemy/engine/create.py b/lib/sqlalchemy/engine/create.py
index cc138412b..c199c21e0 100644
--- a/lib/sqlalchemy/engine/create.py
+++ b/lib/sqlalchemy/engine/create.py
@@ -459,8 +459,7 @@ def create_engine(url, **kwargs):
.. seealso::
- ``engine_caching`` - TODO: this will be an upcoming section describing
- the SQL caching system.
+ :ref:`sql_caching`
.. versionadded:: 1.4
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py
index 51bff223c..f1fc505ac 100644
--- a/lib/sqlalchemy/engine/default.py
+++ b/lib/sqlalchemy/engine/default.py
@@ -1031,7 +1031,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext):
if self.compiled.cache_key is None:
return "no key %.5fs" % (now - self.compiled._gen_time,)
elif self.cache_hit:
- return "cached for %.4gs" % (now - self.compiled._gen_time,)
+ return "cached since %.4gs ago" % (now - self.compiled._gen_time,)
else:
return "generated in %.5fs" % (now - self.compiled._gen_time,)
diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py
index f75cba57d..7df17cf22 100644
--- a/lib/sqlalchemy/engine/result.py
+++ b/lib/sqlalchemy/engine/result.py
@@ -963,7 +963,10 @@ class Result(InPlaceGenerative):
else:
return None
- make_row = self._row_getter
+ if scalar and self._source_supports_scalars:
+ make_row = None
+ else:
+ make_row = self._row_getter
row = make_row(row) if make_row else row
@@ -1016,7 +1019,7 @@ class Result(InPlaceGenerative):
if post_creational_filter:
row = post_creational_filter(row)
- if scalar and row:
+ if scalar and make_row:
return row[0]
else:
return row