
    ih                     r    d dl Z d dlmZmZmZ d dlmZ d dlmZ  e j                  e
      Z G d de      Zy)    N)IteratorListOptional)Document)
BaseLoaderc                   f    e Zd ZdZddddededededeee      d	eee      d
dfdZd
ee	   fdZ
y)CouchbaseLoaderaU  Load documents from `Couchbase`.

    Each document represents one row of the result. The `page_content_fields` are
    written into the `page_content`of the document. The `metadata_fields` are written
    into the `metadata` of the document. By default, all columns are written into
    the `page_content` and none into the `metadata`.
    N)page_content_fieldsmetadata_fieldsconnection_stringdb_usernamedb_passwordqueryr
   r   returnc                   	 ddl m} ddlm} ddlm}	 |st        d      |st        d      |st        d	       |||      } || |	|            | _        || _	        || _
        || _        y# t        $ r}
t        d      |
d}
~
ww xY w)
a  Initialize Couchbase document loader.

        Args:
            connection_string (str): The connection string to the Couchbase cluster.
            db_username (str): The username to connect to the Couchbase cluster.
            db_password (str): The password to connect to the Couchbase cluster.
            query (str): The SQL++ query to execute.
            page_content_fields (Optional[List[str]]): The columns to write into the
                `page_content` field of the document. By default, all columns are
                written.
            metadata_fields (Optional[List[str]]): The columns to write into the
                `metadata` field of the document. By default, no columns are written.
        r   )PasswordAuthenticator)Cluster)ClusterOptionsz]Could not import couchbase package.Please install couchbase SDK with `pip install couchbase`.Nz#connection_string must be provided.zdb_username must be provided.zdb_password must be provided.)couchbase.authr   couchbase.clusterr   couchbase.optionsr   ImportError
ValueErrorclusterr   r
   r   )selfr   r   r   r   r
   r   r   r   r   eauths               l/var/www/html/dev/engine/venv/lib/python3.12/site-packages/langchain_community/document_loaders/couchbase.py__init__zCouchbaseLoader.__init__   s    .	<18 !BCC<==<==$

 !((9>$;O P
#6 .-  	M 	s   A. .	B7BBc              #     K   ddl m} | j                  j                   |d             | j                  j	                  | j                        }|D ]  }| j
                  }| j                  st        |j                               |sg }|D ci c]  }|||   
 }}dj                  fd|j                         D              }t        ||        yc c}w w)	z1Load Couchbase data into Document objects lazily.r   )	timedelta   )seconds
c              3   <   K   | ]  \  }}|v s| d |   yw)z: N ).0kvr
   s      r   	<genexpr>z,CouchbaseLoader.lazy_load.<locals>.<genexpr>\   s,      ! $1q<O7O1#Rs!s   )page_contentmetadataN)datetimer!   r   wait_until_readyr   r   r
   listkeysjoinitemsr   )	r   r!   resultrowr   fieldr,   documentr
   s	           @r   	lazy_loadzCouchbaseLoader.lazy_loadG   s     & 	%%i&:; ##DJJ/ 	GC"22O"&":":&&*388:&6#""$7FGes5z)GHGyy !(+		! H HEF!	G Hs   BCCAC)__name__
__module____qualname____doc__strr   r   r   r   r   r7   r&       r   r	   r	      s~     48/31/1/ 1/ 	1/
 1/ &d3i01/ "$s),1/ 
1/fG8H- Gr=   r	   )loggingtypingr   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   	getLoggerr8   loggerr	   r&   r=   r   <module>rD      s6     + + - @			8	$UGj UGr=   