diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-08-05 17:58:48 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-08-05 18:53:17 -0400 |
commit | 71a3ccbdef0d88e9231b7de9c51e4ed60b3b7181 (patch) | |
tree | 3251bd2b54584f832f7c1f31283ddfb675df3495 /lib/sqlalchemy/sql | |
parent | cc57ea495f6460dd56daa6de57e40047ed999369 (diff) | |
download | sqlalchemy-71a3ccbdef0d88e9231b7de9c51e4ed60b3b7181.tar.gz |
Convert lazy loader, selectinload, load_on_ident to lambda statements
Building on newly robust lambdas in
I29a513c98917b1d503abfdd61e6b6e8800851aa8,
convert key loading off of the "baked" system so that baked
is no longer used by the ORM.
Change-Id: I3abfb45dd6e50f84f29d39434caa0b550ce27864
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r-- | lib/sqlalchemy/sql/base.py | 40 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 12 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/dml.py | 8 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/lambdas.py | 2 |
4 files changed, 58 insertions, 4 deletions
diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py index 36a8151d3..dc2804691 100644 --- a/lib/sqlalchemy/sql/base.py +++ b/lib/sqlalchemy/sql/base.py @@ -16,6 +16,7 @@ import re from . import roles from .traversals import HasCacheKey # noqa +from .traversals import HasCopyInternals # noqa from .traversals import MemoizedHasCacheKey # noqa from .visitors import ClauseVisitor from .visitors import ExtendedInternalTraversal @@ -699,6 +700,20 @@ class CacheableOptions(Options, HasCacheKey): return HasCacheKey._generate_cache_key_for_object(self) +class ExecutableOption(HasCopyInternals, HasCacheKey): + _annotations = util.EMPTY_DICT + + __visit_name__ = "executable_option" + + def _clone(self): + """Create a shallow copy of this ExecutableOption. + + """ + c = self.__class__.__new__(self.__class__) + c.__dict__ = dict(self.__dict__) + return c + + class Executable(Generative): """Mark a :class:`_expression.ClauseElement` as supporting execution. @@ -715,11 +730,18 @@ class Executable(Generative): _with_context_options = () _executable_traverse_internals = [ - ("_with_options", ExtendedInternalTraversal.dp_has_cache_key_list), + ("_with_options", InternalTraversal.dp_executable_options), ("_with_context_options", ExtendedInternalTraversal.dp_plain_obj), ("_propagate_attrs", ExtendedInternalTraversal.dp_propagate_attrs), ] + is_select = False + is_update = False + is_insert = False + is_text = False + is_delete = False + is_dml = False + @property def _effective_plugin_target(self): return self.__visit_name__ @@ -759,6 +781,22 @@ class Executable(Generative): ) @_generative + def _set_compile_options(self, compile_options): + """Assign the compile options to a new value. + + :param compile_options: appropriate CacheableOptions structure + + """ + + self._compile_options = compile_options + + @_generative + def _update_compile_options(self, options): + """update the _compile_options with new keys.""" + + self._compile_options += options + + @_generative def _add_context_option(self, callable_, cache_args): """Add a context option to this statement. diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index a8bd1de33..ac4055bdf 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -353,6 +353,7 @@ class FromLinter(collections.namedtuple("FromLinter", ["froms", "edges"])): message = template.format( froms=froms_str, start=self.froms[start_with] ) + util.warn(message) @@ -713,7 +714,10 @@ class SQLCompiler(Compiled): self.cache_key = cache_key if cache_key: - self._cache_key_bind_match = {b: b for b in cache_key[1]} + self._cache_key_bind_match = ckbm = { + b.key: b for b in cache_key[1] + } + ckbm.update({b: b for b in cache_key[1]}) # compile INSERT/UPDATE defaults/sequences to expect executemany # style execution, which may mean no pre-execute of defaults, @@ -2166,7 +2170,10 @@ class SQLCompiler(Compiled): # key was been generated. ckbm = self._cache_key_bind_match if ckbm: - ckbm.update({bp: bindparam for bp in bindparam._cloned_set}) + for bp in bindparam._cloned_set: + if bp.key in ckbm: + cb = ckbm[bp.key] + ckbm[cb] = bindparam if bindparam.isoutparam: self.has_out_parameters = True @@ -2186,6 +2193,7 @@ class SQLCompiler(Compiled): expanding=bindparam.expanding, **kwargs ) + if bindparam.expanding: ret = "(%s)" % ret return ret diff --git a/lib/sqlalchemy/sql/dml.py b/lib/sqlalchemy/sql/dml.py index 81baa9f52..21476c1f9 100644 --- a/lib/sqlalchemy/sql/dml.py +++ b/lib/sqlalchemy/sql/dml.py @@ -194,6 +194,8 @@ class UpdateBase( _hints = util.immutabledict() named_with_column = False + is_dml = True + @classmethod def _constructor_20_deprecations(cls, fn_name, clsname, names): @@ -774,6 +776,8 @@ class Insert(ValuesBase): select = None include_insert_from_select_defaults = False + is_insert = True + _traverse_internals = ( [ ("table", InternalTraversal.dp_clauseelement), @@ -1002,6 +1006,8 @@ class Update(DMLWhereBase, ValuesBase): __visit_name__ = "update" + is_update = True + _traverse_internals = ( [ ("table", InternalTraversal.dp_clauseelement), @@ -1247,6 +1253,8 @@ class Delete(DMLWhereBase, UpdateBase): __visit_name__ = "delete" + is_delete = True + _traverse_internals = ( [ ("table", InternalTraversal.dp_clauseelement), diff --git a/lib/sqlalchemy/sql/lambdas.py b/lib/sqlalchemy/sql/lambdas.py index 327003902..7d52f97ee 100644 --- a/lib/sqlalchemy/sql/lambdas.py +++ b/lib/sqlalchemy/sql/lambdas.py @@ -1,5 +1,5 @@ # sql/lambdas.py -# Copyright (C) 2005-2019 the SQLAlchemy authors and contributors +# Copyright (C) 2005-2020 the SQLAlchemy authors and contributors # <see AUTHORS file> # # This module is part of SQLAlchemy and is released under |