o
    y¬´\¶'  ã                   @   sä   d dl mZ d dl mZ ddlmZ ddlmZ ddlmZ zddl	m
Z W n ey1   d	ZY nw ejfd
d„Zejfdd„ZG dd„ dejƒZejddd�Zejddd�Zejddd�ZG dd„ dejƒZeeej< eed< d	S )é   )Úcolspecs)Úischema_namesé   )Útypes)Ú
expression)Ú	operatorsé    )ÚUUIDNc                 C   ó   |  | |¡S )zµA synonym for the :meth:`.ARRAY.Comparator.any` method.

    This method is legacy and is here for backwards-compatibility.

    .. seealso::

        :func:`.expression.any_`

    )Úany©ÚotherÚarrexprÚoperator© r   úV/var/www/html/env/lib/python3.10/site-packages/sqlalchemy/dialects/postgresql/array.pyÚAny   ó   r   c                 C   r
   )zµA synonym for the :meth:`.ARRAY.Comparator.all` method.

    This method is legacy and is here for backwards-compatibility.

    .. seealso::

        :func:`.expression.all_`

    )Úallr   r   r   r   ÚAll"   r   r   c                       s8   e Zd ZdZd Z‡ fdd„Zd
dd„Zddd	„Z‡  ZS )Úarrayab  A PostgreSQL ARRAY literal.

    This is used to produce ARRAY literals in SQL expressions, e.g.::

        from sqlalchemy.dialects.postgresql import array
        from sqlalchemy.dialects import postgresql
        from sqlalchemy import select, func

        stmt = select([
                        array([1,2]) + array([3,4,5])
                    ])

        print stmt.compile(dialect=postgresql.dialect())

    Produces the SQL::

        SELECT ARRAY[%(param_1)s, %(param_2)s] ||
            ARRAY[%(param_3)s, %(param_4)s, %(param_5)s]) AS anon_1

    An instance of :class:`.array` will always have the datatype
    :class:`.ARRAY`.  The "inner" type of the array is inferred from
    the values present, unless the ``type_`` keyword argument is passed::

        array(['foo', 'bar'], type_=CHAR)

    .. seealso::

        :class:`.postgresql.ARRAY`

    c                    s&   t t| ƒj|i |¤Ž t| jƒ| _d S ©N)Úsuperr   Ú__init__ÚARRAYÚtype)ÚselfÚclausesÚkw©Ú	__class__r   r   r   S   s   zarray.__init__FNc                    sN   |sˆ t ju rt|tƒsJ ‚tjd |ˆ ˆˆjdd�S t‡ ‡‡fdd„|D ƒƒS )NT)Ú_compared_to_operatorÚtype_Ú_compared_to_typeÚuniquec                    s   g | ]}ˆj ˆ |d ˆd�‘qS )T)Ú_assume_scalarr"   )Ú_bind_param)Ú.0Úo©r   r   r"   r   r   Ú
<listcomp>g   s    ýÿÿz%array._bind_param.<locals>.<listcomp>)r   ÚgetitemÚ
isinstanceÚintr   ÚBindParameterr   r   )r   r   Úobjr%   r"   r   r)   r   r&   W   s   ú
üÿzarray._bind_paramc                 C   s"   |t jt jt jfv rt | ¡S | S r   )r   Úany_opÚall_opr+   r   ÚGrouping)r   Úagainstr   r   r   Ú
self_groupo   s   
zarray.self_group)FNr   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__visit_name__r   r&   r4   Ú__classcell__r   r   r   r   r   0   s    
r   z@>é   )Ú
precedencez<@z&&c                   @   sl   e Zd ZdZG dd„ dejjƒZeZ	ddd„Ze	dd	„ ƒZ
e	d
d„ ƒZdd„ Zdd„ Zdd„ Zdd„ ZdS )r   a–  PostgreSQL ARRAY type.

    .. versionchanged:: 1.1 The :class:`.postgresql.ARRAY` type is now
       a subclass of the core :class:`.types.ARRAY` type.

    The :class:`.postgresql.ARRAY` type is constructed in the same way
    as the core :class:`.types.ARRAY` type; a member type is required, and a
    number of dimensions is recommended if the type is to be used for more
    than one dimension::

        from sqlalchemy.dialects import postgresql

        mytable = Table("mytable", metadata,
                Column("data", postgresql.ARRAY(Integer, dimensions=2))
            )

    The :class:`.postgresql.ARRAY` type provides all operations defined on the
    core :class:`.types.ARRAY` type, including support for "dimensions",
    indexed access, and simple matching such as
    :meth:`.types.ARRAY.Comparator.any` and
    :meth:`.types.ARRAY.Comparator.all`.  :class:`.postgresql.ARRAY` class also
    provides PostgreSQL-specific methods for containment operations, including
    :meth:`.postgresql.ARRAY.Comparator.contains`
    :meth:`.postgresql.ARRAY.Comparator.contained_by`, and
    :meth:`.postgresql.ARRAY.Comparator.overlap`, e.g.::

        mytable.c.data.contains([1, 2])

    The :class:`.postgresql.ARRAY` type may not be supported on all
    PostgreSQL DBAPIs; it is currently known to work on psycopg2 only.

    Additionally, the :class:`.postgresql.ARRAY` type does not work directly in
    conjunction with the :class:`.ENUM` type.  For a workaround, see the
    special type at :ref:`postgresql_array_of_enum`.

    .. seealso::

        :class:`.types.ARRAY` - base array type

        :class:`.postgresql.array` - produces a literal array value.

    c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	zARRAY.Comparatora$  Define comparison operations for :class:`.ARRAY`.

        Note that these operations are in addition to those provided
        by the base :class:`.types.ARRAY.Comparator` class, including
        :meth:`.types.ARRAY.Comparator.any` and
        :meth:`.types.ARRAY.Comparator.all`.

        c                 K   ó   | j t|tjd�S )zBoolean expression.  Test if elements are a superset of the
            elements of the argument array expression.
            ©Úresult_type)ÚoperateÚCONTAINSÚsqltypesÚBoolean)r   r   Úkwargsr   r   r   Úcontainsµ   ó   zARRAY.Comparator.containsc                 C   r=   )z„Boolean expression.  Test if elements are a proper subset of the
            elements of the argument array expression.
            r>   )r@   ÚCONTAINED_BYrB   rC   ©r   r   r   r   r   Úcontained_by»   s   ÿzARRAY.Comparator.contained_byc                 C   r=   )zuBoolean expression.  Test if array has elements in common with
            an argument array expression.
            r>   )r@   ÚOVERLAPrB   rC   rH   r   r   r   ÚoverlapÃ   rF   zARRAY.Comparator.overlapN)r5   r6   r7   r8   rE   rI   rK   r   r   r   r   Ú
