관리-도구
편집 파일: _elements_constructors.cpython-38.pyc
U -?�fH� � @ s� d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d lm Z d d lmZ d dlmZ d dlm Z d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z d dlm!Z! d dlm"Z" d d lm#Z# d d!lm$Z$ d d"lm%Z% d d lm Z d d#lm&Z& d d$lm'Z' d d%lm(Z( d d&l)m*Z* d'd(l+m,Z, ej�r8d d)l-m.Z. d d*l-m/Z/ d d+l-m0Z0 d d,l-m1Z1 d d-l-m2Z2 d d.lm3Z3 d d/l4m5Z5 d d0l6m7Z7 ed1�Z8d2d3d4�d5d6�Z9d7d8d9d:�d;d<�Z:e�spd=d<� Z:d2d3d4�d>d?�Z;d@dAdB�dCdD�Z<dEdFdGdH�dIdJ�Z=d�dLdMdMdNdOdP�dQdR�Z>d�dFdSdTdU�dVdW�Z?edXdXdY�dZd[��Z@ed2d\dY�d]d[��Z@d2d\dY�d^d[�Z@ejAddKejAdddKdKdKf d_dMd`dNdadbdcdNdNdNdTdd�dedf�ZBdddg�dhdididjdk�dldm�ZCdndodpdq�drds�ZDdndodtdq�dudv�ZEd�dFd`dNdwdxdy�dzd{�ZFd@dAdB�d|d}�ZGd2dAd4�d~d�ZHd2dAd4�d�d��ZIdFd�d�d��d�d��ZJd�d��d�d��ZKd�d8d�d��d�d��ZLd�dFd2d`d�d��d�d��ZMd�d��d�d��ZNd2dAdB�d�d��ZOd2dAdB�d�d��ZPd�d8d9d:�d�d��ZQe�s^d�d�� ZQd�d�d�d�d�d�d�d��d�d��ZRed�d�d��dFd�d��d�d���ZSd�d��d�d��ZTdd��d�d�d�d��d�d��ZUdndod�dq�d�d��ZVd�d�d�d��d�d��ZWdS )�� )�annotationsN)�Any)�Callable)�Mapping)�Optional)�overload)�Sequence��Tuple)� TYPE_CHECKING)�TypeVar)�Union� )� coercions)�roles)�_NoArg)�_document_text_coercion�� BindParameter)�BooleanClauseList��Case��Cast)�CollationClause)�CollectionAggregate��ColumnClause)� ColumnElement��Extract)�False_��FunctionFilter��Label)�Null��Over�� TextClause)�True_��TryCast�� TypeCoerce)�UnaryExpression��WithinGroup)�FunctionElement� )�Literal)�_ByArgument)�_ColumnExpressionArgument)�"_ColumnExpressionOrLiteralArgument)�#_ColumnExpressionOrStrLabelArgument)�_TypeEngineArgument)�BinaryExpression)� FromClause)� TypeEngine�_Tz_ColumnExpressionArgument[_T]zCollectionAggregate[bool])�expr�returnc C s t �| �S )ak Produce an ALL expression. For dialects such as that of PostgreSQL, this operator applies to usage of the :class:`_types.ARRAY` datatype, for that of MySQL, it may apply to a subquery. e.g.:: # renders on PostgreSQL: # '5 = ALL (somearray)' expr = 5 == all_(mytable.c.somearray) # renders on MySQL: # '5 = ALL (SELECT value FROM table)' expr = 5 == all_(select(table.c.value)) Comparison to NULL may work using ``None``:: None == all_(mytable.c.somearray) The any_() / all_() operators also feature a special "operand flipping" behavior such that if any_() / all_() are used on the left side of a comparison using a standalone operator such as ``==``, ``!=``, etc. (not including operator methods such as :meth:`_sql.ColumnOperators.is_`) the rendered expression is flipped:: # would render '5 = ALL (column)` all_(mytable.c.column) == 5 Or with ``None``, which note will not perform the usual step of rendering "IS" as is normally the case for NULL:: # would render 'NULL = ALL(somearray)' all_(mytable.c.somearray) == None .. versionchanged:: 1.4.26 repaired the use of any_() / all_() comparing to NULL on the right side to be flipped to the left. The column-level :meth:`_sql.ColumnElement.all_` method (not to be confused with :class:`_types.ARRAY` level :meth:`_types.ARRAY.Comparator.all`) is shorthand for ``all_(col)``:: 5 == mytable.c.somearray.all_() .. seealso:: :meth:`_sql.ColumnOperators.all_` :func:`_expression.any_` )r Z_create_all�r? � rB �U/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/sql/_elements_constructors.py�all_? s 3rD z5Union[Literal[True], _ColumnExpressionArgument[bool]]z_ColumnExpressionArgument[bool]zColumnElement[bool])�initial_clause�clausesr@ c G s dS )a� Produce a conjunction of expressions joined by ``AND``. E.g.:: from sqlalchemy import and_ stmt = select(users_table).where( and_( users_table.c.name == 'wendy', users_table.c.enrolled == True ) ) The :func:`.and_` conjunction is also available using the Python ``&`` operator (though note that compound expressions need to be parenthesized in order to function with Python operator precedence behavior):: stmt = select(users_table).where( (users_table.c.name == 'wendy') & (users_table.c.enrolled == True) ) The :func:`.and_` operation is also implicit in some cases; the :meth:`_expression.Select.where` method for example can be invoked multiple times against a statement, which will have the effect of each clause being combined using :func:`.and_`:: stmt = select(users_table).\ where(users_table.c.name == 'wendy').\ where(users_table.c.enrolled == True) The :func:`.and_` construct must be given at least one positional argument in order to be valid; a :func:`.and_` construct with no arguments is ambiguous. To produce an "empty" or dynamically generated :func:`.and_` expression, from a given list of expressions, a "default" element of :func:`_sql.true` (or just ``True``) should be specified:: from sqlalchemy import true criteria = and_(true(), *expressions) The above expression will compile to SQL as the expression ``true`` or ``1 = 1``, depending on backend, if no other expressions are present. If expressions are present, then the :func:`_sql.true` value is ignored as it does not affect the outcome of an AND expression that has other elements. .. deprecated:: 1.4 The :func:`.and_` element now requires that at least one argument is passed; creating the :func:`.and_` construct with no arguments is deprecated, and will emit a deprecation warning while continuing to produce a blank SQL string. .. seealso:: :func:`.or_` NrB �rE rF rB rB rC �and_u s ?rH c G s t j| � S )a~ Produce a conjunction of expressions joined by ``AND``. E.g.:: from sqlalchemy import and_ stmt = select(users_table).where( and_( users_table.c.name == 'wendy', users_table.c.enrolled == True ) ) The :func:`.and_` conjunction is also available using the Python ``&`` operator (though note that compound expressions need to be parenthesized in order to function with Python operator precedence behavior):: stmt = select(users_table).where( (users_table.c.name == 'wendy') & (users_table.c.enrolled == True) ) The :func:`.and_` operation is also implicit in some cases; the :meth:`_expression.Select.where` method for example can be invoked multiple times against a statement, which will have the effect of each clause being combined using :func:`.and_`:: stmt = select(users_table).\ where(users_table.c.name == 'wendy').\ where(users_table.c.enrolled == True) The :func:`.and_` construct must be given at least one positional argument in order to be valid; a :func:`.and_` construct with no arguments is ambiguous. To produce an "empty" or dynamically generated :func:`.and_` expression, from a given list of expressions, a "default" element of :func:`_sql.true` (or just ``True``) should be specified:: from sqlalchemy import true criteria = and_(true(), *expressions) The above expression will compile to SQL as the expression ``true`` or ``1 = 1``, depending on backend, if no other expressions are present. If expressions are present, then the :func:`_sql.true` value is ignored as it does not affect the outcome of an AND expression that has other elements. .. deprecated:: 1.4 The :func:`.and_` element now requires that at least one argument is passed; creating the :func:`.and_` construct with no arguments is deprecated, and will emit a deprecation warning while continuing to produce a blank SQL string. .. seealso:: :func:`.or_` )r rH �rF rB rB rC rH � s <c C s t �| �S )a Produce an ANY expression. For dialects such as that of PostgreSQL, this operator applies to usage of the :class:`_types.ARRAY` datatype, for that of MySQL, it may apply to a subquery. e.g.:: # renders on PostgreSQL: # '5 = ANY (somearray)' expr = 5 == any_(mytable.c.somearray) # renders on MySQL: # '5 = ANY (SELECT value FROM table)' expr = 5 == any_(select(table.c.value)) Comparison to NULL may work using ``None`` or :func:`_sql.null`:: None == any_(mytable.c.somearray) The any_() / all_() operators also feature a special "operand flipping" behavior such that if any_() / all_() are used on the left side of a comparison using a standalone operator such as ``==``, ``!=``, etc. (not including operator methods such as :meth:`_sql.ColumnOperators.is_`) the rendered expression is flipped:: # would render '5 = ANY (column)` any_(mytable.c.column) == 5 Or with ``None``, which note will not perform the usual step of rendering "IS" as is normally the case for NULL:: # would render 'NULL = ANY(somearray)' any_(mytable.c.somearray) == None .. versionchanged:: 1.4.26 repaired the use of any_() / all_() comparing to NULL on the right side to be flipped to the left. The column-level :meth:`_sql.ColumnElement.any_` method (not to be confused with :class:`_types.ARRAY` level :meth:`_types.ARRAY.Comparator.any`) is shorthand for ``any_(col)``:: 5 = mytable.c.somearray.any_() .. seealso:: :meth:`_sql.ColumnOperators.any_` :func:`_expression.all_` )r Z_create_anyrA rB rB rC �any_� s 3rJ z'_ColumnExpressionOrStrLabelArgument[_T]zUnaryExpression[_T])�columnr@ c C s t �| �S )a Produce an ascending ``ORDER BY`` clause element. e.g.:: from sqlalchemy import asc stmt = select(users_table).order_by(asc(users_table.c.name)) will produce SQL as:: SELECT id, name FROM user ORDER BY name ASC The :func:`.asc` function is a standalone version of the :meth:`_expression.ColumnElement.asc` method available on all SQL expressions, e.g.:: stmt = select(users_table).order_by(users_table.c.name.asc()) :param column: A :class:`_expression.ColumnElement` (e.g. scalar SQL expression) with which to apply the :func:`.asc` operation. .. seealso:: :func:`.desc` :func:`.nulls_first` :func:`.nulls_last` :meth:`_expression.Select.order_by` )r0 Z_create_asc�rK rB rB rC �asc. s %rM z_ColumnExpressionArgument[str]�strzBinaryExpression[str])� expression� collationr@ c C s t �| |�S )a� Return the clause ``expression COLLATE collation``. e.g.:: collate(mycolumn, 'utf8_bin') produces:: mycolumn COLLATE utf8_bin The collation expression is also quoted if it is a case sensitive identifier, e.g. contains uppercase characters. .. versionchanged:: 1.2 quoting is automatically applied to COLLATE expressions if they are case sensitive. )r Z_create_collation_expression)rO rP rB rB rC �collateV s rQ Fz&_ColumnExpressionOrLiteralArgument[_T]r �boolzBinaryExpression[bool])r? �lower_bound�upper_bound� symmetricr@ c C s t �tj| �}|j|||d�S )aV Produce a ``BETWEEN`` predicate clause. E.g.:: from sqlalchemy import between stmt = select(users_table).where(between(users_table.c.id, 5, 7)) Would produce SQL resembling:: SELECT id, name FROM user WHERE id BETWEEN :id_1 AND :id_2 The :func:`.between` function is a standalone version of the :meth:`_expression.ColumnElement.between` method available on all SQL expressions, as in:: stmt = select(users_table).where(users_table.c.id.between(5, 7)) All arguments passed to :func:`.between`, including the left side column expression, are coerced from Python scalar values if a the value is not a :class:`_expression.ColumnElement` subclass. For example, three fixed values can be compared as in:: print(between(5, 3, 7)) Which would produce:: :param_1 BETWEEN :param_2 AND :param_3 :param expr: a column expression, typically a :class:`_expression.ColumnElement` instance or alternatively a Python scalar expression to be coerced into a column expression, serving as the left side of the ``BETWEEN`` expression. :param lower_bound: a column or Python scalar expression serving as the lower bound of the right side of the ``BETWEEN`` expression. :param upper_bound: a column or Python scalar expression serving as the upper bound of the right side of the ``BETWEEN`` expression. :param symmetric: if True, will render " BETWEEN SYMMETRIC ". Note that not all databases support this syntax. .. seealso:: :meth:`_expression.ColumnElement.between` )rU )r �expectr �ExpressionElementRole�between)r? rS rT rU Zcol_exprrB rB rC rX m s 7rX zOptional[TypeEngine[_T]]zBindParameter[_T])�key�type_r@ c C s t | d|ddd�S )ax Create an 'OUT' parameter for usage in functions (stored procedures), for databases which support them. The ``outparam`` can be used like a regular function parameter. The "output" value will be available from the :class:`~sqlalchemy.engine.CursorResult` object via its ``out_parameters`` attribute, which returns a dictionary containing the values. NFT)rZ �unique� isoutparamr )rY rZ rB rB rC �outparam� s r] zBinaryExpression[_T])�clauser@ c C s d S �NrB �r^ rB rB rC �not_� s ra zColumnElement[_T]c C s d S r_ rB r` rB rB rC ra � s c C s t �tj| ��� S )z�Return a negation of the given clause, i.e. ``NOT(clause)``. The ``~`` operator is also overloaded on all :class:`_expression.ColumnElement` subclasses to produce the same result. )r rV r rW � __invert__r` rB rB rC ra � s z Optional[str]z!Optional[_TypeEngineArgument[_T]]z#Union[bool, Literal[_NoArg.NO_ARG]]zOptional[bool]zOptional[Callable[[], Any]])rY �valuerZ r[ �required�quote� callable_� expandingr\ �literal_executer@ c C s t | ||||||||| � S )a'