diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-04-17 13:37:39 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-04-29 12:45:45 -0400 |
commit | 08da8115a6eb7eb125fa5f92f662d915b076fded (patch) | |
tree | a4eaee5acdd2ffd7f254b1426b97e176c6dda803 /lib/sqlalchemy/sql/functions.py | |
parent | 099522075088a3e1a333a2285c10a8a33b203c19 (diff) | |
download | sqlalchemy-08da8115a6eb7eb125fa5f92f662d915b076fded.tar.gz |
Add _cache_key implementation.
This leverages the work started in #4336 to allow ClauseElement
structures to be cachable based on structure, not just identity.
Change-Id: Ia99ddeb5353496dd7d61243245685f02b98d8100
Diffstat (limited to 'lib/sqlalchemy/sql/functions.py')
-rw-r--r-- | lib/sqlalchemy/sql/functions.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index f48a20ec7..0e92d5e50 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -256,6 +256,9 @@ class FunctionElement(Executable, ColumnElement, FromClause): def get_children(self, **kwargs): return (self.clause_expr,) + def _cache_key(self, **kw): + return (FunctionElement, self.clause_expr._cache_key(**kw)) + def _copy_internals(self, clone=_clone, **kw): self.clause_expr = clone(self.clause_expr, **kw) self._reset_exported() @@ -406,6 +409,14 @@ class FunctionAsBinary(BinaryExpression): def get_children(self, **kw): yield self.sql_function + def _cache_key(self, **kw): + return ( + FunctionAsBinary, + self.sql_function._cache_key(**kw), + self.left_index, + self.right_index, + ) + class _FunctionGenerator(object): """Generate :class:`.Function` objects based on getattr calls.""" @@ -566,6 +577,13 @@ class Function(FunctionElement): unique=True, ) + def _cache_key(self, **kw): + return ( + (Function,) + tuple(self.packagenames) + if self.packagenames + else () + (self.name, self.clause_expr._cache_key(**kw)) + ) + class _GenericMeta(VisitableType): def __init__(cls, clsname, bases, clsdict): @@ -684,6 +702,9 @@ class next_value(GenericFunction): self._bind = kw.get("bind", None) self.sequence = seq + def _cache_key(self, **kw): + return (next_value, self.sequence.name) + def compare(self, other, **kw): return ( isinstance(other, next_value) |