diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-06-03 17:38:35 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-06-06 13:31:54 -0400 |
commit | 3ab2364e78641c4f0e4b6456afc2cbed39b0d0e6 (patch) | |
tree | f3dc26609070c1a357a366592c791a3ec0655483 /lib/sqlalchemy/sql/dml.py | |
parent | 14bc09203a8b5b2bc001f764ad7cce6a184975cc (diff) | |
download | sqlalchemy-3ab2364e78641c4f0e4b6456afc2cbed39b0d0e6.tar.gz |
Convert bulk update/delete to new execution model
This reorganizes the BulkUD model in sqlalchemy.orm.persistence
to be based on the CompileState concept and to allow plain
update() / delete() to be passed to session.execute() where
the ORM synchronize session logic will take place.
Also gets "synchronize_session='fetch'" working with horizontal
sharding.
Adding a few more result.scalar_one() types of methods
as scalar_one() seems like what is normally desired.
Fixes: #5160
Change-Id: I8001ebdad089da34119eb459709731ba6c0ba975
Diffstat (limited to 'lib/sqlalchemy/sql/dml.py')
-rw-r--r-- | lib/sqlalchemy/sql/dml.py | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/dml.py b/lib/sqlalchemy/sql/dml.py index 467a764d6..a82641d77 100644 --- a/lib/sqlalchemy/sql/dml.py +++ b/lib/sqlalchemy/sql/dml.py @@ -19,6 +19,7 @@ from .base import CompileState from .base import DialectKWArgs from .base import Executable from .base import HasCompileState +from .elements import BooleanClauseList from .elements import ClauseElement from .elements import Null from .selectable import HasCTE @@ -150,7 +151,6 @@ class UpdateDMLState(DMLState): def __init__(self, statement, compiler, **kw): self.statement = statement - self.isupdate = True self._preserve_parameter_order = statement._preserve_parameter_order if statement._ordered_values is not None: @@ -447,7 +447,9 @@ class ValuesBase(UpdateBase): _returning = () def __init__(self, table, values, prefixes): - self.table = coercions.expect(roles.FromClauseRole, table) + self.table = coercions.expect( + roles.DMLTableRole, table, apply_propagate_attrs=self + ) if values is not None: self.values.non_generative(self, values) if prefixes: @@ -949,6 +951,28 @@ class DMLWhereBase(object): coercions.expect(roles.WhereHavingRole, whereclause), ) + def filter(self, *criteria): + """A synonym for the :meth:`_dml.DMLWhereBase.where` method.""" + + return self.where(*criteria) + + @property + def whereclause(self): + """Return the completed WHERE clause for this :class:`.DMLWhereBase` + statement. + + This assembles the current collection of WHERE criteria + into a single :class:`_expression.BooleanClauseList` construct. + + + .. versionadded:: 1.4 + + """ + + return BooleanClauseList._construct_for_whereclause( + self._where_criteria + ) + class Update(DMLWhereBase, ValuesBase): """Represent an Update construct. @@ -1266,7 +1290,9 @@ class Delete(DMLWhereBase, UpdateBase): """ self._bind = bind - self.table = coercions.expect(roles.FromClauseRole, table) + self.table = coercions.expect( + roles.DMLTableRole, table, apply_propagate_attrs=self + ) self._returning = returning if prefixes: |