o
    ,=ji  ã                   @  s    d dl mZ d dlmZ d dlmZ d dlmZ d dl	m
Z
mZmZ erFd dlZd dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ G dd„ deƒZdS )é    )Úannotations)ÚTYPE_CHECKING)Úpipeline_stages)Ú_BasePipeline)ÚPipelineResultÚPipelineSnapshotÚPipelineStreamN)ÚClient)ÚConstant)ÚPipelineExplainOptions)ÚTransaction)ÚValuec                      sX   e Zd ZU dZded< d‡ fdd„Zd	d	d	i d
œddd„Zd	d	d	i d
œddd„Z‡  ZS )ÚPipelineaÏ  
    Pipelines allow for complex data transformations and queries involving
    multiple stages like filtering, projection, aggregation, and vector search.

    Usage Example:
        >>> from google.cloud.firestore_v1.pipeline_expressions import Field
        >>>
        >>> def run_pipeline():
        ...     client = Client(...)
        ...     pipeline = client.pipeline()
        ...                      .collection("books")
        ...                      .where(Field.of("published").gt(1980))
        ...                      .select("title", "author")
        ...     for result in pipeline.execute():
        ...         print(result)

    Use `client.pipeline()` to create instances of this class.


    r	   Z_clientÚclientÚstagesústages.Stagec                   s   t ƒ j|g|¢R Ž  dS )z®
        Initializes a Pipeline.

        Args:
            client: The `Client` instance to use for execution.
            *stages: Initial stages for the pipeline.
        N)ÚsuperÚ__init__)Úselfr   r   ©Ú	__class__© úlC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\google/cloud/firestore_v1/pipeline.pyr   =   s   zPipeline.__init__N)ÚtransactionÚ	read_timeÚexplain_optionsÚadditional_optionsr   ú'Transaction' | Noner   údatetime.datetime | Noner   úPipelineExplainOptions | Noner   údict[str, Value | Constant]Úreturnú PipelineSnapshot[PipelineResult]c                C  s>   dd„ t ƒ  ¡ D ƒ}tt| fi |¤Ž}dd„ |D ƒ}t||ƒS )a�  
        Executes this pipeline and returns results as a list

        Args:
            transaction (Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]):
                An existing transaction that this query will run in.
                If a ``transaction`` is used and it already has write operations
                added, this method cannot be used (i.e. read-after-write is not
                allowed).
            read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
                time. This must be a microsecond precision timestamp within the past one hour, or
                if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp
                within the past 7 days. For the most accurate results, use UTC timezone.
            explain_options (Optional[:class:`~google.cloud.firestore_v1.query_profile.PipelineExplainOptions`]):
                Options to enable query profiling for this query. When set,
                explain_metrics will be available on the returned list.
            additional_options (Optional[dict[str, Value | Constant]]): Additional options to pass to the query.
                These options will take precedence over method argument if there is a conflict (e.g. explain_options)

        Raises:
            google.api_core.exceptions.GoogleAPIError: If there is a backend error.
        c                 S  ó   i | ]\}}|d kr||“qS ©r   r   ©Ú.0ÚkÚvr   r   r   Ú
<dictcomp>e   ó    z$Pipeline.execute.<locals>.<dictcomp>c                 S  s   g | ]}|‘qS r   r   )r&   Úresultr   r   r   Ú
<listcomp>g   s    z$Pipeline.execute.<locals>.<listcomp>N)ÚlocalsÚitemsr   r   r   )r   r   r   r   r   ÚkwargsÚstreamÚresultsr   r   r   ÚexecuteG   s   
zPipeline.executeúPipelineStream[PipelineResult]c                C  s&   dd„ t ƒ  ¡ D ƒ}tt| fi |¤ŽS )a¦  
        Process this pipeline as a stream, providing results through an Iterable

        Args:
            transaction (Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]):
                An existing transaction that this query will run in.
                If a ``transaction`` is used and it already has write operations
                added, this method cannot be used (i.e. read-after-write is not
                allowed).
            read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
                time. This must be a microsecond precision timestamp within the past one hour, or
                if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp
                within the past 7 days. For the most accurate results, use UTC timezone.
            explain_options (Optional[:class:`~google.cloud.firestore_v1.query_profile.PipelineExplainOptions`]):
                Options to enable query profiling for this query. When set,
                explain_metrics will be available on the returned generator.
            additional_options (Optional[dict[str, Value | Constant]]): Additional options to pass to the query.
                These options will take precedence over method argument if there is a conflict (e.g. explain_options)

        Raises:
            google.api_core.exceptions.GoogleAPIError: If there is a backend error.
        c                 S  r#   r$   r   r%   r   r   r   r)   ˆ   r*   z#Pipeline.stream.<locals>.<dictcomp>N)r-   r.   r   r   )r   r   r   r   r   r/   r   r   r   r0   j   s   zPipeline.stream)r   r	   r   r   )
r   r   r   r   r   r   r   r    r!   r"   )
r   r   r   r   r   r   r   r    r!   r3   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r2   r0   Ú__classcell__r   r   r   r   r   %   s   
 ú&úr   )Ú
__future__r   Útypingr   Zgoogle.cloud.firestore_v1r   r   Z'google.cloud.firestore_v1.base_pipeliner   Z)google.cloud.firestore_v1.pipeline_resultr   r   r   ÚdatetimeZ google.cloud.firestore_v1.clientr	   Z.google.cloud.firestore_v1.pipeline_expressionsr
   Z'google.cloud.firestore_v1.query_profiler   Z%google.cloud.firestore_v1.transactionr   Z(google.cloud.firestore_v1.types.documentr   r   r   r   r   r   Ú<module>   s   