ó
    À‘´j  ã                  óÖ   • S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	J
r
JrJr  SSKrSSKJrJr  SSKJr  \" \5      R)                  S	5      rSS
 jr\SS j5       r\SS j5       rSS jrg)a  Postgres/pgvector connection helper for the ADE RAG playground.

Reuses `quber.settings` for credentials (it loads `.env` from the current
working directory) and registers the pgvector type adapters so `VECTOR`
columns round-trip as Python lists / numpy arrays.
é    )Úannotations)ÚasynccontextmanagerÚcontextmanager)ÚPath)ÚAsyncGeneratorÚ	GeneratorÚLiteralStringÚcastN)Úregister_vectorÚregister_vector_async)Úget_settingsz
schema.sqlc            
     ó°   • [        5       R                  n SU R                   SU R                   SU R                   SU R                   SU R
                   3
$ )Nzhost=z port=z dbname=z user=z
 password=)r   ÚdbÚhostÚportÚuserÚpassword)r   s    Ú1/home/mande/repo/quber/src/quber/playground/db.pyÚdsnr      sL   € Ü	‹×	Ñ	€BØ�2—7‘7�)˜6 "§'¡' ¨(°2·5±5°'¸ÀÇÁ¸yÈ
ÐSU×S^ÑS^ÐR_Ð`Ð`ó    c               #  ó˜   #   • [         R                  " [        5       SS9 n [        U 5        U v •  SSS5        g! , (       d  f       g= f7f)a.  Yield a connection with pgvector adapters registered and autocommit on.

For code off the event loop: ingest, the CLI, scripts. A request handler
or anything else running under asyncio uses `connect_async`, because a
blocking query there holds the loop and stalls every other request's
in-flight work.
T©Ú
autocommitN)ÚpsycopgÚconnectr   r   ©Úconns    r   r   r      s1   é € ô 
�Šœ›¨4Ò	0°DÜ˜ÔØŠ
÷ 
1×	0Ö	0üs   ‚A
 9°	A
¹
AÁA
c                ó  #   • [         R                  R                  [        5       SS9I Sh  v•N  ISh  v•N n [	        U 5      I Sh  v•N   U 7v •  SSS5      ISh  v•N   g N6 N/ N N! , ISh  v•N  (       d  f       g= f7f)zƒThe same connection for code on the event loop: queries are awaited,
so the loop keeps serving other requests while Postgres works.Tr   N)r   ÚAsyncConnectionr   r   r   r   s    r   Úconnect_asyncr    )   s_   é € ô ×,Ñ,×4Ñ4´S³UÀtÐ4ÐL×L×LÐLÐPTÜ# DÓ)×)Ð)Ø‹
÷ M×LÔLÙ)÷ M×L×LÐLüsf   ‚*B¬A#­BµA%¶B¹A+ÁA'Á		A+ÁBÁA)ÁBÁ%BÁ'A+Á)BÁ+BÁ1A4Á2BÁ>Bc                 ó²   • [        [        [        R                  5       5      n [	        5        nUR                  U 5        SSS5        g! , (       d  f       g= f)zKCreate the `ade_playground` schema from schema.sql (drops existing tables).N)r
   r	   ÚSCHEMA_FILEÚ	read_textr   Úexecute)Úsqlr   s     r   Úapply_schemar&   2   s6   € ô Œ}œk×3Ñ3Ó5Ó
6€CÜ	Œ�dØ�‰�SÔ÷ 
�Žús   ­AÁ
A)ÚreturnÚstr)r'   zGenerator[psycopg.Connection])r'   z'AsyncGenerator[psycopg.AsyncConnection])r'   ÚNone)Ú__doc__Ú
__future__r   Ú
contextlibr   r   Úpathlibr   Útypingr   r   r	   r
   r   Úpgvector.psycopgr   r   Úquber.settingsr   Ú__file__Ú	with_namer"   r   r   r    r&   © r   r   Ú<module>r4      sk   ðñõ #ç :Ý ß AÓ Aã ß Cå 'á�8‹n×&Ñ& |Ó4€ôað
 ó
ó ð
ð óó ðõr   