
    mBNjL)                         d dl mZmZmZ 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d	lmZ d
ZdZdZ G d d      Zy)    )ListOptionalUnionN)
DriverInfo)
RedisError   )get_package_version   )Cluster_Conn
Is_Cluster)
AsyncGraphz	GRAPH.UDFz
GRAPH.LISTzGRAPH.CONFIGc                       e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZededd fd       ZdedefdZ	de
e   fd	Zd
edeeef   fdZdd
eddfdZddZddZddZdd
ededefdZddee   defdZd ZdefdZy)FalkorDBa  
    Asynchronous FalkorDB Class for interacting with a FalkorDB server.

    Supports both TCP and Unix socket connections.

    Usage example::
        from falkordb.asyncio import FalkorDB
        # connect to the database and select the 'social' graph
        db = FalkorDB()
        graph = db.select_graph("social")

        # connect using a Unix socket
        db = FalkorDB.from_url("unix:///path/to/redis.sock")
        graph = db.select_graph("social")

        # get a single 'Person' node from the graph and print its name
        response = await graph.query("MATCH (n:Person) RETURN n LIMIT 1")
        result   = response.result_set
        person   = result[0][0]
        print(person.properties['name'])
    Nc%           
         t        j                  d"i d|d|ddd|d|d|d|d	|d
|d|	d|
d|ddd|d|d|d|d|d|d|d|d|d|d|d|dt        ||xs
 t                     d|d|d|d |d!|}%t	        |%      rt        |%||| |!|"|#|$      }%|%| _        |%j                  | _        |%j                  | _        y )#Nhostportdbr   passwordsocket_timeoutsocket_connect_timeoutsocket_keepalivesocket_keepalive_optionsconnection_poolunix_socket_pathencodingencoding_errorsdecode_responsesTretry_on_errorsslssl_keyfilessl_certfilessl_cert_reqsssl_ca_certsssl_ca_datassl_check_hostnamemax_connectionssingle_connection_clienthealth_check_intervalclient_namedriver_infousernameretryredis_connect_funccredential_providerprotocol )	redisRedisr   r	   r   r   
connectionflushdbexecute_command)&selfr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   lib_namelib_versionr+   r,   connect_funcr.   r/   cluster_error_retry_attemptsstartup_nodesrequire_full_coveragereinitialize_stepsread_from_replicasaddress_remapconns&                                         j/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/falkordb/asyncio/falkordb.py__init__zFalkorDB.__init__(   s   R {{  
 
 
  
 	 

 * 
 $: 
 . 
 &> 
 , 
 . 
  
 , 
 " 
 * 
  
  $! 
" &# 
$ (% 
& &' 
( $) 
*  2+ 
, ,- 
. &>/ 
0 #81 
2 $3 
4 #8[-Q<O<QR5 
6 7 
8 9 
:  ,; 
< !4= 
> ? 
D d,%""	D ||#33    urlreturnc                     |j                  d      rd|t        d      d z   }n"|j                  d      rd|t        d      d z   }d|d<   t        j                  |fi |} | |j                        S )	aN  
        Creates a new FalkorDB instance from a URL.

        Args:
            cls: The class itself.
            url (str): The URL.
            kwargs: Additional keyword arguments to pass to the
                ``DB.from_url`` function.

        Returns:
            DB: A new DB instance.

        Usage example::
        db = FalkorDB.from_url("falkor://[[username]:[password]]@localhost:6379")
        db = FalkorDB.from_url("falkors://[[username]:[password]]@localhost:6379")
        db = FalkorDB.from_url("unix://[username@]/path/to/socket.sock?db=0[&password=password]")
        z	falkor://zredis://Nz
falkors://z	rediss://Tr   )r   )
startswithlenr1   from_urlr   )clsrD   kwargsr@   s       rA   rI   zFalkorDB.from_url   sy    * >>+&s3{#3#566C^^L)C$5$7 88C%)!"~~c,V,4#7#788rC   graph_idc                 t    t        |t              r|dk(  rt        dt        |       d      t	        | |      S )z
        Selects a graph by creating a new Graph instance.

        Args:
            graph_id (str): The identifier of the graph.

        Returns:
            AsyncGraph: A new Graph instance associated with the selected graph.
         z*Expected a string parameter, but received .)
isinstancestr	TypeErrortyper   )r6   rL   s     rA   select_graphzFalkorDB.select_graph   sA     (C(HN<T(^<LAN  $))rC   c                 \   K   | j                   j                  t               d{   S 7 w)z
        Lists all graph names.
        See: https://docs.falkordb.com/commands/graph.list.html

        Returns:
            List: List of graph names.

        N)r3   r5   LIST_CMDr6   s    rA   list_graphszFalkorDB.list_graphs   s#      __44X>>>>s   #,*,namec                 j   K   | j                   j                  t        d|       d{   }|d   S 7 	w)aA  
        Retrieve a DB level configuration.
        For a list of available configurations see: https://docs.falkordb.com/configuration.html#falkordb-configuration-parameters

        Args:
            name (str): The name of the configuration.

        Returns:
            int or str: The configuration value.

        GETNr
   r3   r5   
CONFIG_CMD)r6   rY   ress      rA   
config_getzFalkorDB.config_get   s2      OO33JtLL1v Ms   %31
3c                 b   K   | j                   j                  t        d||       d{   S 7 w)aD  
        Update a DB level configuration.
        For a list of available configurations see: https://docs.falkordb.com/configuration.html#falkordb-configuration-parameters

        Args:
            name (str): The name of the configuration.
            value: The value to set.

        Returns:
            None

        SETNr\   )r6   rY   values      rA   
