添加注册登录功能

This commit is contained in:
2025-08-29 00:34:40 +08:00
parent 09065f2ce7
commit 2fe3474d9e
3060 changed files with 29217 additions and 87137 deletions

View File

@@ -47,6 +47,7 @@ from . import type_api
from . import visitors
from ._typing import _ColumnsClauseArgument
from ._typing import _no_kw
from ._typing import _T
from ._typing import _TP
from ._typing import is_column_element
from ._typing import is_select_statement
@@ -71,6 +72,7 @@ from .base import ColumnCollection
from .base import ColumnSet
from .base import CompileState
from .base import DedupeColumnCollection
from .base import DialectKWArgs
from .base import Executable
from .base import Generative
from .base import HasCompileState
@@ -101,9 +103,9 @@ from ..util.typing import Literal
from ..util.typing import Protocol
from ..util.typing import Self
and_ = BooleanClauseList.and_
_T = TypeVar("_T", bound=Any)
if TYPE_CHECKING:
from ._typing import _ColumnExpressionArgument
@@ -286,7 +288,7 @@ class ExecutableReturnsRows(Executable, ReturnsRows):
class TypedReturnsRows(ExecutableReturnsRows, Generic[_TP]):
"""base for executable statements that return rows."""
"""base for a typed executable statements that return rows."""
class Selectable(ReturnsRows):
@@ -1339,7 +1341,7 @@ class Join(roles.DMLTableRole, FromClause):
c for c in self.right.c
]
primary_key.extend( # type: ignore
primary_key.extend(
sqlutil.reduce_columns(
(c for c in _columns if c.primary_key), self.onclause
)
@@ -1745,7 +1747,7 @@ class AliasedReturnsRows(NoInit, NamedFromClause):
def description(self) -> str:
name = self.name
if isinstance(name, _anonymous_label):
name = "anon_1"
return "anon_1"
return name
@@ -1785,6 +1787,14 @@ class AliasedReturnsRows(NoInit, NamedFromClause):
class FromClauseAlias(AliasedReturnsRows):
element: FromClause
@util.ro_non_memoized_property
def description(self) -> str:
name = self.name
if isinstance(name, _anonymous_label):
return f"Anonymous alias of {self.element.description}"
return name
class Alias(roles.DMLTableRole, FromClauseAlias):
"""Represents an table or selectable alias (AS).
@@ -2224,7 +2234,7 @@ class CTE(
_suffixes=self._suffixes,
)
def union(self, *other: _SelectStatementForCompoundArgument) -> CTE:
def union(self, *other: _SelectStatementForCompoundArgument[Any]) -> CTE:
r"""Return a new :class:`_expression.CTE` with a SQL ``UNION``
of the original CTE against the given selectables provided
as positional arguments.
@@ -2253,7 +2263,9 @@ class CTE(
_suffixes=self._suffixes,
)
def union_all(self, *other: _SelectStatementForCompoundArgument) -> CTE:
def union_all(
self, *other: _SelectStatementForCompoundArgument[Any]
) -> CTE:
r"""Return a new :class:`_expression.CTE` with a SQL ``UNION ALL``
of the original CTE against the given selectables provided
as positional arguments.
@@ -2514,6 +2526,14 @@ class HasCTE(roles.HasCTERole, SelectsRows):
_independent_ctes: Tuple[CTE, ...] = ()
_independent_ctes_opts: Tuple[_CTEOpts, ...] = ()
name_cte_columns: bool = False
"""indicates if this HasCTE as contained within a CTE should compel the CTE
to render the column names of this object in the WITH clause.
.. versionadded:: 2.0.42
"""
@_generative
def add_cte(self, *ctes: CTE, nest_here: bool = False) -> Self:
r"""Add one or more :class:`_sql.CTE` constructs to this statement.
@@ -3294,7 +3314,7 @@ class ForUpdateArg(ClauseElement):
self.of = None
class Values(roles.InElementRole, Generative, LateralFromClause):
class Values(roles.InElementRole, HasCTE, Generative, LateralFromClause):
"""Represent a ``VALUES`` construct that can be used as a FROM element
in a statement.
@@ -3315,7 +3335,9 @@ class Values(roles.InElementRole, Generative, LateralFromClause):
("_data", InternalTraversal.dp_dml_multi_values),
("name", InternalTraversal.dp_string),
("literal_binds", InternalTraversal.dp_boolean),
]
] + HasCTE._has_ctes_traverse_internals
name_cte_columns = True
def __init__(
self,
@@ -3339,6 +3361,10 @@ class Values(roles.InElementRole, Generative, LateralFromClause):
def _column_types(self) -> List[TypeEngine[Any]]:
return [col.type for col in self._column_args]
@util.ro_non_memoized_property
def _all_selected_columns(self) -> _SelectIterable:
return self._column_args
@_generative
def alias(self, name: Optional[str] = None, flat: bool = False) -> Self:
"""Return a new :class:`_expression.Values`
@@ -3368,7 +3394,7 @@ class Values(roles.InElementRole, Generative, LateralFromClause):
return self
@_generative
def lateral(self, name: Optional[str] = None) -> LateralFromClause:
def lateral(self, name: Optional[str] = None) -> Self:
"""Return a new :class:`_expression.Values` with the lateral flag set,
so that
it renders as LATERAL.
@@ -3486,6 +3512,8 @@ class ScalarValues(roles.InElementRole, GroupedElement, ColumnElement[Any]):
self, against: Optional[OperatorType] = None
) -> Self: ...
def _ungroup(self) -> ColumnElement[Any]: ...
class SelectBase(
roles.SelectStatementRole,
@@ -3924,7 +3952,7 @@ class SelectStatementGrouping(GroupedElement, SelectBase, Generic[_SB]):
raise NotImplementedError
class GenerativeSelect(SelectBase, Generative):
class GenerativeSelect(DialectKWArgs, SelectBase, Generative):
"""Base class for SELECT statements where additional elements can be
added.
@@ -4205,8 +4233,9 @@ class GenerativeSelect(SelectBase, Generative):
count: _LimitOffsetType,
with_ties: bool = False,
percent: bool = False,
**dialect_kw: Any,
) -> Self:
"""Return a new selectable with the given FETCH FIRST criterion
r"""Return a new selectable with the given FETCH FIRST criterion
applied.
This is a numeric value which usually renders as ``FETCH {FIRST | NEXT}
@@ -4236,6 +4265,11 @@ class GenerativeSelect(SelectBase, Generative):
:param percent: When ``True``, ``count`` represents the percentage
of the total number of selected rows to return. Defaults to ``False``
:param \**dialect_kw: Additional dialect-specific keyword arguments
may be accepted by dialects.
.. versionadded:: 2.0.41
.. seealso::
:meth:`_sql.GenerativeSelect.limit`
@@ -4243,7 +4277,7 @@ class GenerativeSelect(SelectBase, Generative):
:meth:`_sql.GenerativeSelect.offset`
"""
self._validate_dialect_kwargs(dialect_kw)
self._limit_clause = None
if count is None:
self._fetch_clause = self._fetch_clause_options = None
@@ -4448,7 +4482,7 @@ class _CompoundSelectKeyword(Enum):
INTERSECT_ALL = "INTERSECT ALL"
class CompoundSelect(HasCompileState, GenerativeSelect, ExecutableReturnsRows):
class CompoundSelect(HasCompileState, GenerativeSelect, TypedReturnsRows[_TP]):
"""Forms the basis of ``UNION``, ``UNION ALL``, and other
SELECT-based set operations.
@@ -4485,6 +4519,7 @@ class CompoundSelect(HasCompileState, GenerativeSelect, ExecutableReturnsRows):
]
+ SupportsCloneAnnotations._clone_annotations_traverse_internals
+ HasCTE._has_ctes_traverse_internals
+ DialectKWArgs._dialect_kwargs_traverse_internals
)
selects: List[SelectBase]
@@ -4495,7 +4530,7 @@ class CompoundSelect(HasCompileState, GenerativeSelect, ExecutableReturnsRows):
def __init__(
self,
keyword: _CompoundSelectKeyword,
*selects: _SelectStatementForCompoundArgument,
*selects: _SelectStatementForCompoundArgument[_TP],
):
self.keyword = keyword
self.selects = [
@@ -4509,38 +4544,38 @@ class CompoundSelect(HasCompileState, GenerativeSelect, ExecutableReturnsRows):
@classmethod
def _create_union(
cls, *selects: _SelectStatementForCompoundArgument
) -> CompoundSelect:
cls, *selects: _SelectStatementForCompoundArgument[_TP]
) -> CompoundSelect[_TP]:
return CompoundSelect(_CompoundSelectKeyword.UNION, *selects)
@classmethod
def _create_union_all(
cls, *selects: _SelectStatementForCompoundArgument
) -> CompoundSelect:
cls, *selects: _SelectStatementForCompoundArgument[_TP]
) -> CompoundSelect[_TP]:
return CompoundSelect(_CompoundSelectKeyword.UNION_ALL, *selects)
@classmethod
def _create_except(
cls, *selects: _SelectStatementForCompoundArgument
) -> CompoundSelect:
cls, *selects: _SelectStatementForCompoundArgument[_TP]
) -> CompoundSelect[_TP]:
return CompoundSelect(_CompoundSelectKeyword.EXCEPT, *selects)
@classmethod
def _create_except_all(
cls, *selects: _SelectStatementForCompoundArgument
) -> CompoundSelect:
cls, *selects: _SelectStatementForCompoundArgument[_TP]
) -> CompoundSelect[_TP]:
return CompoundSelect(_CompoundSelectKeyword.EXCEPT_ALL, *selects)
@classmethod
def _create_intersect(
cls, *selects: _SelectStatementForCompoundArgument
) -> CompoundSelect:
cls, *selects: _SelectStatementForCompoundArgument[_TP]
) -> CompoundSelect[_TP]:
return CompoundSelect(_CompoundSelectKeyword.INTERSECT, *selects)
@classmethod
def _create_intersect_all(
cls, *selects: _SelectStatementForCompoundArgument
) -> CompoundSelect:
cls, *selects: _SelectStatementForCompoundArgument[_TP]
) -> CompoundSelect[_TP]:
return CompoundSelect(_CompoundSelectKeyword.INTERSECT_ALL, *selects)
def _scalar_type(self) -> TypeEngine[Any]:
@@ -4557,7 +4592,7 @@ class CompoundSelect(HasCompileState, GenerativeSelect, ExecutableReturnsRows):
return True
return False
def set_label_style(self, style: SelectLabelStyle) -> CompoundSelect:
def set_label_style(self, style: SelectLabelStyle) -> Self:
if self._label_style is not style:
self = self._generate()
select_0 = self.selects[0].set_label_style(style)
@@ -4565,7 +4600,7 @@ class CompoundSelect(HasCompileState, GenerativeSelect, ExecutableReturnsRows):
return self
def _ensure_disambiguated_names(self) -> CompoundSelect:
def _ensure_disambiguated_names(self) -> Self:
new_select = self.selects[0]._ensure_disambiguated_names()
if new_select is not self.selects[0]:
self = self._generate()
@@ -4691,7 +4726,7 @@ class SelectState(util.MemoizedSlots, CompileState):
def __init__(
self,
statement: Select[Any],
compiler: Optional[SQLCompiler],
compiler: SQLCompiler,
**kw: Any,
):
self.statement = statement
@@ -5306,6 +5341,7 @@ class Select(
+ HasHints._has_hints_traverse_internals
+ SupportsCloneAnnotations._clone_annotations_traverse_internals
+ Executable._executable_traverse_internals
+ DialectKWArgs._dialect_kwargs_traverse_internals
)
_cache_key_traversal: _CacheKeyTraversalType = _traverse_internals + [
@@ -5327,7 +5363,9 @@ class Select(
stmt.__dict__.update(kw)
return stmt
def __init__(self, *entities: _ColumnsClauseArgument[Any]):
def __init__(
self, *entities: _ColumnsClauseArgument[Any], **dialect_kw: Any
):
r"""Construct a new :class:`_expression.Select`.
The public constructor for :class:`_expression.Select` is the
@@ -5340,7 +5378,6 @@ class Select(
)
for ent in entities
]
GenerativeSelect.__init__(self)
def _scalar_type(self) -> TypeEngine[Any]:
@@ -5739,8 +5776,9 @@ class Select(
:attr:`_sql.Select.columns_clause_froms`
"""
compiler = self._default_compiler()
return self._compile_state_factory(self, None)._get_display_froms()
return self._compile_state_factory(self, compiler)._get_display_froms()
@property
@util.deprecated(
@@ -6585,8 +6623,8 @@ class Select(
return SelectStatementGrouping(self)
def union(
self, *other: _SelectStatementForCompoundArgument
) -> CompoundSelect:
self, *other: _SelectStatementForCompoundArgument[_TP]
) -> CompoundSelect[_TP]:
r"""Return a SQL ``UNION`` of this select() construct against
the given selectables provided as positional arguments.
@@ -6604,8 +6642,8 @@ class Select(
return CompoundSelect._create_union(self, *other)
def union_all(
self, *other: _SelectStatementForCompoundArgument
) -> CompoundSelect:
self, *other: _SelectStatementForCompoundArgument[_TP]
) -> CompoundSelect[_TP]:
r"""Return a SQL ``UNION ALL`` of this select() construct against
the given selectables provided as positional arguments.
@@ -6623,8 +6661,8 @@ class Select(
return CompoundSelect._create_union_all(self, *other)
def except_(
self, *other: _SelectStatementForCompoundArgument
) -> CompoundSelect:
self, *other: _SelectStatementForCompoundArgument[_TP]
) -> CompoundSelect[_TP]:
r"""Return a SQL ``EXCEPT`` of this select() construct against
the given selectable provided as positional arguments.
@@ -6639,8 +6677,8 @@ class Select(
return CompoundSelect._create_except(self, *other)
def except_all(
self, *other: _SelectStatementForCompoundArgument
) -> CompoundSelect:
self, *other: _SelectStatementForCompoundArgument[_TP]
) -> CompoundSelect[_TP]:
r"""Return a SQL ``EXCEPT ALL`` of this select() construct against
the given selectables provided as positional arguments.
@@ -6655,8 +6693,8 @@ class Select(
return CompoundSelect._create_except_all(self, *other)
def intersect(
self, *other: _SelectStatementForCompoundArgument
) -> CompoundSelect:
self, *other: _SelectStatementForCompoundArgument[_TP]
) -> CompoundSelect[_TP]:
r"""Return a SQL ``INTERSECT`` of this select() construct against
the given selectables provided as positional arguments.
@@ -6674,8 +6712,8 @@ class Select(
return CompoundSelect._create_intersect(self, *other)
def intersect_all(
self, *other: _SelectStatementForCompoundArgument
) -> CompoundSelect:
self, *other: _SelectStatementForCompoundArgument[_TP]
) -> CompoundSelect[_TP]:
r"""Return a SQL ``INTERSECT ALL`` of this select() construct
against the given selectables provided as positional arguments.
@@ -6762,9 +6800,8 @@ class ScalarSelect(
def self_group(self, against: Optional[OperatorType] = None) -> Self:
return self
if TYPE_CHECKING:
def _ungroup(self) -> Select[Any]: ...
def _ungroup(self) -> Self:
return self
@_generative
def correlate(
@@ -6852,7 +6889,6 @@ class Exists(UnaryExpression[bool]):
"""
inherit_cache = True
element: Union[SelectStatementGrouping[Select[Any]], ScalarSelect[Any]]
def __init__(
self,
@@ -6878,7 +6914,6 @@ class Exists(UnaryExpression[bool]):
s,
operator=operators.exists,
type_=type_api.BOOLEANTYPE,
wraps_column_expression=True,
)
@util.ro_non_memoized_property
@@ -6886,13 +6921,19 @@ class Exists(UnaryExpression[bool]):
return []
def _regroup(
self, fn: Callable[[Select[Any]], Select[Any]]
) -> SelectStatementGrouping[Select[Any]]:
element = self.element._ungroup()
self,
fn: Callable[[Select[Any]], Select[Any]],
) -> ScalarSelect[Any]:
assert isinstance(self.element, ScalarSelect)
element = self.element.element
if not isinstance(element, Select):
raise exc.InvalidRequestError(
"Can only apply this operation to a plain SELECT construct"
)
new_element = fn(element)
return_value = new_element.self_group(against=operators.exists)
assert isinstance(return_value, SelectStatementGrouping)
return_value = new_element.scalar_subquery()
return return_value
def select(self) -> Select[Tuple[bool]]:
@@ -6947,7 +6988,6 @@ class Exists(UnaryExpression[bool]):
:meth:`_sql.ScalarSelect.correlate_except`
"""
e = self._clone()
e.element = self._regroup(
lambda element: element.correlate_except(*fromclauses)