Repository URL to install this package:
Version:
4.0.108 ▾
|
contego
/
home
/
tvault
/
.virtenv
/
lib
/
python2.7
/
site-packages
/
sqlalchemy
/
dialects
/
postgresql
/
json.pyc
|
---|
ó EYc @@ sè d d l m Z d d l 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 m Z d d l m Z d Z d e j f d YZ d e j f d YZ e e d <d e f d YZ e e d <d S( i ( t absolute_importNi ( t ischema_namesi ( t types( t custom_op( t sql( t elementst default_comparator( t utilt JSONt JSONElementt JSONBc B@ s8 e Z d Z e d d d Z e d Z d Z RS( sË Represents accessing an element of a :class:`.JSON` value. The :class:`.JSONElement` is produced whenever using the Python index operator on an expression that has the type :class:`.JSON`:: expr = mytable.c.json_data['some_key'] The expression typically compiles to a JSON access such as ``col -> key``. Modifiers are then available for typing behavior, including :meth:`.JSONElement.cast` and :attr:`.JSONElement.astext`. c C@ s¼ | | _ | d k rf t | d r] t | t j r] d } d d j d | D } qf d } n | | _ t | d d } t j | | | } t t | j | | | d | d S( Nt __iter__s #>s {%s}s , c s@ s | ] } t j | Vq d S( N( R t text_type( t .0t elem( ( sX /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/json.pys <genexpr>+ s s ->t precedencei t type_( t _astextt Nonet hasattrt isinstanceR t string_typest joint _json_opstringR R t _check_literalt superR t __init__( t selft leftt rightt astextt opstringt result_typet operator( ( sX /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/json.pyR # s c C@ sI | j r | St | j | j d t d | j d d t j d t Sd S( sê Convert this :class:`.JSONElement` to use the 'astext' operator when evaluated. E.g.:: select([data_table.c.data['some key'].astext]) .. seealso:: :meth:`.JSONElement.cast` R R t >R t convert_unicodeN( R R R R t TrueR t sqltypest String( R ( ( sX /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/json.pyR 6 s c C@ s- | j s | j j | St j | | Sd S( s Convert this :class:`.JSONElement` to apply both the 'astext' operator as well as an explicit type cast when evaluated. E.g.:: select([data_table.c.data['some key'].cast(Integer)]) .. seealso:: :attr:`.JSONElement.astext` N( R R t castR ( R R ( ( sX /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/json.pyR' O s N( t __name__t __module__t __doc__t FalseR R t propertyR R' ( ( ( sX /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/json.pyR s c B@ sN e Z d Z d Z e d Z d e j j f d YZ d Z d Z RS( s Represent the Postgresql JSON type. The :class:`.JSON` type stores arbitrary JSON format data, e.g.:: data_table = Table('data_table', metadata, Column('id', Integer, primary_key=True), Column('data', JSON) ) with engine.connect() as conn: conn.execute( data_table.insert(), data = {"key1": "value1", "key2": "value2"} ) :class:`.JSON` provides several operations: * Index operations:: data_table.c.data['some key'] * Index operations returning text (required for text comparison):: data_table.c.data['some key'].astext == 'some value' * Index operations with a built-in CAST call:: data_table.c.data['some key'].cast(Integer) == 5 * Path index operations:: data_table.c.data[('key_1', 'key_2', ..., 'key_n')] * Path index operations returning text (required for text comparison):: data_table.c.data[('key_1', 'key_2', ..., 'key_n')].astext == \ 'some value' Index operations return an instance of :class:`.JSONElement`, which represents an expression such as ``column -> index``. This element then defines methods such as :attr:`.JSONElement.astext` and :meth:`.JSONElement.cast` for setting up type behavior. The :class:`.JSON` type, when used with the SQLAlchemy ORM, does not detect in-place mutations to the structure. In order to detect these, the :mod:`sqlalchemy.ext.mutable` extension must be used. This extension will allow "in-place" changes to the datastructure to produce events which will be detected by the unit of work. See the example at :class:`.HSTORE` for a simple example involving a dictionary. Custom serializers and deserializers are specified at the dialect level, that is using :func:`.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``. .. versionadded:: 0.9 R c C@ s | | _ d S( s Construct a :class:`.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. N( t none_as_null( R R- ( ( sX /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/json.pyR ¨ s t comparator_factoryc B@ s e Z d Z d Z d Z RS( s0 Define comparison operations for :class:`.JSON`.c C@ s t | j | S( s Get the value at a given key.( R t expr( R t other( ( sX /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/json.pyt __getitem__¼ s c C@ sG t | t r. | j d k r. | t j f Sn t j j j | | | S( Ns ->( R R R R% t Textt Concatenablet Comparatort _adapt_expression( R t opt other_comparator( ( sX /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/json.pyR5 Á s ( R( R) R* R1 R5 ( ( ( sX /home/tvault/.virtenv/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/json.pyR. ¹ s c @ sR | j p t j t j r<