관리-도구
편집 파일: hstore.cpython-38.pyc
U -?�f- � @ sZ d dl Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd lm Z d dl mZ d dl mZ d ZG dd� dejejej�ZG dd� dej�ZG dd� dej�ZG dd� dej�ZG dd� dej�ZG dd� dej�ZG dd� dej�ZG dd� dej�ZG dd� dej�Ze �d e j�Z e �d!e j�Z!d"d#� Z"d$d%� Z#d&d'� Z$dS )(� N� )�ARRAY)�CONTAINED_BY)�CONTAINS)�GETITEM)�HAS_ALL)�HAS_ANY)�HAS_KEY� )�types)� functions)�HSTORE�hstorec @ sX e Zd ZdZd ZdZe�� Zddd�Z G dd� dej jejj�ZeZ dd � Zd d� ZdS ) r a% Represent the PostgreSQL HSTORE type. The :class:`.HSTORE` type stores dictionaries containing strings, e.g.:: data_table = Table('data_table', metadata, Column('id', Integer, primary_key=True), Column('data', HSTORE) ) with engine.connect() as conn: conn.execute( data_table.insert(), data = {"key1": "value1", "key2": "value2"} ) :class:`.HSTORE` provides for a wide range of operations, including: * Index operations:: data_table.c.data['some key'] == 'some value' * Containment operations:: data_table.c.data.has_key('some key') data_table.c.data.has_all(['one', 'two', 'three']) * Concatenation:: data_table.c.data + {"k1": "v1"} For a full list of special methods see :class:`.HSTORE.comparator_factory`. .. container:: topic **Detecting Changes in HSTORE columns when using the ORM** For usage with the SQLAlchemy ORM, it may be desirable to combine the usage of :class:`.HSTORE` with :class:`.MutableDict` dictionary now part of the :mod:`sqlalchemy.ext.mutable` extension. This extension will allow "in-place" changes to the dictionary, e.g. addition of new keys or replacement/removal of existing keys to/from the current dictionary, to produce events which will be detected by the unit of work:: from sqlalchemy.ext.mutable import MutableDict class MyClass(Base): __tablename__ = 'data_table' id = Column(Integer, primary_key=True) data = Column(MutableDict.as_mutable(HSTORE)) my_object = session.query(MyClass).one() # in-place mutation, requires Mutable extension # in order for the ORM to detect my_object.data['some_key'] = 'some value' session.commit() When the :mod:`sqlalchemy.ext.mutable` extension is not used, the ORM will not be alerted to any changes to the contents of an existing dictionary, unless that dictionary value is re-assigned to the HSTORE-attribute itself, thus generating a change event. .. seealso:: :class:`.hstore` - render the PostgreSQL ``hstore()`` function. FNc C s |dk r|| _ dS )z�Construct a new :class:`.HSTORE`. :param text_type: the type that should be used for indexed values. Defaults to :class:`_types.Text`. N)� text_type)�selfr � r �U/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/dialects/postgresql/hstore.py�__init__i s zHSTORE.__init__c @ sx e Zd ZdZdd� Zdd� Zdd� Zdd � Zd d� Zdd � Z dd� Z dd� Zdd� Zdd� Z dd� Zdd� Zdd� ZdS )zHSTORE.Comparatorz2Define comparison operations for :class:`.HSTORE`.c C s | j t|tjd�S )zvBoolean expression. Test for presence of a key. Note that the key may be a SQLA expression. �Zresult_type)�operater �sqltypes�Boolean�r �otherr r r �has_keyx s zHSTORE.Comparator.has_keyc C s | j t|tjd�S )z;Boolean expression. Test for presence of all keys in jsonbr )r r r r r r r r �has_all~ s zHSTORE.Comparator.has_allc C s | j t|tjd�S )z:Boolean expression. Test for presence of any key in jsonbr )r r r r r r r r �has_any� s zHSTORE.Comparator.has_anyc K s | j t|tjd�S )z�Boolean expression. Test if keys (or array) are a superset of/contained the keys of the argument jsonb expression. kwargs may be ignored by this operator but are required for API conformance. r )r r r r )r r �kwargsr r r �contains� s zHSTORE.Comparator.containsc C s | j t|tjd�S )z|Boolean expression. Test if keys are a proper subset of the keys of the argument jsonb expression. r )r r r r r r r r �contained_by� s �zHSTORE.Comparator.contained_byc C s t || jjfS �N)r �typer )r �indexr r r �_setup_getitem� s z HSTORE.Comparator._setup_getitemc C s t | j|�S )z�Boolean expression. Test for presence of a non-NULL value for the key. Note that the key may be a SQLA expression. )�_HStoreDefinedFunction�expr�r �keyr r r �defined� s zHSTORE.Comparator.definedc C s t |t�rt|�}t| j|�S )z�HStore expression. Returns the contents of this hstore with the given key deleted. Note that the key may be a SQLA expression. )� isinstance�dict�_serialize_hstore�_HStoreDeleteFunctionr% r&