
    ,h*2                       S SK Jr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  SS	K	J
r
  SS
K	J	r  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  \(       a  SSKJr  SSK J!r!  SSK"J#r#  SSK"J$r$  SSK"J%r%  Sr& " S S \RN                  RP                  5      r( " S! S"\(5      r) " S# S$\RN                  5      r' " S% S&\'5      r*g')(    )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                  F    \ rS rSr      SS jrSS jr    S	S jrSrg)
JSONPathType+   c                   ^ SU4S jjnU$ )Nc                   > [        U [        5      (       a  U $ U (       a#  SSR                  [        [        U 5      5      -  n OSn T(       a  T" U 5      n U $ )Nz{%s}z, z{})
isinstancestrjoinmap)value
super_procs    [/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/dialects/postgresql/json.pyprocess(JSONPathType._processor.<locals>.process/   sL    %%%  $))CUO"<="5)L    )r+   r   returnr    )selfdialectr,   r.   s     ` r-   
_processorJSONPathType._processor,   s    	 r0   c                B    U R                  XR                  U5      5      $ N)r5   string_bind_processorr3   r4   s     r-   bind_processorJSONPathType.bind_processor@   s    w(B(B7(KLLr0   c                B    U R                  XR                  U5      5      $ r8   )r5   string_literal_processorr:   s     r-   literal_processorJSONPathType.literal_processorC   s     w(E(Eg(NOOr0   r2   N)r4   r   r,   zOptional[Callable[[Any], Any]]r1   zCallable[[Any], Any])r4   r   r1   z_BindProcessorType[Any])r4   r   r1   z_LiteralProcessorType[Any])__name__
__module____qualname____firstlineno__r5   r;   r?   __static_attributes__r2   r0   r-   r#   r#   +   s=    ,J	(MPP	#Pr0   r#   c                      \ rS rSrSrS rSrg)JSONPATHI   a@  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)
        )
    )

r2   N)rA   rB   rC   rD   __doc____visit_name__rE   r2   r0   r-   rG   rG   I   s      Nr0   rG   c                     ^  \ rS rSr% SrSr\R                  " 5       rS\	S'     S
   SU 4S jjjr
 " S S\R                  R                  \   5      r\rS	rU =r$ )r    [   aB	  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_typec                4   > [         TU ]  US9  Ub  X l        gg)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`.

)none_as_nullN)super__init__rM   )r3   rO   rM   	__class__s      r-   rQ   JSON.__init__   s&    2 	l3"* #r0   c                  8    \ rS rSr% SrS\S'   \SS j5       rSrg)	JSON.Comparator   6Define comparison operations for :class:`_types.JSON`.r    typec                   [        U R                  R                  R                  [        R
                  R                  5      (       aQ  U R                  R                  R                  [        U R                  R                  U R                  R                  S9$ U R                  R                  R                  [        U R                  R                  U R                  R                  S9$ )zOn 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rightrX   sqltypesr    r#   leftoperater   rM   r   )r3   s    r-   astextJSON.Comparator.astext   s     $))//..0J0JKKyy~~--#IIOO $		 5 5 .   yy~~--DIIOO9N9N .  r0   r2   N)r1   zColumnElement[str])	rA   rB   rC   rD   rI   __annotations__propertyra   rE   r2   r0   r-   
ComparatorrU      s    D
		 
	r0   re   )rM   )FN)rO   boolrM   zOptional[TypeEngine[str]])rA   rB   rC   rD   rI   render_bind_castr^   TextrM   rc   rQ   r    re   r   comparator_factoryrE   __classcell__)rR   s   @r-   r    r    [   si    KZ #+==?K2 #15++ /+ +:X]]--b1 < $r0   r    c                  P    \ rS rSrSrS r " S S\R                  \   5      r\r	Sr
g)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                  |    \ rS rSr% SrS\S'   SS jrSS jrSS jrSS jr	SS	 jr
    SS
 jrSS jrSS jrSrg)JSONB.Comparatori  rW   r!   rX   c                H    U R                  [        U[        R                  S9$ )zBoolean expression.  Test for presence of a key (equivalent of
the ``?`` operator).  Note that the key may be a SQLA expression.
rZ   )r`   r   r^   Booleanr3   others     r-   has_keyJSONB.Comparator.has_key#       <<H<L<L<MMr0   c                H    U R                  [        U[        R                  S9$ )z`Boolean expression.  Test for presence of all keys in jsonb
(equivalent of the ``?&`` operator)
rZ   )r`   r   r^   rp   rq   s     r-   has_allJSONB.Comparator.has_all)  ru   r0   c                H    U R                  [        U[        R                  S9$ )z_Boolean expression.  Test for presence of any key in jsonb
(equivalent of the ``?|`` operator)
rZ   )r`   r   r^   rp   rq   s     r-   has_anyJSONB.Comparator.has_any/  ru   r0   c                H    U R                  [        U[        R                  S9$ )zBoolean 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.
rZ   )r`   r   r^   rp   )r3   rr   kwargss      r-   containsJSONB.Comparator.contains5  s     <<%X=M=M<NNr0   c                H    U R                  [        U[        R                  S9$ )zBoolean expression.  Test if keys are a proper subset of the
keys of the argument jsonb expression
(equivalent of the ``<@`` operator).
rZ   )r`   r   r^   rp   rq   s     r-   contained_byJSONB.Comparator.contained_by?  s'    
 <<e1A1A    r0   c                    [        U[        5      (       d  [        U5      n[        U[        [        R
                  5      5      nU R                  [        U[        S9$ )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
rZ   )	r'   	_pg_arrayr   r   r^   TEXTr`   r   r!   )r3   r   
right_sides      r-   delete_pathJSONB.Comparator.delete_pathH  sE     eY//!%(eU8==%9:J<<ZU<KKr0   c                H    U R                  [        U[        R                  S9$ )zBoolean expression. Test for presence of item given by the
argument JSONPath expression (equivalent of the ``@?`` operator).

.. versionadded:: 2.0
rZ   )r`   r   r^   rp   rq   s     r-   path_existsJSONB.Comparator.path_existsX  s'     <<U0@0@    r0   c                H    U R                  [        U[        R                  S9$ )zBoolean 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
rZ   )r`   r   r^   rp   rq   s     r-   
path_matchJSONB.Comparator.path_matchb  s'     <<Ex/?/?    r0   r2   N)rr   r   r1   ColumnElement[bool])rr   r   r}   r   r1   r   )r   z Union[List[str], _pg_array[str]]r1   zColumnElement[JSONB])rA   rB   rC   rD   rI   rc   rs   rw   rz   r~   r   r   r   r   rE   r2   r0   r-   re   rn     sI    D	N	N	N	O		L9	L!	L 		r0   re   r2   N)rA   rB   rC   rD   rI   rJ   r    re   r   ri   rE   r2   r0   r-   r!   r!      s/    /b NOT__R( Ob $r0   r!   N)+
__future__r   typingr   r   r   r   r   r	   r   r   r   	operatorsr   r   r   r   r   r   r   r   r   r    r   r^   sqlr   sql._typingr   engine.interfacesr   sql.elementsr   sql.type_apir   r   r   __all__r    r#   rG   r!   r2   r0   r-   <module>r      s    #         %  #  "    & " ! !  ,-25*
P8==-- P< |  $L$8== L$^E$D E$r0   