mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Проверка 09.02.2025
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# orm/interfaces.py
|
||||
# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
|
||||
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
|
||||
# <see AUTHORS file>
|
||||
#
|
||||
# This module is part of SQLAlchemy and is released under
|
||||
@@ -149,13 +149,17 @@ class ORMColumnDescription(TypedDict):
|
||||
class _IntrospectsAnnotations:
|
||||
__slots__ = ()
|
||||
|
||||
@classmethod
|
||||
def _mapper_property_name(cls) -> str:
|
||||
return cls.__name__
|
||||
|
||||
def found_in_pep593_annotated(self) -> Any:
|
||||
"""return a copy of this object to use in declarative when the
|
||||
object is found inside of an Annotated object."""
|
||||
|
||||
raise NotImplementedError(
|
||||
f"Use of the {self.__class__} construct inside of an "
|
||||
f"Annotated object is not yet supported."
|
||||
f"Use of the {self._mapper_property_name()!r} "
|
||||
"construct inside of an Annotated object is not yet supported."
|
||||
)
|
||||
|
||||
def declarative_scan(
|
||||
@@ -181,7 +185,8 @@ class _IntrospectsAnnotations:
|
||||
raise sa_exc.ArgumentError(
|
||||
f"Python typing annotation is required for attribute "
|
||||
f'"{cls.__name__}.{key}" when primary argument(s) for '
|
||||
f'"{self.__class__.__name__}" construct are None or not present'
|
||||
f'"{self._mapper_property_name()}" '
|
||||
"construct are None or not present"
|
||||
)
|
||||
|
||||
|
||||
@@ -201,6 +206,7 @@ class _AttributeOptions(NamedTuple):
|
||||
dataclasses_default_factory: Union[_NoArg, Callable[[], Any]]
|
||||
dataclasses_compare: Union[_NoArg, bool]
|
||||
dataclasses_kw_only: Union[_NoArg, bool]
|
||||
dataclasses_hash: Union[_NoArg, bool, None]
|
||||
|
||||
def _as_dataclass_field(self, key: str) -> Any:
|
||||
"""Return a ``dataclasses.Field`` object given these arguments."""
|
||||
@@ -218,6 +224,8 @@ class _AttributeOptions(NamedTuple):
|
||||
kw["compare"] = self.dataclasses_compare
|
||||
if self.dataclasses_kw_only is not _NoArg.NO_ARG:
|
||||
kw["kw_only"] = self.dataclasses_kw_only
|
||||
if self.dataclasses_hash is not _NoArg.NO_ARG:
|
||||
kw["hash"] = self.dataclasses_hash
|
||||
|
||||
if "default" in kw and callable(kw["default"]):
|
||||
# callable defaults are ambiguous. deprecate them in favour of
|
||||
@@ -297,6 +305,7 @@ _DEFAULT_ATTRIBUTE_OPTIONS = _AttributeOptions(
|
||||
_NoArg.NO_ARG,
|
||||
_NoArg.NO_ARG,
|
||||
_NoArg.NO_ARG,
|
||||
_NoArg.NO_ARG,
|
||||
)
|
||||
|
||||
_DEFAULT_READONLY_ATTRIBUTE_OPTIONS = _AttributeOptions(
|
||||
@@ -306,6 +315,7 @@ _DEFAULT_READONLY_ATTRIBUTE_OPTIONS = _AttributeOptions(
|
||||
_NoArg.NO_ARG,
|
||||
_NoArg.NO_ARG,
|
||||
_NoArg.NO_ARG,
|
||||
_NoArg.NO_ARG,
|
||||
)
|
||||
|
||||
|
||||
@@ -675,27 +685,37 @@ class PropComparator(SQLORMOperations[_T_co], Generic[_T_co], ColumnOperators):
|
||||
|
||||
# definition of custom PropComparator subclasses
|
||||
|
||||
from sqlalchemy.orm.properties import \
|
||||
ColumnProperty,\
|
||||
Composite,\
|
||||
Relationship
|
||||
from sqlalchemy.orm.properties import (
|
||||
ColumnProperty,
|
||||
Composite,
|
||||
Relationship,
|
||||
)
|
||||
|
||||
|
||||
class MyColumnComparator(ColumnProperty.Comparator):
|
||||
def __eq__(self, other):
|
||||
return self.__clause_element__() == other
|
||||
|
||||
|
||||
class MyRelationshipComparator(Relationship.Comparator):
|
||||
def any(self, expression):
|
||||
"define the 'any' operation"
|
||||
# ...
|
||||
|
||||
|
||||
class MyCompositeComparator(Composite.Comparator):
|
||||
def __gt__(self, other):
|
||||
"redefine the 'greater than' operation"
|
||||
|
||||
return sql.and_(*[a>b for a, b in
|
||||
zip(self.__clause_element__().clauses,
|
||||
other.__composite_values__())])
|
||||
return sql.and_(
|
||||
*[
|
||||
a > b
|
||||
for a, b in zip(
|
||||
self.__clause_element__().clauses,
|
||||
other.__composite_values__(),
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
# application of custom PropComparator subclasses
|
||||
@@ -703,17 +723,22 @@ class PropComparator(SQLORMOperations[_T_co], Generic[_T_co], ColumnOperators):
|
||||
from sqlalchemy.orm import column_property, relationship, composite
|
||||
from sqlalchemy import Column, String
|
||||
|
||||
class SomeMappedClass(Base):
|
||||
some_column = column_property(Column("some_column", String),
|
||||
comparator_factory=MyColumnComparator)
|
||||
|
||||
some_relationship = relationship(SomeOtherClass,
|
||||
comparator_factory=MyRelationshipComparator)
|
||||
class SomeMappedClass(Base):
|
||||
some_column = column_property(
|
||||
Column("some_column", String),
|
||||
comparator_factory=MyColumnComparator,
|
||||
)
|
||||
|
||||
some_relationship = relationship(
|
||||
SomeOtherClass, comparator_factory=MyRelationshipComparator
|
||||
)
|
||||
|
||||
some_composite = composite(
|
||||
Column("a", String), Column("b", String),
|
||||
comparator_factory=MyCompositeComparator
|
||||
)
|
||||
Column("a", String),
|
||||
Column("b", String),
|
||||
comparator_factory=MyCompositeComparator,
|
||||
)
|
||||
|
||||
Note that for column-level operator redefinition, it's usually
|
||||
simpler to define the operators at the Core level, using the
|
||||
@@ -855,8 +880,9 @@ class PropComparator(SQLORMOperations[_T_co], Generic[_T_co], ColumnOperators):
|
||||
|
||||
e.g.::
|
||||
|
||||
query.join(Company.employees.of_type(Engineer)).\
|
||||
filter(Engineer.name=='foo')
|
||||
query.join(Company.employees.of_type(Engineer)).filter(
|
||||
Engineer.name == "foo"
|
||||
)
|
||||
|
||||
:param \class_: a class or mapper indicating that criterion will be
|
||||
against this specific subclass.
|
||||
@@ -882,11 +908,11 @@ class PropComparator(SQLORMOperations[_T_co], Generic[_T_co], ColumnOperators):
|
||||
|
||||
|
||||
stmt = select(User).join(
|
||||
User.addresses.and_(Address.email_address != 'foo')
|
||||
User.addresses.and_(Address.email_address != "foo")
|
||||
)
|
||||
|
||||
stmt = select(User).options(
|
||||
joinedload(User.addresses.and_(Address.email_address != 'foo'))
|
||||
joinedload(User.addresses.and_(Address.email_address != "foo"))
|
||||
)
|
||||
|
||||
.. versionadded:: 1.4
|
||||
|
Reference in New Issue
Block a user