添加注册登录功能
This commit is contained in:
@@ -148,10 +148,11 @@ class QueryContext:
|
||||
def __init__(
|
||||
self,
|
||||
compile_state: CompileState,
|
||||
statement: Union[Select[Any], FromStatement[Any]],
|
||||
statement: Union[Select[Any], FromStatement[Any], UpdateBase],
|
||||
user_passed_query: Union[
|
||||
Select[Any],
|
||||
FromStatement[Any],
|
||||
UpdateBase,
|
||||
],
|
||||
params: _CoreSingleExecuteParams,
|
||||
session: Session,
|
||||
@@ -230,7 +231,7 @@ class AbstractORMCompileState(CompileState):
|
||||
if compiler is None:
|
||||
# this is the legacy / testing only ORM _compile_state() use case.
|
||||
# there is no need to apply criteria options for this.
|
||||
self.global_attributes = ga = {}
|
||||
self.global_attributes = {}
|
||||
assert toplevel
|
||||
return
|
||||
else:
|
||||
@@ -264,10 +265,10 @@ class AbstractORMCompileState(CompileState):
|
||||
@classmethod
|
||||
def create_for_statement(
|
||||
cls,
|
||||
statement: Union[Select, FromStatement],
|
||||
compiler: Optional[SQLCompiler],
|
||||
statement: Executable,
|
||||
compiler: SQLCompiler,
|
||||
**kw: Any,
|
||||
) -> AbstractORMCompileState:
|
||||
) -> CompileState:
|
||||
"""Create a context for a statement given a :class:`.Compiler`.
|
||||
|
||||
This method is always invoked in the context of SQLCompiler.process().
|
||||
@@ -413,8 +414,8 @@ class ORMCompileState(AbstractORMCompileState):
|
||||
attributes: Dict[Any, Any]
|
||||
global_attributes: Dict[Any, Any]
|
||||
|
||||
statement: Union[Select[Any], FromStatement[Any]]
|
||||
select_statement: Union[Select[Any], FromStatement[Any]]
|
||||
statement: Union[Select[Any], FromStatement[Any], UpdateBase]
|
||||
select_statement: Union[Select[Any], FromStatement[Any], UpdateBase]
|
||||
_entities: List[_QueryEntity]
|
||||
_polymorphic_adapters: Dict[_InternalEntityType, ORMAdapter]
|
||||
compile_options: Union[
|
||||
@@ -436,15 +437,30 @@ class ORMCompileState(AbstractORMCompileState):
|
||||
def __init__(self, *arg, **kw):
|
||||
raise NotImplementedError()
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@classmethod
|
||||
def create_for_statement(
|
||||
cls,
|
||||
statement: Executable,
|
||||
compiler: SQLCompiler,
|
||||
**kw: Any,
|
||||
) -> ORMCompileState:
|
||||
return cls._create_orm_context(
|
||||
cast("Union[Select, FromStatement]", statement),
|
||||
toplevel=not compiler.stack,
|
||||
compiler=compiler,
|
||||
**kw,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def create_for_statement(
|
||||
cls,
|
||||
statement: Union[Select, FromStatement],
|
||||
compiler: Optional[SQLCompiler],
|
||||
**kw: Any,
|
||||
) -> ORMCompileState: ...
|
||||
@classmethod
|
||||
def _create_orm_context(
|
||||
cls,
|
||||
statement: Union[Select, FromStatement],
|
||||
*,
|
||||
toplevel: bool,
|
||||
compiler: Optional[SQLCompiler],
|
||||
**kw: Any,
|
||||
) -> ORMCompileState:
|
||||
raise NotImplementedError()
|
||||
|
||||
def _append_dedupe_col_collection(self, obj, col_collection):
|
||||
dedupe = self.dedupe_columns
|
||||
@@ -654,8 +670,8 @@ class ORMCompileState(AbstractORMCompileState):
|
||||
)
|
||||
|
||||
|
||||
class DMLReturningColFilter:
|
||||
"""an adapter used for the DML RETURNING case.
|
||||
class _DMLReturningColFilter:
|
||||
"""a base for an adapter used for the DML RETURNING cases
|
||||
|
||||
Has a subset of the interface used by
|
||||
:class:`.ORMAdapter` and is used for :class:`._QueryEntity`
|
||||
@@ -689,6 +705,21 @@ class DMLReturningColFilter:
|
||||
else:
|
||||
return None
|
||||
|
||||
def adapt_check_present(self, col):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class _DMLBulkInsertReturningColFilter(_DMLReturningColFilter):
|
||||
"""an adapter used for the DML RETURNING case specifically
|
||||
for ORM bulk insert (or any hypothetical DML that is splitting out a class
|
||||
hierarchy among multiple DML statements....ORM bulk insert is the only
|
||||
example right now)
|
||||
|
||||
its main job is to limit the columns in a RETURNING to only a specific
|
||||
mapped table in a hierarchy.
|
||||
|
||||
"""
|
||||
|
||||
def adapt_check_present(self, col):
|
||||
mapper = self.mapper
|
||||
prop = mapper._columntoproperty.get(col, None)
|
||||
@@ -697,6 +728,30 @@ class DMLReturningColFilter:
|
||||
return mapper.local_table.c.corresponding_column(col)
|
||||
|
||||
|
||||
class _DMLUpdateDeleteReturningColFilter(_DMLReturningColFilter):
|
||||
"""an adapter used for the DML RETURNING case specifically
|
||||
for ORM enabled UPDATE/DELETE
|
||||
|
||||
its main job is to limit the columns in a RETURNING to include
|
||||
only direct persisted columns from the immediate selectable, not
|
||||
expressions like column_property(), or to also allow columns from other
|
||||
mappers for the UPDATE..FROM use case.
|
||||
|
||||
"""
|
||||
|
||||
def adapt_check_present(self, col):
|
||||
mapper = self.mapper
|
||||
prop = mapper._columntoproperty.get(col, None)
|
||||
if prop is not None:
|
||||
# if the col is from the immediate mapper, only return a persisted
|
||||
# column, not any kind of column_property expression
|
||||
return mapper.persist_selectable.c.corresponding_column(col)
|
||||
|
||||
# if the col is from some other mapper, just return it, assume the
|
||||
# user knows what they are doing
|
||||
return col
|
||||
|
||||
|
||||
@sql.base.CompileState.plugin_for("orm", "orm_from_statement")
|
||||
class ORMFromStatementCompileState(ORMCompileState):
|
||||
_from_obj_alias = None
|
||||
@@ -715,12 +770,16 @@ class ORMFromStatementCompileState(ORMCompileState):
|
||||
eager_joins = _EMPTY_DICT
|
||||
|
||||
@classmethod
|
||||
def create_for_statement(
|
||||
def _create_orm_context(
|
||||
cls,
|
||||
statement_container: Union[Select, FromStatement],
|
||||
statement: Union[Select, FromStatement],
|
||||
*,
|
||||
toplevel: bool,
|
||||
compiler: Optional[SQLCompiler],
|
||||
**kw: Any,
|
||||
) -> ORMFromStatementCompileState:
|
||||
statement_container = statement
|
||||
|
||||
assert isinstance(statement_container, FromStatement)
|
||||
|
||||
if compiler is not None and compiler.stack:
|
||||
@@ -851,14 +910,24 @@ class ORMFromStatementCompileState(ORMCompileState):
|
||||
return None
|
||||
|
||||
def setup_dml_returning_compile_state(self, dml_mapper):
|
||||
"""used by BulkORMInsert (and Update / Delete?) to set up a handler
|
||||
"""used by BulkORMInsert, Update, Delete to set up a handler
|
||||
for RETURNING to return ORM objects and expressions
|
||||
|
||||
"""
|
||||
target_mapper = self.statement._propagate_attrs.get(
|
||||
"plugin_subject", None
|
||||
)
|
||||
adapter = DMLReturningColFilter(target_mapper, dml_mapper)
|
||||
|
||||
if self.statement.is_insert:
|
||||
adapter = _DMLBulkInsertReturningColFilter(
|
||||
target_mapper, dml_mapper
|
||||
)
|
||||
elif self.statement.is_update or self.statement.is_delete:
|
||||
adapter = _DMLUpdateDeleteReturningColFilter(
|
||||
target_mapper, dml_mapper
|
||||
)
|
||||
else:
|
||||
adapter = None
|
||||
|
||||
if self.compile_options._is_star and (len(self._entities) != 1):
|
||||
raise sa_exc.CompileError(
|
||||
@@ -1017,21 +1086,17 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
|
||||
_having_criteria = ()
|
||||
|
||||
@classmethod
|
||||
def create_for_statement(
|
||||
def _create_orm_context(
|
||||
cls,
|
||||
statement: Union[Select, FromStatement],
|
||||
*,
|
||||
toplevel: bool,
|
||||
compiler: Optional[SQLCompiler],
|
||||
**kw: Any,
|
||||
) -> ORMSelectCompileState:
|
||||
"""compiler hook, we arrive here from compiler.visit_select() only."""
|
||||
|
||||
self = cls.__new__(cls)
|
||||
|
||||
if compiler is not None:
|
||||
toplevel = not compiler.stack
|
||||
else:
|
||||
toplevel = True
|
||||
|
||||
select_statement = statement
|
||||
|
||||
# if we are a select() that was never a legacy Query, we won't
|
||||
@@ -1799,8 +1864,6 @@ class ORMSelectCompileState(ORMCompileState, SelectState):
|
||||
"selectable/table as join target"
|
||||
)
|
||||
|
||||
of_type = None
|
||||
|
||||
if isinstance(onclause, interfaces.PropComparator):
|
||||
# descriptor/property given (or determined); this tells us
|
||||
# explicitly what the expected "left" side of the join is.
|
||||
@@ -2462,7 +2525,7 @@ def _column_descriptions(
|
||||
|
||||
|
||||
def _legacy_filter_by_entity_zero(
|
||||
query_or_augmented_select: Union[Query[Any], Select[Any]]
|
||||
query_or_augmented_select: Union[Query[Any], Select[Any]],
|
||||
) -> Optional[_InternalEntityType[Any]]:
|
||||
self = query_or_augmented_select
|
||||
if self._setup_joins:
|
||||
@@ -2477,7 +2540,7 @@ def _legacy_filter_by_entity_zero(
|
||||
|
||||
|
||||
def _entity_from_pre_ent_zero(
|
||||
query_or_augmented_select: Union[Query[Any], Select[Any]]
|
||||
query_or_augmented_select: Union[Query[Any], Select[Any]],
|
||||
) -> Optional[_InternalEntityType[Any]]:
|
||||
self = query_or_augmented_select
|
||||
if not self._raw_columns:
|
||||
@@ -2535,7 +2598,7 @@ class _QueryEntity:
|
||||
def setup_dml_returning_compile_state(
|
||||
self,
|
||||
compile_state: ORMCompileState,
|
||||
adapter: DMLReturningColFilter,
|
||||
adapter: Optional[_DMLReturningColFilter],
|
||||
) -> None:
|
||||
raise NotImplementedError()
|
||||
|
||||
@@ -2737,7 +2800,7 @@ class _MapperEntity(_QueryEntity):
|
||||
def setup_dml_returning_compile_state(
|
||||
self,
|
||||
compile_state: ORMCompileState,
|
||||
adapter: DMLReturningColFilter,
|
||||
adapter: Optional[_DMLReturningColFilter],
|
||||
) -> None:
|
||||
loading._setup_entity_query(
|
||||
compile_state,
|
||||
@@ -2896,7 +2959,7 @@ class _BundleEntity(_QueryEntity):
|
||||
def setup_dml_returning_compile_state(
|
||||
self,
|
||||
compile_state: ORMCompileState,
|
||||
adapter: DMLReturningColFilter,
|
||||
adapter: Optional[_DMLReturningColFilter],
|
||||
) -> None:
|
||||
return self.setup_compile_state(compile_state)
|
||||
|
||||
@@ -3086,7 +3149,7 @@ class _RawColumnEntity(_ColumnEntity):
|
||||
def setup_dml_returning_compile_state(
|
||||
self,
|
||||
compile_state: ORMCompileState,
|
||||
adapter: DMLReturningColFilter,
|
||||
adapter: Optional[_DMLReturningColFilter],
|
||||
) -> None:
|
||||
return self.setup_compile_state(compile_state)
|
||||
|
||||
@@ -3203,10 +3266,13 @@ class _ORMColumnEntity(_ColumnEntity):
|
||||
def setup_dml_returning_compile_state(
|
||||
self,
|
||||
compile_state: ORMCompileState,
|
||||
adapter: DMLReturningColFilter,
|
||||
adapter: Optional[_DMLReturningColFilter],
|
||||
) -> None:
|
||||
self._fetch_column = self.column
|
||||
column = adapter(self.column, False)
|
||||
|
||||
self._fetch_column = column = self.column
|
||||
if adapter:
|
||||
column = adapter(column, False)
|
||||
|
||||
if column is not None:
|
||||
compile_state.dedupe_columns.add(column)
|
||||
compile_state.primary_columns.append(column)
|
||||
|
||||
Reference in New Issue
Block a user