
    dhN                     J    S SK JrJrJrJr  S SKJr  S SKJr   " S S\5      r	g)    )DictListOptionalcast)Document)
BaseLoaderc                       \ rS rSrSr     SS\S\S\S\\\\4      S\\	\      S	\\	\      4S
 jjr
S\	\   4S jrSrg)DuckDBLoader   a7  Load from `DuckDB`.

Each document represents one row of the result. The `page_content_columns`
are written into the `page_content` of the document. The `metadata_columns`
are written into the `metadata` of the document. By default, all columns
are written into the `page_content` and none into the `metadata`.
Nquerydatabase	read_onlyconfigpage_content_columnsmetadata_columnsc                 `    Xl         X l        X0l        U=(       d    0 U l        XPl        X`l        g)a  

Args:
    query: The query to execute.
    database: The database to connect to. Defaults to ":memory:".
    read_only: Whether to open the database in read-only mode.
      Defaults to False.
    config: A dictionary of configuration options to pass to the database.
      Optional.
    page_content_columns: The columns to write into the `page_content`
      of the document. Optional.
    metadata_columns: The columns to write into the `metadata` of the document.
      Optional.
N)r   r   r   r   r   r   )selfr   r   r   r   r   r   s          j/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/document_loaders/duckdb_loader.py__init__DuckDBLoader.__init__   s*    . 
 "l$8! 0    returnc           
        ^^  SS K n/ nUR                  U R                  U R                  U R
                  S9 nUR                  U R                  5      nUR                  5       n[        [        UR                  5      nU Vs/ sH  owS   PM	     snmU R                  c  TnOU R                  nU R                  c  / n	OU R                  n	U H]  mSR                  UU4S jU 5       5      n
U	 Vs0 sH  nUTTR                  U5         _M     nn[!        XS9nUR#                  U5        M_     S S S 5        U$ ! [         a    [        S5      ef = fs  snf s  snf ! , (       d  f       U$ = f)Nr   zTCould not import duckdb python package. Please install it with `pip install duckdb`.)r   r   r   
c              3   T   >#    U H  nU S TTR                  U5          3v   M      g7f)z: N)index).0columnfield_namesresults     r   	<genexpr>$DuckDBLoader.load.<locals>.<genexpr>L   s4      )"6 hb(9(9&(A!B CD"6s   %()page_contentmetadata)duckdbImportErrorconnectr   r   r   executer   fetchallr   listdescriptionr   r   joinr   r   append)r   r%   docsconquery_resultresultsr+   cr   r   r#   r   r$   docr   r    s                 @@r   loadDuckDBLoader.load/   s~   	 ^^]]dnnT[[  
;;tzz2L"++-Gt\%=%=>K)45AQ45K((0'2$'+'@'@$$$,#% #'#8#8 !#yy )"6)   #3"2 F;#4#4V#<=="2  
 LLC  "%
@ O  	? 	 6$1
 
@ s6   D8 A
EEA E0E E8E
E
E*)r   r   r   r   r   r   )z:memory:FNNN)__name__
__module____qualname____firstlineno____doc__strboolr   r   r   r   r   r4   __static_attributes__ r   r   r
   r
      s     #+/480411 1 	1
 c3h(1 'tCy11 #49-1<*d8n *r   r
   N)
typingr   r   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   r
   r>   r   r   <module>rB      s    - - - @Q: Qr   