
    D6i~                     (    d Z ddlmZ  G d d      Zy)a  
QueryChain is a wrapper for sequence of queries.


Features:

    * Easy iteration for sequence of queries
    * Limit, offset and count which are applied to all queries in the chain
    * Smart __getitem__ support


Initialization
^^^^^^^^^^^^^^

QueryChain takes iterable of queries as first argument. Additionally limit and
offset parameters can be given

::

    chain = QueryChain([session.query(User), session.query(Article)])

    chain = QueryChain(
        [session.query(User), session.query(Article)],
        limit=4
    )


Simple iteration
^^^^^^^^^^^^^^^^
::

    chain = QueryChain([session.query(User), session.query(Article)])

    for obj in chain:
        print obj


Limit and offset
^^^^^^^^^^^^^^^^

Lets say you have 5 blog posts, 5 articles and 5 news items in your
database.

::

    chain = QueryChain(
        [
            session.query(BlogPost),
            session.query(Article),
            session.query(NewsItem)
        ],
        limit=5
    )

    list(chain)  # all blog posts but not articles and news items


    chain = chain.offset(4)
    list(chain)  # last blog post, and first four articles


Just like with original query object the limit and offset can be chained to
return a new QueryChain.

::

    chain = chain.limit(5).offset(7)


Chain slicing
^^^^^^^^^^^^^

::

    chain = QueryChain(
        [
            session.query(BlogPost),
            session.query(Article),
            session.query(NewsItem)
        ]
    )

    chain[3:6]   # New QueryChain with offset=3 and limit=6


Count
^^^^^

Let's assume that there are five blog posts, five articles and five news
items in the database, and you have the following query chain::

    chain = QueryChain(
        [
            session.query(BlogPost),
            session.query(Article),
            session.query(NewsItem)
        ]
    )

You can then get the total number rows returned by the query chain
with :meth:`~QueryChain.count`::

    >>> chain.count()
    15


    )copyc                   <    e Zd ZdZd
dZd Zd Zd Zd Zd Z	d	 Z
y)
QueryChaina  
    QueryChain can be used as a wrapper for sequence of queries.

    :param queries: A sequence of SQLAlchemy Query objects
    :param limit: Similar to normal query limit this parameter can be used for
        limiting the number of results for the whole query chain.
    :param offset: Similar to normal query offset this parameter can be used
        for offsetting the query chain as a whole.

    .. versionadded: 0.26.0
    Nc                 .    || _         || _        || _        y N)queries_limit_offset)selfr   limitoffsets       _/home/azureuser/techstart-app/venv/lib/python3.12/site-packages/sqlalchemy_utils/query_chain.py__init__zQueryChain.__init__}   s        c              #   X  K   d}d}| j                   D ]  }t        |      }| j                  r|j                  | j                  |z
        }| j                  r|j                  | j                  |z
        }d}|D ]  }|dz  }|dz  }|  |s||j                         z  }||z  } y w)Nr      )r   r   r	   r   r
   r   count)r   consumedskippedquery
query_copy	obj_countobjs          r   __iter__zQueryChain.__iter__   s     \\ 	%EeJ{{DKK($:;||T\\G%;<I AQ		
 :++--9$!	%s   B(B*c                     | d | S r    r   values     r   r   zQueryChain.limit   s    FU|r   c                     | |d  S r   r   r   s     r   r   zQueryChain.offset   s    EF|r   c                 :    t        d | j                  D              S )zY
        Return the total number of rows this QueryChain's queries would return.
        c              3   <   K   | ]  }|j                           y wr   )r   ).0qs     r   	<genexpr>z#QueryChain.count.<locals>.<genexpr>   s     317793s   )sumr   r   s    r   r   zQueryChain.count   s     3dll333r   c                    t        |t              rg| j                  | j                  |j                  |j                  n| j
                  |j                  |j                        S | j                        S | |d D ]  }|c S  y )N)r   r   r   r   )
isinstanceslice	__class__r   stopr	   startr
   )r   keyr   s      r   __getitem__zQueryChain.__getitem__   s    c5!>>"%(("6chhDKK$'II$9syy "   @D|| "   C{ 
r   c                     dt        |       z  S )Nz<QueryChain at 0x%x>)idr&   s    r   __repr__zQueryChain.__repr__   s    %400r   )NN)__name__
__module____qualname____doc__r   r   r   r   r   r.   r1   r   r   r   r   r   p   s*    

%*4	1r   r   N)r5   r   r   r   r   r   <module>r6      s   jX ?1 ?1r   