
    h                    8   S SK Jr  S SKrS SKJr  S SKJrJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr  \(       a  S S	KJr  S S
KJr  S SKJr  SS jr      S                 SS jjr S         SS jjrSS jrSS jrSS.     SS jjrSS jrg)    )annotationsN)import_module)TYPE_CHECKINGAny)import_optional)parse_version)
from_arrow)ModuleUpgradeRequiredError)	Coroutine)	DataFrame)
SchemaDictc                |    SSK nSSKnUR                  R                  R	                  5         UR                  U 5      $ )z/Run asynchronous code as if it was synchronous.r   N)asynciopolars._utils.nest_asyncio_utilsnest_asyncioapplyrun)cor   polarss      S/home/james-whalen/.local/lib/python3.13/site-packages/polars/io/database/_utils.py
_run_asyncr      s,    %
MM$$&;;r?    c                Z   [        S5      n[        UR                  5      S:  a  U(       a  Sn	[        U	5      eSn
0 nOSn
SU0n UR                  " SUU U
UUUUS.UD6n[        XS
9$ ! [
         a8  n[        R                  " SS	[        U5      5      n[        U5      " U5      UeS nAff = f)N
connectorx)r         zL'pre_execution_query' is only supported in connectorx version 0.4.2 or laterarrow2arrowpre_execution_query)connqueryreturn_typepartition_onpartition_rangepartition_numprotocolz://[^:]+:[^:]+@z://***:***@schema_overrides )r   r   __version__
ValueErrorread_sqlBaseExceptionresubstrtyper	   )r"   connection_urir$   r%   r&   r'   r)   r    cxmsgr#   pre_execution_argstblerrerrmsgs                  r   _read_sql_connectorxr:      s     
	&BR^^$y0`CS/!35HI)kk 	
#%+'	
 !	
 c==  ))=#c(C3iS()s   A( (
B*23B%%B*c                
   [        U5       oDR                  5        nUR                  " U 40 U=(       d    0 D6  UR                  5       nS S S 5        S S S 5        [	        WUS9$ ! , (       d  f       N = f! , (       d  f       N)= f)Nr(   )_open_adbc_connectioncursorexecutefetch_arrow_tabler	   )r"   r3   r)   execute_optionsr!   r=   r7   s          r   _read_sql_adbcrA   F   sc     
~	.$u8!6B8&&( 9F	. c,<== 9F	.	.s"   A4-A#	A4#
A1	-A44
Bc                r    U R                  SS5      S   R                  5       nSS0nUR                  X5      $ )N:   r   postgres
postgresql)splitlowerget)r3   driver_namedriver_suffix_maps      r   _get_adbc_driver_name_from_urirL   R   s>     &&sA.q1779K)3\(B  ::r   c                "    [        U 5      nSU 3$ )Nadbc_driver_)rL   )r3   rJ   s     r   _get_adbc_module_name_from_urirO   Y   s    0@K+''r   T)dbapi_submodulec          
        [        U SSSU R                  SS5       3S9nU(       d  U$  [        U  S35      nU$ ! [         a?  nS[	        U5      ;   a*  [        S	5      n[        US
S5      nSU S3n[        U5      S ee S nAff = f)NADBCzdriver not detectedz8If ADBC supports this database, please run: pip install _-)
err_prefix
err_suffixinstall_messagez.dbapiz6PyArrow is required for the DBAPI-compatible interfaceadbc_driver_managerr+   z0.0z;pyarrow is required for adbc-driver-manager < 1.6.0, found zG.
Either upgrade `adbc-driver-manager` (suggested) or install `pyarrow`)r   replacer   ImportErrorr1   getattrr
   )module_namerP   adbc_driveradbc_driver_dbapierX   adbc_str_versionr5   s           r   _import_optional_adbc_driverra   ^   s     "(F""3,-/K !)[M*@A !   CAO"12G"H&':M5Q N#$ %$$ 
 -S1t;s   : 
B:A>>Bc                    [        U 5      n[        U 5      n[        U5      nUS;   a  [        R                  " SU S3SU 5      n UR                  U 5      $ )N)duckdb	snowflakesqlite^z:/{,3} )rL   rO   ra   r/   r0   connect)r3   rJ   r\   r]   s       r   r<   r<      sW    0@K0@K.{;K 77!K= 92~N~..r   )r   zCoroutine[Any, Any, Any]returnr   )NNNNNN)r"   zstr | list[str]r3   r1   r$   
str | Noner%   ztuple[int, int] | Noner&   z
int | Noner'   rj   r)   SchemaDict | Noner    zstr | list[str] | Noneri   r   )N)
r"   r1   r3   r1   r)   rk   r@   zdict[str, Any] | Noneri   r   )r3   r1   ri   r1   )r\   r1   rP   boolri   r   )r3   r1   ri   r   )
__future__r   r/   	importlibr   typingr   r   polars._dependenciesr   polars._utils.variousr   polars.convertr	   polars.exceptionsr
   collections.abcr   r   r   polars._typingr   r   r:   rA   rL   rO   ra   r<   r*   r   r   <module>rv      s   " 	 # % 0 / % 8) )  $.2 $*.26&>&>&> &> ,	&>
 &> &> (&> 0&> &>Z .2		>	>	> (	> +		>
 	>;( !&!&! &! 		&!R	/r   