
    dh                     r    S SK r S SKJrJrJr  S SKJr  S SKJr  \ R                  " \
5      r " S S\5      rg)    N)IteratorListOptional)Document)
BaseLoaderc                   t    \ rS rSrSrSSS.S\S\S\S\S	\\\      S
\\\      SS4S jjrS\	\
   4S jrSrg)CouchbaseLoader   aA  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                .    SSK Jn  SSKJn  SSKJn	  U(       d  [        S5      eU(       d  [        S5      eU(       d  [        S	5      eU" UU5      nU" X" U5      5      U l        X@l	        XPl
        X`l        g! [         a  n
[        S5      U
eSn
A
ff = f)
ax  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               f/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/document_loaders/couchbase.py__init__CouchbaseLoader.__init__   s    .	<18 !BCC<==<==$

 !((9>$;O P
#6 .-  	M 	s   A9 9
BBBc              #     ^#    SSK Jn  U R                  R                  U" SS95        U R                  R	                  U R                  5      nU H  nU R
                  nU R                  mT(       d  [        UR                  5       5      mU(       d  / nU Vs0 sH  oUX5   _M	     nnSR                  U4S jUR                  5        5       5      n[        XvS9v   M     gs  snf 7f)	z1Load Couchbase data into Document objects lazily.r   )	timedelta   )seconds
c              3   D   >#    U H  u  pUT;   d  M  U S U 3v   M     g7f)z: N ).0kvr   s      r   	<genexpr>,CouchbaseLoader.lazy_load.<locals>.<genexpr>\   s*      !(3q<O7O1#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_loadCouchbaseLoader.lazy_loadG   s     & 	%%i&:; ##DJJ/C"22O"&":":&&*388:&6#""$7FGesz)HGyy !(+		! H EF!  Hs   BC%C %A C%)r   r   r   r   )__name__
__module____qualname____firstlineno____doc__strr   r   r    r   r   r:   __static_attributes__r(       r   r	   r	      s~     48/31/1/ 1/ 	1/
 1/ &d3i01/ "$s),1/ 
1/fG8H- GrC   r	   )loggingtypingr   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   	getLoggerr<   loggerr	   r(   rC   r   <module>rJ      s4     + + - @			8	$UGj UGrC   