
    [h*2                       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 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 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 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 ddlmZ ddlmZ er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% dZ& G d d ej'        j(                  Z( G d! d"e(          Z) G d# d$ej'                  Z' G d% d&e'          Z*d'S )(    )annotations)Any)Callable)List)Optional)TYPE_CHECKING)Union   )ARRAY)array)ASTEXT)CONTAINED_BY)CONTAINS)DELETE_PATH)HAS_ALL)HAS_ANY)HAS_KEY)JSONPATH_ASTEXT)PATH_EXISTS)
PATH_MATCH   )types)cast)_T)Dialect)ColumnElement)_BindProcessorType)_LiteralProcessorType)
TypeEngine)JSONJSONBc                  &    e Zd ZddZdd	ZddZdS )JSONPathTypedialectr   
super_procOptional[Callable[[Any], Any]]returnCallable[[Any], Any]c                    dfd}|S )Nvaluer   r'   c                    t          | t                    r| S | r,dd                    t          t          |                     z  } nd} r |           } | S )Nz{%s}z, z{})
isinstancestrjoinmap)r*   r%   s    r/var/www/api.easyaligner.net/htdocs/venv_linux/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/json.pyprocessz(JSONPathType._processor.<locals>.process/   sg    %%% 	   $))CUOO"<"<= *"
5))L    )r*   r   r'   r    )selfr$   r%   r1   s     ` r0   
_processorzJSONPathType._processor,   s(    	 	 	 	 	 	 r2   _BindProcessorType[Any]c                T    |                      ||                     |                    S N)r5   string_bind_processorr4   r$   s     r0   bind_processorzJSONPathType.bind_processor@   s$    w(B(B7(K(KLLLr2   _LiteralProcessorType[Any]c                T    |                      ||                     |                    S r8   )r5   string_literal_processorr:   s     r0   literal_processorzJSONPathType.literal_processorC   s&     w(E(Eg(N(NOOOr2   N)r$   r   r%   r&   r'   r(   )r$   r   r'   r6   )r$   r   r'   r<   )__name__
__module____qualname__r5   r;   r?   r3   r2   r0   r#   r#   +   sZ           (M M M MP P P P P Pr2   r#   c                      e Zd ZdZd ZdS )JSONPATHad  JSON Path Type.

    This is usually required to cast literal values to json path when using
    json search like function, such as ``jsonb_path_query_array`` or
    ``jsonb_path_exists``::

        stmt = sa.select(
            sa.func.jsonb_path_query_array(
                table.c.jsonb_col, cast("$.address.id", JSONPATH)
            )
        )

    N)r@   rA   rB   __doc____visit_name__r3   r2   r0   rD   rD   I   s           NNNr2   rD   c                       e Zd ZU dZdZ ej                    Zded<   	 	 dd fd
Z	 G d dej
        j        e                   ZeZ xZS )r    a

  Represent the PostgreSQL JSON type.

    :class:`_postgresql.JSON` is used automatically whenever the base
    :class:`_types.JSON` datatype is used against a PostgreSQL backend,
    however base :class:`_types.JSON` datatype does not provide Python
    accessors for PostgreSQL-specific comparison methods such as
    :meth:`_postgresql.JSON.Comparator.astext`; additionally, to use
    PostgreSQL ``JSONB``, the :class:`_postgresql.JSONB` datatype should
    be used explicitly.

    .. seealso::

        :class:`_types.JSON` - main documentation for the generic
        cross-platform JSON datatype.

    The operators provided by the PostgreSQL version of :class:`_types.JSON`
    include:

    * Index operations (the ``->`` operator)::

        data_table.c.data["some key"]

        data_table.c.data[5]

    * Index operations returning text
      (the ``->>`` operator)::

        data_table.c.data["some key"].astext == "some value"

      Note that equivalent functionality is available via the
      :attr:`.JSON.Comparator.as_string` accessor.

    * Index operations with CAST
      (equivalent to ``CAST(col ->> ['some key'] AS <type>)``)::

        data_table.c.data["some key"].astext.cast(Integer) == 5

      Note that equivalent functionality is available via the
      :attr:`.JSON.Comparator.as_integer` and similar accessors.

    * Path index operations (the ``#>`` operator)::

        data_table.c.data[("key_1", "key_2", 5, ..., "key_n")]

    * Path index operations returning text (the ``#>>`` operator)::

        data_table.c.data[
            ("key_1", "key_2", 5, ..., "key_n")
        ].astext == "some value"

    Index operations return an expression object whose type defaults to
    :class:`_types.JSON` by default,
    so that further JSON-oriented instructions
    may be called upon the result type.

    Custom serializers and deserializers are specified at the dialect level,
    that is using :func:`_sa.create_engine`.  The reason for this is that when
    using psycopg2, the DBAPI only allows serializers at the per-cursor
    or per-connection level.   E.g.::

        engine = create_engine(
            "postgresql+psycopg2://scott:tiger@localhost/test",
            json_serializer=my_serialize_fn,
            json_deserializer=my_deserialize_fn,
        )

    When using the psycopg2 dialect, the json_deserializer is registered
    against the database using ``psycopg2.extras.register_default_json``.

    .. seealso::

        :class:`_types.JSON` - Core level JSON type

        :class:`_postgresql.JSONB`

    TzTypeEngine[str]astext_typeFNnone_as_nullboolOptional[TypeEngine[str]]c                b    t                                          |           |	|| _        dS dS )a  Construct a :class:`_types.JSON` type.

        :param none_as_null: if True, persist the value ``None`` as a
         SQL NULL value, not the JSON encoding of ``null``.   Note that
         when this flag is False, the :func:`.null` construct can still
         be used to persist a NULL value::

             from sqlalchemy import null

             conn.execute(table.insert(), {"data": null()})

         .. seealso::

              :attr:`_types.JSON.NULL`

        :param astext_type: the type to use for the
         :attr:`.JSON.Comparator.astext`
         accessor on indexed attributes.  Defaults to :class:`_types.Text`.

        )rI   N)super__init__rH   )r4   rI   rH   	__class__s      r0   rN   zJSON.__init__   s<    2 	l333"*D #"r2   c                  6    e Zd ZU dZded<   edd            ZdS )	JSON.Comparator6Define comparison operations for :class:`_types.JSON`.r    typer'   ColumnElement[str]c                J   t          | j        j        j        t          j        j                  r;| j        j                            t          | j        j        | j        j
                  S | j        j                            t          | j        j        | j        j
                  S )a  On an indexed expression, use the "astext" (e.g. "->>")
            conversion when rendered in SQL.

            E.g.::

                select(data_table.c.data["some key"].astext)

            .. seealso::

                :meth:`_expression.ColumnElement.cast`

            result_type)r,   exprrightrS   sqltypesr    r#   leftoperater   rH   r   )r4   s    r0   astextzJSON.Comparator.astext   s     $)/.0JKK 	y~--#IO $	 5 .    y~--DIO9N .   r2   N)r'   rT   )r@   rA   rB   rE   __annotations__propertyr]   r3   r2   r0   
