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/elements.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/elements.py')
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index af5eab257..6ce505412 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -215,6 +215,7 @@ class ClauseElement( _is_select_statement = False _is_bind_parameter = False _is_clause_list = False + _is_lambda_element = False _order_by_label_element = None @@ -1337,9 +1338,6 @@ class BindParameter(roles.InElementRole, ColumnElement): :ref:`change_4808`. - - - """ if required is NO_ARG: @@ -1406,15 +1404,15 @@ class BindParameter(roles.InElementRole, ColumnElement): the context of an expanding IN against a tuple. """ - cloned = self._clone() + cloned = self._clone(maintain_key=True) cloned._expanding_in_types = types return cloned - def _with_value(self, value): + def _with_value(self, value, maintain_key=False): """Return a copy of this :class:`.BindParameter` with the given value set. """ - cloned = self._clone() + cloned = self._clone(maintain_key=maintain_key) cloned.value = value cloned.callable = None cloned.required = False @@ -1442,9 +1440,9 @@ class BindParameter(roles.InElementRole, ColumnElement): c.type = type_ return c - def _clone(self): + def _clone(self, maintain_key=False): c = ClauseElement._clone(self) - if self.unique: + if not maintain_key and self.unique: c.key = _anonymous_label( "%%(%d %s)s" % (id(c), c._orig_key or "param") ) |