diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-12-16 17:06:43 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-07-03 23:39:51 -0400 |
commit | 3dc9a4a2392d033f9d1bd79dd6b6ecea6281a61c (patch) | |
tree | 1041bccb37422f526dccb5b1e57ffad1c702549b /lib/sqlalchemy/sql/base.py | |
parent | 5060043e8e95ab0aab5f63ed288c1426c46da66e (diff) | |
download | sqlalchemy-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/sql/base.py')
-rw-r--r-- | lib/sqlalchemy/sql/base.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py index 9dcd7dca9..6cdab8eac 100644 --- a/lib/sqlalchemy/sql/base.py +++ b/lib/sqlalchemy/sql/base.py @@ -14,6 +14,7 @@ import itertools import operator import re +from . import roles from .traversals import HasCacheKey # noqa from .traversals import MemoizedHasCacheKey # noqa from .visitors import ClauseVisitor @@ -447,13 +448,17 @@ class CompileState(object): "compile_state_plugin", "default" ) klass = cls.plugins.get( - (plugin_name, statement.__visit_name__), None + (plugin_name, statement._effective_plugin_target), None ) if klass is None: - klass = cls.plugins[("default", statement.__visit_name__)] + klass = cls.plugins[ + ("default", statement._effective_plugin_target) + ] else: - klass = cls.plugins[("default", statement.__visit_name__)] + klass = cls.plugins[ + ("default", statement._effective_plugin_target) + ] if klass is cls: return cls(statement, compiler, **kw) @@ -469,14 +474,18 @@ class CompileState(object): "compile_state_plugin", "default" ) try: - return cls.plugins[(plugin_name, statement.__visit_name__)] + return cls.plugins[ + (plugin_name, statement._effective_plugin_target) + ] except KeyError: return None @classmethod def _get_plugin_class_for_plugin(cls, statement, plugin_name): try: - return cls.plugins[(plugin_name, statement.__visit_name__)] + return cls.plugins[ + (plugin_name, statement._effective_plugin_target) + ] except KeyError: return None @@ -637,6 +646,10 @@ class Executable(Generative): ("_propagate_attrs", ExtendedInternalTraversal.dp_propagate_attrs), ] + @property + def _effective_plugin_target(self): + return self.__visit_name__ + @_generative def options(self, *options): """Apply options to this statement. @@ -667,7 +680,9 @@ class Executable(Generative): to the usage of ORM queries """ - self._with_options += options + self._with_options += tuple( + coercions.expect(roles.HasCacheKeyRole, opt) for opt in options + ) @_generative def _add_context_option(self, callable_, cache_args): |