ComparatorrQ      sC         DD


		 	 	 
	 	 	r2   r`   )FN)rI   rJ   rH   rK   )r@   rA   rB   rE   render_bind_castrZ   TextrH   r^   rN   r    r`   r   comparator_factory__classcell__)rO   s   @r0   r    r    [   s         K KZ #08=??K2222 #15+ + + + + + +:    X]-b1   < $r2   r    c                  L    e Zd ZdZd Z G d dej        e                   ZeZdS )r!   a  Represent the PostgreSQL JSONB type.

    The :class:`_postgresql.JSONB` type stores arbitrary JSONB format data,
    e.g.::

        data_table = Table(
            "data_table",
            metadata,
            Column("id", Integer, primary_key=True),
            Column("data", JSONB),
        )

        with engine.connect() as conn:
            conn.execute(
                data_table.insert(), data={"key1": "value1", "key2": "value2"}
            )

    The :class:`_postgresql.JSONB` type includes all operations provided by
    :class:`_types.JSON`, including the same behaviors for indexing
    operations.
    It also adds additional operators specific to JSONB, including
    :meth:`.JSONB.Comparator.has_key`, :meth:`.JSONB.Comparator.has_all`,
    :meth:`.JSONB.Comparator.has_any`, :meth:`.JSONB.Comparator.contains`,
    :meth:`.JSONB.Comparator.contained_by`,
    :meth:`.JSONB.Comparator.delete_path`,
    :meth:`.JSONB.Comparator.path_exists` and
    :meth:`.JSONB.Comparator.path_match`.

    Like the :class:`_types.JSON` type, the :class:`_postgresql.JSONB`
    type does not detect
    in-place changes when used with the ORM, unless the
    :mod:`sqlalchemy.ext.mutable` extension is used.

    Custom serializers and deserializers
    are shared with the :class:`_types.JSON` class,
    using the ``json_serializer``
    and ``json_deserializer`` keyword arguments.  These must be specified
    at the dialect level using :func:`_sa.create_engine`.  When using
    psycopg2, the serializers are associated with the jsonb type using
    ``psycopg2.extras.register_default_jsonb`` on a per-connection basis,
    in the same way that ``psycopg2.extras.register_default_json`` is used
    to register these handlers with the json type.

    .. seealso::

        :class:`_types.JSON`

    c                  ^    e Zd ZU dZded<   ddZdd	Zdd
ZddZddZ	ddZ
ddZddZdS )JSONB.ComparatorrR   r!   rS   otherr   r'   ColumnElement[bool]c                P    |                      t          |t          j                  S )zBoolean expression.  Test for presence of a key (equivalent of
            the ``?`` operator).  Note that the key may be a SQLA expression.
            rV   )r\   r   rZ   Booleanr4   rh   s     r0   has_keyzJSONB.Comparator.has_key#       <<H<L<MMMr2   c                P    |                      t          |t          j                  S )zxBoolean expression.  Test for presence of all keys in jsonb
            (equivalent of the ``?&`` operator)
            rV   )r\   r   rZ   rk   rl   s     r0   has_allzJSONB.Comparator.has_all)  rn   r2   c                P    |                      t          |t          j                  S )zwBoolean expression.  Test for presence of any key in jsonb
            (equivalent of the ``?|`` operator)
            rV   )r\   r   rZ   rk   rl   s     r0   has_anyzJSONB.Comparator.has_any/  rn   r2   kwargsc                P    |                      t          |t          j                  S )a"  Boolean expression.  Test if keys (or array) are a superset
            of/contained the keys of the argument jsonb expression
            (equivalent of the ``@>`` operator).

            kwargs may be ignored by this operator but are required for API
            conformance.
            rV   )r\   r   rZ   rk   )r4   rh   rs   s      r0   containszJSONB.Comparator.contains5  s     <<%X=M<NNNr2   c                P    |                      t          |t          j                  S )zBoolean expression.  Test if keys are a proper subset of the
            keys of the argument jsonb expression
            (equivalent of the ``<@`` operator).
            rV   )r\   r   rZ   rk   rl   s     r0   contained_byzJSONB.Comparator.contained_by?  s)    
 <<e1A     r2   r    Union[List[str], _pg_array[str]]ColumnElement[JSONB]c                    t          |t                    st          |          }t          |t          t          j                            }|                     t          |t                    S )a=  JSONB expression. Deletes field or array element specified in
            the argument array (equivalent of the ``#-`` operator).

            The input may be a list of strings that will be coerced to an
            ``ARRAY`` or an instance of :meth:`_postgres.array`.

            .. versionadded:: 2.0
            rV   )	r,   	_pg_arrayr   r   rZ   TEXTr\   r   r!   )r4   r   