config_setzFalkorDB.config_set   s)      __44ZeTTTTs   &/-/c                 t   K   	 | j                   j                          d{    y7 # t        $ r Y yw xY ww)z5
        Close the underlying connection(s).
        N)r3   acloser   rW   s    rA   re   zFalkorDB.aclose   s2     
	//((*** 		s(   8) ') 8) 	5858c                    K   | S w)z2Return self to support async with-statement usage.r0   rW   s    rA   
__aenter__zFalkorDB.__aenter__   s      s   c                 @   K   | j                          d{    y7 w)z:Close the connection when exiting an async with-statement.N)re   )r6   exc_typeexc_valexc_tbs       rA   	__aexit__zFalkorDB.__aexit__   s      kkms   scriptreplacec                   K   t         dg}|r|j                  d       |j                  ||g       t        | j                        rS| j                  j                         D ]4  }| j                  j                  |      } |j                  |  d{   }6 S  | j                  j                  |  d{   }|S 7 +7 w)a:  
        Load a User Defined Function (UDF) library.

        Args:
            name (str): The name of the library to load.
            script (str): The UDF script contents.
            replace (bool, optional): If True, replace an existing
                library with the same name. Defaults to False.
        LOADREPLACEN)UDF_CMDappendextendr   r3   get_primariesget_redis_connectionr5   )r6   rY   rm   rn   argsnodeclientresps           rA   udf_loadzFalkorDB.udf_load   s       KK	"T6N# doo&557==dC3V33T:: 8  988$??D	 ;?s$   BC B<$C 5B>6C >C lib	with_codec                    K   t         dg}||j                  |       |r|j                  d        | j                  j                  |  d{   S 7 w)a  
        List User Defined Function (UDF) libraries.

        Args:
            lib (str, optional): If provided, filter the list to
                this specific library.
            with_code (bool, optional): If True, include the library
                source code in the result. Defaults to False.

        Returns:
            list: A list of UDF libraries and their metadata.
        LISTNWITHCODE)rr   rs   r3   r5   )r6   r|   r}   rw   s       rA   udf_listzFalkorDB.udf_list  sO       ?KKKK
#4T__44d;;;;s   AAAAc                 D  K   t        | j                        rZ| j                  j                         D ];  }| j                  j                  |      }|j	                  t
        d       d{   }= S | j                  j	                  t
        d       d{   }|S 7 27 w)zK
        Flush (remove) all User Defined Function (UDF) libraries.
        FLUSHNr   r3   ru   rv   r5   rr   )r6   rx   ry   rz   s       rA   	udf_flushzFalkorDB.udf_flush*  s      doo&557==dC#33GWEE 8  88'JJD	 FJs$   A'B )B*+B BB B c                 H  K   t        | j                        r[| j                  j                         D ]<  }| j                  j                  |      }|j	                  t
        d|       d{   }> S | j                  j	                  t
        d|       d{   }|S 7 37 w)z
        Delete a User Defined Function (UDF) library.

        Args:
            lib (str): The name of the library to delete.
        DELETENr   )r6   r|   rx   ry   rz   s        rA   
udf_deletezFalkorDB.udf_delete;  s      doo&557==dC#33GXsKK 8  88(CPPD	 LPs$   A(B"*B+,B"B B" B")$	localhosti  NNNNNNNzutf-8strictNFNNrequiredNNFNFr   Nr   z1.0.0NNNNr      NF   FN)N)rE   N)rE   r   )F)NF)__name__
__module____qualname____doc__rB   classmethodrQ   rI   r   rT   r   rX   r   intr_   rc   re   rg   rl   boolr{   r   r   r   r   r0   rC   rA   r   r      sD   0 #!%   !& %&# MY4v 93 9Z 9 9<*S *Z *"
?49 
?S U38_  US U U 	
3  d :<(3- <4 <0"C rC   r   )typingr   r   r   redis.asyncioasyncior1   redis.driver_infor   redis.exceptionsr   _versionr	   clusterr   r   graphr   rr   rV   r]   r   r0   rC   rA   <module>r      s:    ( (  ( ' * -  
{ {rC   