
    Pf(                         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ZdZd	Zd
ZdZdZdZdZ G d d          Z G d de          ZdS )    )	DataError)ResponseError   )VersionMismatchException)ExecutionPlan)AsyncQueryResultQueryResultzGRAPH.PROFILEzGRAPH.RO_QUERYzGRAPH.QUERYzGRAPH.DELETEzGRAPH.SLOWLOGzGRAPH.CONFIGz
GRAPH.LISTzGRAPH.EXPLAINc                   b    e Zd ZdZd ZddZd Zd Zd Zd	 Z	d
 Z
d ZddZd ZddZddZdS )GraphCommandszRedisGraph Commandsc                 v   t          | j                  dk    rt          | j                  dk    rdS d}| j                                        D ]\  }}|t	          |          dz   z  }|d                    d | j        D                       z  }|d         dk    r
|dd         }|                     |          S )z&
        Create entire graph.
        r   NzCREATE ,c                 ,    g | ]}t          |          S  )str).0edges     O/var/www/html/env/lib/python3.11/site-packages/redis/commands/graph/commands.py
<listcomp>z(GraphCommands.commit.<locals>.<listcomp>    s    <<<3t99<<<    )lennodesedgesitemsr   joinquery)selfr   _nodes       r   commitzGraphCommands.commit   s     tz??aC
OOq$8$84z'')) 	% 	%GAtSYY_$EE<<<<<=== 9#2#JEzz%   r   NFc                 R   |}|                      |          |z   }|rt          }n|rt          nt          }|| j        |dg}t          |t                    r|                    d|g           n|t          d          	  | j	        | }	t          | |	|          S # t          $ r8}
dt          |
          v r |r|                     |||d          cY d}
~
S |
d}
~
wt          $ rB}
|
j        | _        |                                  |                     ||||          cY d}
~
S d}
~
ww xY w)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.
        	--compacttimeoutN+Timeout argument must be a positive integerunknown commandF	read_only)_build_params_headerPROFILE_CMDRO_QUERY_CMD	QUERY_CMDname
isinstanceintextend	Exceptionexecute_commandr	   r   r   r   r   version_refresh_schemar   qparamsr#   r'   profiler   cmdcommandresponsees              r   r   zGraphCommands.query(   sy   *  ))&11E9
  	;CC"+:,,C	5+6 gs## 	KNNIw/0000 IJJJ	=+t+W5HtXw777 	 	 	 CFF**y*zz!VWzFFFFFFFFG' 	= 	= 	= 9DL  """::a)<<<<<<<<	=s6   ?B 
D&$+CD&CD&$7D!D&!D&c                 T    d}|t          |          z  }|                     |          S )z 
        Merge pattern.
        zMERGE )r   r   )r   patternr   s      r   mergezGraphCommands.mergeb   s+     Wzz%   r   c                 j    |                                   |                     t          | j                  S )z|
        Deletes graph.
        For more information see `DELETE <https://redis.io/commands/graph.delete>`_. # noqa
        )_clear_schemar1   
DELETE_CMDr,   r   s    r   deletezGraphCommands.deletek   s.    
 	##J	:::r   c                 J    |                                   i | _        g | _        dS zT
        Commit the graph and reset the edges and the nodes to zero length.
        Nr    r   r   rB   s    r   flushzGraphCommands.flusht   s#     	



r   c                      t          d          )zInternal only. Not supported.zVGRAPH.BULK is internal only. Use https://github.com/redisgraph/redisgraph-bulk-loader.)NotImplementedError)r   kwargss     r   bulkzGraphCommands.bulk|   s    !H
 
 	
r   c                 0    |                      |d          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)r7   )r   )r   r   s     r   r7   zGraphCommands.profile   s     zz%z...r   c                 B    |                      t          | j                  S )a  
        Get a list containing up to 10 of the slowest queries issued
        against the given graph ID.
        For more information see `GRAPH.SLOWLOG <https://redis.io/commands/graph.slowlog>`_. # noqa

        Each item in the list has the following structure:
        1. A unix timestamp at which the log entry was processed.
        2. The issued command.
        3. The issued query.
        4. The amount of time needed for its execution, in milliseconds.
        )r1   SLOWLOG_CMDr,   rB   s    r   slowlogzGraphCommands.slowlog   s     ##K;;;r   c                     |rdnd|g}|'|r|                     |           nt          d           | j        t          g|R  S )a  
        Retrieve or update a RedisGraph configuration.
        For more information see `https://redis.io/commands/graph.config-get/>`_. # noqa

        Args:

        name : str
            The name of the configuration
        value :
            The value we want to set (can be used only when `set` is on)
        set : bool
            Turn on to set a configuration. Default behavior is get.
        SETGETNz3``value`` can be provided only when ``set`` is True)appendr   r1   
