
    +h(                         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y)    )	DataError)ResponseError   )VersionMismatchException)ExecutionPlan)AsyncQueryResultQueryResultzGRAPH.PROFILEzGRAPH.RO_QUERYzGRAPH.QUERYzGRAPH.DELETEzGRAPH.SLOWLOGzGRAPH.CONFIGz
GRAPH.LISTzGRAPH.EXPLAINc                   `    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y)GraphCommandszRedisGraph Commandsc           	      ~   t        | j                        dk(  rt        | j                        dk(  ryd}| j                  j                         D ]  \  }}|t	        |      dz   z  } |dj                  | j                  D cg c]  }t	        |       c}      z  }|d   dk(  r|dd }| j                  |      S c c}w )z&
        Create entire graph.
        r   NzCREATE ,)lennodesedgesitemsstrjoinquery)selfr   _nodeedges        P/var/www/html/venv/lib/python3.12/site-packages/redis/commands/graph/commands.pycommitzGraphCommands.commit   s     tzz?aC

Oq$8zz'') 	%GAtSY_$E	% 	<3t9<== 9#2JEzz%   =s   B:
Nc                    |}| j                  |      |z   }|rt        }n|rt        nt        }|| j                  |dg}t        |t              r|j                  d|g       n|t        d      	  | j                  | }	t        | |	|      S # t        $ r0}
dt        |
      v r|r| j                  |||d      cY d}
~
S |
d}
~
wt        $ r?}
|
j                  | _        | j!                          | 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(   s   *  ))&1E9
 C"+,C		5+6 gs#NNIw/0 IJJ	=+t++W5HtXw77 	 CF*yzz!VWzFFG' 	= 99DL  "::a)<<	=s6   0B 	D#C 8D>C  D4D DDc                 D    d}|t        |      z  }| j                  |      S )z 
        Merge pattern.
        zMERGE )r   r   )r   patternr   s      r   mergezGraphCommands.mergeb   s&     Wzz%      c                 b    | j                          | j                  t        | j                        S )z|
        Deletes graph.
        For more information see `DELETE <https://redis.io/commands/graph.delete>`_. # noqa
        )_clear_schemar,   
DELETE_CMDr'   r   s    r   deletezGraphCommands.deletek   s'    
 	##J		::r:   c                 @    | j                          i | _        g | _        yzT
        Commit the graph and reset the edges and the nodes to zero length.
        Nr   r   r   r>   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                 (    | j                  |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)r2   )r   )r   r   s     r   r2   zGraphCommands.profile   s     zz%z..r:   c                 B    | j                  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.
        )r,   SLOWLOG_CMDr'   r>   s    r   slowlogzGraphCommands.slowlog   s     ##K;;r:   c                     |rdnd|g}||r|j                  |       nt        d       | j                  t        g| 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GETz3``value`` can be provided only when ``set`` is True)appendr   r,   
CONFIG_CMD)r   r'   valuesetr1   s        r   configzGraphCommands.config   sQ     %E40e$I  $t##J888r:   c                 ,    | j                  t              S )z
        Lists all graph keys in the keyspace.
        For more information see `GRAPH.LIST <https://redis.io/commands/graph.list>`_. # noqa
        )r,   LIST_CMDr>   s    r   	list_keyszGraphCommands.list_keys   s    
 ##H--r:   c                     | j                  |      |z   }| j                  t        | j                  |      }t	        |d   t
              r|D cg c]  }|j                          }}dj                  |      S c c}w )
        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   
r#   r,   EXPLAIN_CMDr'   r(   bytesdecoder   r   r   r1   planbs        r   execution_planzGraphCommands.execution_plan   sk     ))&1E9##KEBd1gu%(,-1AHHJ-D-yy .s   A7c                     | j                  |      |z   }| j                  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#   r,   r[   r'   r   r   r   r1   r_   s       r   explainzGraphCommands.explain   s<     ))&1E9##KEBT""r:   NNFF)NFN)__name__
__module____qualname____doc__r   r   r9   r?   rC   rG   r2   rK   rS   rV   ra   re    r:   r   r   r      sB    !&8=t!;
/<90. #r:   r   c                   *    e Zd ZddZddZddZd Zy)AsyncGraphCommandsNc                   K   |}| j                  |      |z   }|rt        }n|rt        nt        }|| j                  |dg}t        |t              r|j                  d|g       n|t        d      	  | j                  |  d{   }	t               j                  | |	|       d{   S 7 '7 # t        $ r9}
dt        |
      v r%|r#| j                  |||d       d{  7  cY d}
~
S |
d}
~
wt        $ rH}
|
j                   | _        | j#                          | j                  ||||       d{  7  cY d}
~
S d}
~
ww xY w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*   r+   r,   r   
initializer   r   r   r   r-   r.   r/   s              r   r   zAsyncGraphCommands.query   s5    *  ))&1E9
 C"+,C		5+6 gs#NNIw/0 IJJ	C1T117;;H)+66tXwOOO <O 	 CF*y!ZZ67eZLLLLG' 	C 99DL  "Avw	BBBB	Cs   A/E2B0 B,"B0 'B.(B0 +E,B0 .B0 0	E9'C- C#!C-%E&E+C--E98D<1D42D<6E7E<EEc                   K   | j                  |      |z   }| j                  t        | j                  |       d{   }t	        |d   t
              r|D cg c]  }|j                          }}dj                  |      S 7 Ec c}w w)rX   Nr   rY   rZ   r^   s        r   ra   z!AsyncGraphCommands.execution_plan  sv      ))&1E9))+tyy%HHd1gu%(,-1AHHJ-D-yy I-s!   9BBBB.BBc                    K   | j                  |      |z   }| j                  t        | j                  |       d{   }t	        |      S 7 w)z
        Get the execution plan for given query,
        GRAPH.EXPLAIN returns ExecutionPlan object.

        Args:
            query: the query that will be executed
            params: query parameters
        Nrc   rd   s       r   re   zAsyncGraphCommands.explain%  sI      ))&1E9))+tyy%HHT"" Is   9AAAc                 \   K   | j                          d{    i | _        g | _        y7 wrA   rB   r>   s    r   rC   zAsyncGraphCommands.flush3  s*      kkm

 	s   ,*,rf   rg   )rh   ri   rj   r   ra   re   rC   rl   r:   r   rn   rn      s    8Ct #r:   rn   N)redisr   redis.exceptionsr   
exceptionsr   ra   r   query_resultr   r	   r$   r%   r&   r=   rJ   rP   rU   r[   r   rn   rl   r:   r   <module>rx      sW     * 0 ) 7	

E# E#P_ _r:   