right_sides      r0   delete_pathzJSONB.Comparator.delete_pathH  sT     eY// )!%((eU8=%9%9::J<<ZU<KKKr2   c                P    |                      t          |t          j                  S )zBoolean expression. Test for presence of item given by the
            argument JSONPath expression (equivalent of the ``@?`` operator).

            .. versionadded:: 2.0
            rV   )r\   r   rZ   rk   rl   s     r0   path_existszJSONB.Comparator.path_existsX  s)     <<U0@     r2   c                P    |                      t          |t          j                  S )a  Boolean expression. Test if JSONPath predicate given by the
            argument JSONPath expression matches
            (equivalent of the ``@@`` operator).

            Only the first item of the result is taken into account.

            .. versionadded:: 2.0
            rV   )r\   r   rZ   rk   rl   s     r0   
path_matchzJSONB.Comparator.path_matchb  s)     <<Ex/?     r2   N)rh   r   r'   ri   )rh   r   rs   r   r'   ri   )r   rx   r'   ry   )r@   rA   rB   rE   r^   rm   rp   rr   ru   rw   r~   r   r   r3   r2   r0   r`   rg     s         DD	N 	N 	N 	N	N 	N 	N 	N	N 	N 	N 	N	O 	O 	O 	O	 	 	 		L 	L 	L 	L 	 	 	 		 	 	 	 	 	r2   r`   N)	r@   rA   rB   rE   rF   r    r`   r   rc   r3   r2   r0   r!   r!      sd        / /b NO O O O OT_R( O O Ob $r2   r!   N)+
__future__r   typingr   r   r   r   r   r	   r   r   r{   	operatorsr   r   r   r   r   r   r   r   r   r    r   rZ   sqlr   sql._typingr   engine.interfacesr   sql.elementsr   sql.type_apir   r   r   __all__r    r#   rD   r!   r3   r2   r0   <module>r      s   # " " " " "                                                 % % % % % %       # # # # # #       " " " " " "                   & & & & & & " " " " " " ! ! ! ! ! ! ! ! ! ! ! !             +,,,,,,------222222555555******
P P P P P8=- P P P<         |      $L$ L$ L$ L$ L$8= L$ L$ L$^E$ E$ E$ E$ E$D E$ E$ E$ E$ E$r2   