CONFIG_CMD)r   r,   valuesetr6   s        r   configzGraphCommands.config   sl     )%%E40 e$$$$I   $t#J88888r   c                 6    |                      t                    S )z
        Lists all graph keys in the keyspace.
        For more information see `GRAPH.LIST <https://redis.io/commands/graph.list>`_. # noqa
        )r1   LIST_CMDrB   s    r   	list_keyszGraphCommands.list_keys   s    
 ##H---r   c                     |                      |          |z   }|                     t          | j        |          }t	          |d         t
                    rd |D             }d                    |          S )
        Get the execution plan for given query,
        GRAPH.EXPLAIN returns an array of operations.

        Args:
            query: the query that will be executed
            params: query parameters
        r   c                 6    g | ]}|                                 S r   decoder   bs     r   r   z0GraphCommands.execution_plan.<locals>.<listcomp>        ---1AHHJJ---r   
r(   r1   EXPLAIN_CMDr,   r-   bytesr   r   r   r6   plans       r   execution_planzGraphCommands.execution_plan   sn     ))&11E9##KEBBd1gu%% 	.-----Dyyr   c                     |                      |          |z   }|                     t          | j        |          }t	          |          S )a8  
        Get the execution plan for given query,
        GRAPH.EXPLAIN returns ExecutionPlan object.
        For more information see `GRAPH.EXPLAIN <https://redis.io/commands/graph.explain>`_. # noqa

        Args:
            query: the query that will be executed
            params: query parameters
        r(   r1   re   r,   r   rg   s       r   explainzGraphCommands.explain   sC     ))&11E9##KEBBT"""r   NNFF)NFN)__name__
__module____qualname____doc__r    r   r>   rC   rG   rK   r7   rO   rW   rZ   ri   rl   r   r   r   r   r      s        ! ! !&8= 8= 8= 8=t! ! !; ; ;  
 
 
/ / /< < <9 9 9 90. . .    # # # # # #r   r   c                   ,    e Zd ZddZddZddZd ZdS )	AsyncGraphCommandsNFc                   K   |}|                      |          |z   }|rt          }n|rt          nt          }|| j        |dg}t          |t                    r|                    d|g           n|t          d          	  | j	        |  d{V }	t                                          | |	|           d{V S # t          $ r>}
dt          |
          v r&|r$|                     |||d           d{V cY d}
~
S |
d}
~
wt          $ rH}
|
j        | _        |                                  |                     ||||           d{V cY d}
~
S d}
~
ww xY w)a1  
        Executes a query against the graph.
        For more information see `GRAPH.QUERY <https://oss.redis.com/redisgraph/master/commands/#graphquery>`_. # 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.
        r"   r#   Nr$   r%   Fr&   )r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r   
initializer   r   r   r   r2   r3   r4   s              r   r   zAsyncGraphCommands.query   s     *  ))&11E9
  	;CC"+:,,C	5+6 gs## 	KNNIw/0000 IJJJ	C1T17;;;;;;;H)++66tXwOOOOOOOOO 	 	 	 CFF**y*!ZZ67eZLLLLLLLLLLLLLLG' 	C 	C 	C 9DL  """Avw	BBBBBBBBBBBBBB	Cs6   8B: :
E1C=5E;C==E
=EEEc                    K   |                      |          |z   }|                     t          | j        |           d{V }t	          |d         t
                    rd |D             }d                    |          S )r\   Nr   c                 6    g | ]}|                                 S r   r^   r`   s     r   r   z5AsyncGraphCommands.execution_plan.<locals>.<listcomp>"  rb   r   rc   rd   rg   s       r   ri   z!AsyncGraphCommands.execution_plan  s       ))&11E9))+ty%HHHHHHHHd1gu%% 	.-----Dyyr   c                    K   |                      |          |z   }|                     t          | j        |           d{V }t	          |          S )z
        Get the execution plan for given query,
        GRAPH.EXPLAIN returns ExecutionPlan object.

        Args:
            query: the query that will be executed
            params: query parameters
        Nrk   rg   s       r   rl   zAsyncGraphCommands.explain%  sY       ))&11E9))+ty%HHHHHHHHT"""r   c                 Z   K   |                                   d{V  i | _        g | _        dS rE   rF   rB   s    r   rG   zAsyncGraphCommands.flush3  s:       kkmm



r   rm   rn   )ro   rp   rq   r   ri   rl   rG   r   r   r   rt   rt      sd        8C 8C 8C 8Ct    # # # #    r   rt   N)redisr   redis.exceptionsr   
exceptionsr   ri   r   query_resultr   r	   r)   r*   r+   rA   rN   rT   rY   re   r   rt   r   r   r   <module>r      s          * * * * * * 0 0 0 0 0 0 ) ) ) ) ) ) 7 7 7 7 7 7 7 7	

E# E# E# E# E# E# E# E#P_ _ _ _ _ _ _ _ _ _r   