관리-도구
편집 파일: hstore.cpython-311.pyc
� �܋f�0 � �: � d dl Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z d Ze j e j Z e j d edd�� � Z e j d edd�� � Z e j dedd�� � Z e j dedd�� � Z e j dedd�� � Z e j dedd�� � Z G d� dej ej ej � � Z G d� de j � � Z G d� de j � � Z G d� de j � � Z G d� de j � � Z G d� de j � � Z G d� de j � � Z G d � d!e j � � Z! G d"� d#e j � � Z" e j# d$e j$ � � Z% e j# d%e j$ � � Z&d&� Z'd'� Z(d(� Z)dS ))� N� )�ARRAY� )�types)�util)� functions)� operators)�HSTORE�hstorez->T)� precedence�natural_self_precedent�eager_grouping�?z?&z?|z@>z<@c � � e Zd ZdZd ZdZ ej � � Zd d�Z G d� dej j ej j � � ZeZ d� Zd� ZdS ) r at 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`. 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 � � |� || _ dS dS )z�Construct a new :class:`.HSTORE`. :param text_type: the type that should be used for indexed values. Defaults to :class:`_types.Text`. .. versionadded:: 1.1.0 N)� text_type)�selfr s �\/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/dialects/postgresql/hstore.py�__init__zHSTORE.__init__� s � � � �&�D�N�N�N� !� � c �` � e Zd ZdZd� Zd� Zd� Zd� Zd� Zd� Z d� Z d � Zd � Zd� Z d� Zd � Zd� ZdS )�HSTORE.Comparatorz2Define comparison operations for :class:`.HSTORE`.c �P � | � t |t j �� � S )zvBoolean expression. Test for presence of a key. Note that the key may be a SQLA expression. ��result_type)�operate�HAS_KEY�sqltypes�Boolean�r �others r �has_keyzHSTORE.Comparator.has_key� s � � �<�<���H�<L�<�M�M�Mr c �P � | � t |t j �� � S )z;Boolean expression. Test for presence of all keys in jsonbr )r �HAS_ALLr r r s r �has_allzHSTORE.Comparator.has_all� � � ��<�<���H�<L�<�M�M�Mr c �P � | � t |t j �� � S )z:Boolean expression. Test for presence of any key in jsonbr )r �HAS_ANYr r r s r �has_anyzHSTORE.Comparator.has_any� r&