/
opt
/
alt
/
python27
/
lib64
/
python2.7
/
site-packages
/
sqlalchemy
/
dialects
/
mssql
/
up file
home
� 1��fc @ s� d d l m Z d e j f d � � YZ d e f d � � YZ d e e j j f d � � YZ d e e j j f d � � YZ d S( i ( t typest JSONc B s e Z d Z RS( s� MSSQL JSON type. MSSQL supports JSON-formatted data as of SQL Server 2016. The :class:`_mssql.JSON` datatype at the DDL level will represent the datatype as ``NVARCHAR(max)``, but provides for JSON-level comparison functions as well as Python coercion behavior. :class:`_mssql.JSON` is used automatically whenever the base :class:`_types.JSON` datatype is used against a SQL Server backend. .. seealso:: :class:`_types.JSON` - main documentation for the generic cross-platform JSON datatype. The :class:`_mssql.JSON` type supports persistence of JSON values as well as the core index operations provided by :class:`_types.JSON` datatype, by adapting the operations to render the ``JSON_VALUE`` or ``JSON_QUERY`` functions at the database level. The SQL Server :class:`_mssql.JSON` type necessarily makes use of the ``JSON_QUERY`` and ``JSON_VALUE`` functions when querying for elements of a JSON object. These two functions have a major restriction in that they are **mutually exclusive** based on the type of object to be returned. The ``JSON_QUERY`` function **only** returns a JSON dictionary or list, but not an individual string, numeric, or boolean element; the ``JSON_VALUE`` function **only** returns an individual string, numeric, or boolean element. **both functions either return NULL or raise an error if they are not used against the correct expected value**. To handle this awkward requirement, indexed access rules are as follows: 1. When extracting a sub element from a JSON that is itself a JSON dictionary or list, the :meth:`_types.JSON.Comparator.as_json` accessor should be used:: stmt = select( data_table.c.data["some key"].as_json() ).where( data_table.c.data["some key"].as_json() == {"sub": "structure"} ) 2. When extracting a sub element from a JSON that is a plain boolean, string, integer, or float, use the appropriate method among :meth:`_types.JSON.Comparator.as_boolean`, :meth:`_types.JSON.Comparator.as_string`, :meth:`_types.JSON.Comparator.as_integer`, :meth:`_types.JSON.Comparator.as_float`:: stmt = select( data_table.c.data["some key"].as_string() ).where( data_table.c.data["some key"].as_string() == "some string" ) .. versionadded:: 1.4 ( t __name__t __module__t __doc__( ( ( sQ /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/json.pyR s <t _FormatTypeMixinc B s# e Z d � Z d � Z d � Z RS( c C s t � � d S( N( t NotImplementedError( t selft value( ( sQ /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/json.pyt _format_valueW s c s% � j | � � � � f d � } | S( Nc s( � j | � } � r$ � | � } n | S( N( R ( R ( R t super_proc( sQ /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/json.pyt process] s ( t string_bind_processor( R t dialectR ( ( R R sQ /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/json.pyt bind_processorZ s c s% � j | � � � � f d � } | S( Nc s( � j | � } � r$ � | � } n | S( N( R ( R ( R R ( sQ /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/json.pyR h s ( t string_literal_processor( R R R ( ( R R sQ /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/json.pyt literal_processore s ( R R R R R ( ( ( sQ /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/json.pyR V s t JSONIndexTypec B s e Z d � Z RS( c C s* t | t � r d | } n d | } | S( Ns $[%s]s $."%s"( t isinstancet int( R R ( ( sQ /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/json.pyR r s ( R R R ( ( ( sQ /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/json.pyR q s t JSONPathTypec B s e Z d � Z RS( c C sA d d j g | D]) } t | t � r/ d | n d | ^ q � S( Ns $%st s [%s]s ."%s"( t joinR R ( R R t elem( ( sQ /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/json.pyR { s ( R R R ( ( ( sQ /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/json.pyR z s N( R R t sqltypesR t objectR R R ( ( ( sQ /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/json.pyt <module> s E