idw'ddlmZddlmZddlmZddlmZdZej ej Z ej de dd Z ej d e dd Zej d e dd Zej d e dd Zej d e dd Zej de dd Zej de dd ZGddejjZGddejZGddeZdS))absolute_import)types)util) operators)JSONJSONBz->>T) precedencenatural_self_precedenteager_groupingz#>>?z?&z?|z@>z<@ceZdZdZdZdS) JSONPathTypec<||fd}|S)Ncjd|D}dd|z}r |}|S)Nc6g|]}tj|Sr text_type.0elems X/opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/json.py z@JSONPathType.bind_processor..process..K"===tdnT**==={%s}, joinvaluetokens super_procs rprocessz,JSONPathType.bind_processor..processIH==u===Fdii//0E *" 5))Lr)string_bind_processorselfdialectr%r$s @rbind_processorzJSONPathType.bind_processorFs6//88      rc<||fd}|S)Ncjd|D}dd|z}r |}|S)Nc6g|]}tj|Srrrs rrzCJSONPathType.literal_processor..process..Xrrrrrr!s rr%z/JSONPathType.literal_processor..processVr&r)string_literal_processorr(s @rliteral_processorzJSONPathType.literal_processorSs6227;;      rN)__name__ __module__ __qualname__r+r0rrrrrEs2        rrcveZdZdZejZdfd ZGddejj Z e Z xZ S)raB Represent the PostgreSQL JSON type. This type is a specialization of the Core-level :class:`_types.JSON` type. Be sure to read the documentation for :class:`_types.JSON` for important tips regarding treatment of NULL values and ORM use. .. versionchanged:: 1.1 :class:`_postgresql.JSON` is now a PostgreSQL- specific specialization of the new :class:`_types.JSON` type. 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 )``):: 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' .. versionchanged:: 1.1 The :meth:`_expression.ColumnElement.cast` operator on JSON objects now requires that the :attr:`.JSON.Comparator.astext` modifier be called explicitly, if the cast works only from a textual string. 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://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` FNcptt||| ||_dSdS)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()) .. versionchanged:: 0.9.8 - Added ``none_as_null``, and :func:`.null` is now supported in order to persist a NULL value. .. 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`. .. versionadded:: 1.1 ) none_as_nullN)superr__init__ astext_type)r)r6r9 __class__s rr8z JSON.__init__sB2 dD"" "===  "*D    # "rc(eZdZdZedZdS)JSON.Comparator6Define comparison operations for :class:`_types.JSON`.cJt|jjjtjjr;|jjt|jj|jj S|jjt|jj|jj S)aOn 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) isinstanceexprrighttypesqltypesrrleftoperateJSONPATH_ASTEXTr9ASTEXT)r)s rastextzJSON.Comparator.astexts$)/. 0JKK y~--#IO $ 5. y~--DIO9N.rN)r1r2r3__doc__propertyrJrrr Comparatorr<s3DD       rrM)FN) r1r2r3rKrETextr9r8rrMcomparator_factory __classcell__)r:s@rrrasHHT (-//K++++++:X]-8$rrc@eZdZdZdZGddejZeZdS)r aRepresent 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`, and :meth:`.JSONB.Comparator.contained_by`. 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. .. versionadded:: 0.9.7 .. seealso:: :class:`_types.JSON` c0eZdZdZdZdZdZdZdZdS)JSONB.Comparatorr=cP|t|tjS)zvBoolean expression. Test for presence of a key. Note that the key may be a SQLA expression. r?)rGHAS_KEYrEBooleanr)others rhas_keyzJSONB.Comparator.has_keys<<H$rr N) __future__rrrErsqlr__all__ _PRECEDENCEjson_getitem_opidx_precedence custom_oprIrHrUr[r_rbrfrrr rrrrqs'&&&&&!!!!!! &y'@A       &)%   )      )      )      9     #y"  8=-8F$F$F$F$F$8=F$F$F$RQ$Q$Q$Q$Q$DQ$Q$Q$Q$Q$r