o
    }l~i  ã                   @  s´   d 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 ddl
mZ ddl
mZ erPd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 )z”
.. warning::
    **Preview API**: Firestore Pipelines is currently in preview and is
    subject to potential breaking changes in future releases.
é    )Úannotations)ÚTYPE_CHECKING)Úpipeline_stages)Ú_BasePipeline)ÚPipelineStream)ÚPipelineSnapshot)ÚPipelineResultN)ÚClient)ÚConstant)ÚTransaction)ÚValue)ÚPipelineExplainOptionsc                      sN   e Zd ZdZ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 )ÚPipelineam  
    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.

    .. warning::
        **Preview API**: Firestore Pipelines is currently in preview and is
        subject to potential breaking changes in future releases.
    Úclientr	   Ú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__© úi/var/www/newdalilibackend/backend/venv/lib/python3.10/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)
        c                 S  ó   i | ]\}}|d kr||“qS ©r   r   ©Ú.0ÚkÚvr   r   r   Ú
<dictcomp>b   ó    z$Pipeline.execute.<locals>.<dictcomp>c                 S  s   g | ]}|‘qS r   r   )r&   Úresultr   r   r   Ú
<listcomp>d   s    z$Pipeline.execute.<locals>.<listcomp>)Ú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 )aA  
        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)
        c                 S  r#   r$   r   r%   r   r   r   r)   ‚   r*   z#Pipeline.stream.<locals>.<dictcomp>)r-   r.   r   r   )r   r   r   r   r   r/   r   r   r   r0   g   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__r   r2   r0   Ú__classcell__r   r   r   r   r   %   s    ú#úr   )r7   Ú
__future__r   Útypingr   Úgoogle.cloud.firestore_v1r   r   Ú'google.cloud.firestore_v1.base_pipeliner   Ú)google.cloud.firestore_v1.pipeline_resultr   r   r   ÚdatetimeÚ google.cloud.firestore_v1.clientr	   Ú.google.cloud.firestore_v1.pipeline_expressionsr
   Ú%google.cloud.firestore_v1.transactionr   Ú(google.cloud.firestore_v1.types.documentr   Ú'google.cloud.firestore_v1.query_profiler   r   r   r   r   r   Ú<module>   s    