File: //lib/python3.9/site-packages/redis/commands/graph/__pycache__/commands.cpython-39.pyc
a
��b� � @ sN d dl mZ d dlmZ ddlmZ ddlmZ ddlm Z G dd� d�Z
d S )
� )� DataError)�
ResponseError� )�VersionMismatchException)�
ExecutionPlan)�QueryResultc @ sx e Zd ZdZdd� Zddd�Zdd � Zd
d� Zdd
� Zdd� Z dd� Z
dd� Zddd�Zdd� Z
ddd�Zddd�ZdS ) �
GraphCommandszRedisGraph Commandsc C s� t | j�dkr t | j�dkr dS d}| j�� D ]\}}|t|�d 7 }q.|d�dd� | jD ��7 }|d dkrz|dd� }| �|�S )z&
Create entire graph.
r NzCREATE �,c S s g | ]}t |��qS � )�str)�.0Zedger
r
�A/usr/lib/python3.9/site-packages/redis/commands/graph/commands.py�
<listcomp> � z(GraphCommands.commit.<locals>.<listcomp>���)�len�nodes�edges�itemsr �join�query)�selfr �_Znoder
r
r
�commit s zGraphCommands.commitNFc
C s, |}|dur| � |�| }|r$d}n|r,dnd}|| j|dg}|r`t|t�sTtd��|d|g7 }z| j|� } t| | |�W S ty� }
zRdt|
�v r�t d � d
t|
�v r�|r�| j
|||dd�W Y d}
~
S |
�W Y d}
~
nNd}
~
0 t�y& }
z,|
j| _| �
� | �
||||�W Y d}
~
S d}
~
0 0 dS )
a
Executes a query against the graph.
For more information see `GRAPH.QUERY <https://redis.io/commands/graph.query>`_. # noqa
Args:
q : str
The query.
params : dict
Query parameters.
timeout : int
Maximum runtime for read queries in milliseconds.
read_only : bool
Executes a readonly query if set to True.
profile : bool
Return details on results produced by and time
spent in each operation.
Nz
GRAPH.PROFILEzGRAPH.RO_QUERYzGRAPH.QUERYz --compactz+Timeout argument must be a positive integer�timeoutzwrong number of argumentsz>Note: RedisGraph Python requires server version 2.2.8 or abovezunknown commandF)� read_only)�_build_params_header�name�
isinstance�int� Exception�execute_commandr r r �printr r �versionZ_refresh_schema)r �q�paramsr r �profiler �cmdZcommandZresponse�er
r
r
r s4
�zGraphCommands.queryc C s d}|t |�7 }| �|�S )z
Merge pattern.
zMERGE )r r )r �patternr r
r
r
�merge^ s zGraphCommands.mergec C s | � � | �d| j�S )z|
Deletes graph.
For more information see `DELETE <https://redis.io/commands/graph.delete>`_. # noqa
zGRAPH.DELETE)Z
_clear_schemar! r �r r
r
r
�deleteg s zGraphCommands.deletec C s | � � i | _g | _dS )zT
Commit the graph and reset the edges and the nodes to zero length.
N)r r r r+ r
r
r
�flushp s zGraphCommands.flushc K s t d��dS )zInternal only. Not supported.zVGRAPH.BULK is internal only. Use https://github.com/redisgraph/redisgraph-bulk-loader.N)�NotImplementedError)r �kwargsr
r
r
�bulkx s �zGraphCommands.bulkc C s | j |dd�S )ar
Execute a query and produce an execution plan augmented with metrics
for each operation's execution. Return a string representation of a
query execution plan, with details on results produced by and time
spent in each operation.
For more information see `GRAPH.PROFILE <https://redis.io/commands/graph.profile>`_. # noqa
T)r&