Comparatorª   s
    	rL   FNc                 C   s>   t |tƒr	tdƒ‚t |tƒr|ƒ }|| _|| _|| _|| _dS )aP  Construct an ARRAY.

        E.g.::

          Column('myarray', ARRAY(Integer))

        Arguments are:

        :param item_type: The data type of items of this array. Note that
          dimensionality is irrelevant here, so multi-dimensional arrays like
          ``INTEGER[][]``, are constructed as ``ARRAY(Integer)``, not as
          ``ARRAY(ARRAY(Integer))`` or such.

        :param as_tuple=False: Specify whether return results
          should be converted to tuples from lists. DBAPIs such
          as psycopg2 return lists by default. When tuples are
          returned, the results are hashable.

        :param dimensions: if non-None, the ARRAY will assume a fixed
         number of dimensions.  This will cause the DDL emitted for this
         ARRAY to include the exact number of bracket clauses ``[]``,
         and will also optimize the performance of the type overall.
         Note that PG arrays are always implicitly "non-dimensioned",
         meaning they can store any number of dimensions no matter how
         they were declared.

        :param zero_indexes=False: when True, index values will be converted
         between Python zero-based and PostgreSQL one-based indexes, e.g.
         a value of one will be added to all index values before passing
         to the database.

         .. versionadded:: 0.9.5


        zUDo not nest ARRAY types; ARRAY(basetype) handles multi-dimensional arrays of basetypeN)r,   r   Ú
ValueErrorr   Ú	item_typeÚas_tupleÚ
dimensionsÚzero_indexes)r   rN   rO   rP   rQ   r   r   r   r   Ë   s   
&ÿ

zARRAY.__init__c                 C   s   | j S r   )rO   ©r   r   r   r   Úhashableý   s   zARRAY.hashablec                 C   s   t S r   )ÚlistrR   r   r   r   Úpython_type  s   zARRAY.python_typec                 C   s   ||kS r   r   )r   ÚxÚyr   r   r   Úcompare_values  s   zARRAY.compare_valuesc                    st   ˆd u rt |ƒ}ˆdksˆd u r,|rt|d t tfƒs,ˆr(ˆ ‡fdd„|D ƒƒS ˆ |ƒS ˆ ‡ ‡‡‡fdd„|D ƒƒS )Nr   r   c                 3   s   � | ]}ˆ |ƒV  qd S r   r   ©r'   rV   )Úitemprocr   r   Ú	<genexpr>  s   € z$ARRAY._proc_array.<locals>.<genexpr>c                 3   s0   � | ]}ˆ  |ˆˆd urˆd nd ˆ ¡V  qd S )Nr   )Ú_proc_arrayrY   ©Ú
collectionÚdimrZ   r   r   r   r[     s   € úü
ÿ)rT   r,   Útuple)r   ÚarrrZ   r_   r^   r   r]   r   r\     s   ûú	ùzARRAY._proc_arrayc                    s$   ˆj  |¡ |¡‰ ‡ ‡fdd„}|S )Nc                    s   | d u r| S ˆ  | ˆ ˆjt¡S r   )r\   rP   rT   ©Úvalue©Ú	item_procr   r   r   Úprocess*  s
   
ÿz%ARRAY.bind_processor.<locals>.process)rN   Údialect_implÚbind_processor)r   Údialectrf   r   rd   r   rh   %  s
   ÿzARRAY.bind_processorc                    s&   ˆj  |¡ ||¡‰ ‡ ‡fdd„}|S )Nc                    s*   | d u r| S ˆ  | ˆ ˆjˆjrt¡S t¡S r   )r\   rP   rO   r`   rT   rb   rd   r   r   rf   9  s   üüz'ARRAY.result_processor.<locals>.process)rN   rg   Úresult_processor)r   ri   Úcoltyperf   r   rd   r   rj   4  s
   ÿzARRAY.result_processor)FNF)r5   r6   r7   r8   rB   r   rL   Úcomparator_factoryr   ÚpropertyrS   rU   rX   r\   rh   rj   r   r   r   r   r   }   s    +
ÿ2

r   Ú_array)Úbaser   r   Ú r   rB   Úsqlr   r   Úuuidr	   Ú_python_UUIDÚImportErrorÚeqr   r   ÚTupler   Ú	custom_oprA   rG   rJ   r   r   r   r   r   Ú<module>   s(   ÿF 
K