+
    iG                         R t ^ RIHt ^ RIt^RIHt ^RIHt ^RI	Ht
 ^RIHt ^RIHt ^RIHt ^RIHt ^RIHt ]P&                  ! ]4      t ! R R	4      t ! R
 R4      t ! R R4      t]P2                  tR# )zBaked query extension.

Provides a creational pattern for the :class:`.query.Query` object which
allows the fully constructed object, Core select statement, and string
compiled result to be fully cached.


N)exc)util)Query)Session)func)literal_columnc                   4   a  ] tR t^#t o RtRtR tR tRtV t	R# )BakeryzCallable which returns a :class:`.BakedQuery`.

This object is returned by the class method
:meth:`.BakedQuery.bakery`.  It exists as an object
so that the "cache" can be easily inspected.

.. versionadded:: 1.2


c                    Wn         W n        R # Nclscache)selfcls_r   s   &&&nC:\Users\petid\OneDrive\Desktop\Maestro\MAESTRO\maestro-backend\venv\Lib\site-packages\sqlalchemy/ext/baked.py__init__Bakery.__init__1   s    
    c                :    V P                  V P                  W4      # r   r   )r   
initial_fnargss   &&*r   __call__Bakery.__call__5   s    xx

J55r   )r   r   Nr   )
__name__
__module____qualname____firstlineno____doc__	__slots__r   r   __static_attributes____classdictcell____classdict__s   @r   r	   r	   #   s      	 I6 6r   r	   c                      a  ] tR t^9t o RtRtRR lt]RR l4       tR t	RR lt
R tR tR	 tR
 tR tR tRR ltR tRR ltRR ltR tR tR tR tRtV tR# )
BakedQueryz3A builder object for :class:`.query.Query` objects.c                `    RV n         V P                  W#4       V.V n        R V n        Wn        R# )FN )
_cache_key_update_cache_keysteps_spoiled_bakery)r   bakeryr   r   s   &&&&r   r   BakedQuery.__init__>   s,    z0 \
r   Nc                D    \        V \        P                  ! WR7      4      # )zCConstruct a new bakery.

:return: an instance of :class:`.Bakery`

)
size_alert)r	   r   LRUCache)r   size_size_alerts   &&&r   r-   BakedQuery.bakeryE   s     c4==FGGr   c                    \         P                  \         4      pV P                  Vn        \        V P                  4      Vn        V P
                  Vn        V P                  Vn        V# r   )r%   __new__r(   listr*   r,   r+   )r   b1s   & r   _cloneBakedQuery._cloneO   sH    
+

#\\
mm	r   c                \    V ;P                   VP                  3V,           ,          un         R # r   )r(   __code__r   fnr   s   &&&r   r)   BakedQuery._update_cache_keyW   s    BKK>D00r   c                x    \        V\        4      '       d   V P                  ! V!   V # V P                  V4       V # r   )
isinstancetupleadd_criteriar   others   &&r   __iadd__BakedQuery.__iadd__Z   s9    eU##u%  e$r   c                p    \        V\        4      '       d   V P                  ! V!  # V P                  V4      # r   )rA   rB   with_criteriarD   s   &&r   __add__BakedQuery.__add__a   s1    eU##%%u--%%e,,r   c                ^    V P                  W4       V P                  P                  V4       V # )zAdd a criteria function to this :class:`.BakedQuery`.

This is equivalent to using the ``+=`` operator to
modify a :class:`.BakedQuery` in-place.

)r)   r*   appendr=   s   &&*r   rC   BakedQuery.add_criteriag   s)     	r(

"r   c                F    V P                  4       P                  ! V.VO5!  # )zAdd a criteria function to a :class:`.BakedQuery` cloned from this
one.

This is equivalent to using the ``+`` operator to
produce a new :class:`.BakedQuery` with modifications.

)r9   rC   r=   s   &&*r   rI   BakedQuery.with_criteriar   s      {{}))"4t44r   c                    \        W4      # )zReturn a :class:`_baked.Result` object for this
:class:`.BakedQuery`.

This is equivalent to calling the :class:`.BakedQuery` as a
Python callable, e.g. ``result = my_baked_query(session)``.

)Resultr   sessions   &&r   for_sessionBakedQuery.for_session|   s     d$$r   c                $    V P                  V4      # r   )rU   rS   s   &&r   r   BakedQuery.__call__   s    ((r   c                    V'       gN   V P                   '       g<   V P                  4       pV;P                  R,          un        VP                  .V n        RV n         V # )a  Cancel any query caching that will occur on this BakedQuery object.

The BakedQuery can continue to be used normally, however additional
creational functions will not be cached; they will be called
on every invocation.

This is to support the case where a particular step in constructing
a baked query disqualifies the query from being cacheable, such
as a variant that relies upon some uncacheable value.

:param full: if False, only functions added to this
 :class:`.BakedQuery` object subsequent to the spoil step will be
 non-cached; the state of the :class:`.BakedQuery` up until
 this point will be pulled from the cache.   If True, then the
 entire :class:`_query.Query` object is built from scratch each
 time, with all creational functions being called on each
 invocation.

T)_query_only)r+   r9   r(   _retrieve_baked_queryr*   )r   full_spoil_points   && r   spoilBakedQuery.spoil   sH    ( DMMM;;=L##'77#&<<=DJr   c                >    V P                   VP                  3,           # )as  Return the key that actually goes into the cache dictionary for
this :class:`.BakedQuery`, taking into account the given
:class:`.Session`.

This basically means we also will include the session's query_class,
as the actual :class:`_query.Query` object is part of what's cached
and needs to match the type of :class:`_query.Query` that a later
session will want to use.

)r(   
_query_clsrS   s   &&r   _effective_keyBakedQuery._effective_key   s     '"4"4!666r   c                L    V P                  4       pVP                  WVR7       V# )z)Cloning version of _add_lazyload_options.)
cache_path)r9   _add_lazyload_options)r   optionseffective_pathre   qs   &&&& r   _with_lazyload_options!BakedQuery._with_lazyload_options   s%    KKM	JOr   c                ^  aa RpV'       g   SpS Fv  pVP                   '       g   VP                  '       g   K)  VP                  4       pVf   V P                  RR7       KQ  V^,          '       d   Q R4       hWF^ ,          ,          pKx  	  V P	                  VV3R lVP
                  V4       R# )a  Used by per-state lazy loaders to add options to the
"lazy load" query from a parent query.

Creates a cache key based on given load path and query options;
if a repeatable cache key cannot be generated, the query is
"spoiled" so that it won't use caching.

NT)r\   zloader options with variable bound parameters not supported with baked queries.  Please use new-style select() statements for cached ORM queries.c                 B   < V P                  S4      P                  ! S!  # r   )_with_current_pathrg   )ri   rh   rg   s   &r   <lambda>2BakedQuery._add_lazyload_options.<locals>.<lambda>   s    a**>:BBGLr   r'   )_is_legacy_option_is_compile_state_generate_cache_keyr^   rC   path)r   rg   rh   re   keyoptcks   &ff&   r   rf    BakedQuery._add_lazyload_options   s     'JC$$$(=(=(=,,.:JJDJ)!!uu '9 a5LC  	LOO	
r   c                    V P                   P                  V P                  V4      R 4      pVf?   V P                  V4      pVP	                  R 4      V P                   V P                  V4      &   VP	                  V4      # r   )r,   getrb   	_as_querywith_session)r   rT   querys   && r   r[    BakedQuery._retrieve_baked_query   sp      !4!4W!=tD=NN7+E9>9K9K:DLL,,W56 !!'**r   c                    V P                  V4      pR Vn        VP                  4       pVP                  P                  '       d!   VV3V P
                  V P                  V4      &   W#3# r   )r{   rT   _statement_20_compile_options_bake_okr,   rb   )r   rT   r}   	statements   &&  r   _bakeBakedQuery._bake   sg    w' '')	 %%...:DLL,,W56
 r   c                   \        V\        4      '       d   TpMX\        V\        4      '       d(   VP                  pVf   \        P
                  ! R4      hM\        R\        V4      ,          4      hV P                  V4      # )ah  Return the :class:`_query.Query` object for use as a subquery.

This method should be used within the lambda callable being used
to generate a step of an enclosing :class:`.BakedQuery`.   The
parameter should normally be the :class:`_query.Query` object that
is passed to the lambda::

    sub_bq = self.bakery(lambda s: s.query(User.name))
    sub_bq += lambda q: q.filter(User.id == Address.user_id).correlate(Address)

    main_bq = self.bakery(lambda s: s.query(Address))
    main_bq += lambda q: q.filter(sub_bq.to_query(q).exists())

In the case where the subquery is used in the first callable against
a :class:`.Session`, the :class:`.Session` is also accepted::

    sub_bq = self.bakery(lambda s: s.query(User.name))
    sub_bq += lambda q: q.filter(User.id == Address.user_id).correlate(Address)

    main_bq = self.bakery(
        lambda s: s.query(Address.id, sub_bq.to_query(q).scalar_subquery())
    )

:param query_or_session: a :class:`_query.Query` object or a class
 :class:`.Session` object, that is assumed to be within the context
 of an enclosing :class:`.BakedQuery` callable.


 .. versionadded:: 1.3


z1Given Query needs to be associated with a Sessionz)Query or Session object expected, got %r.)	rA   r   r   rT   sa_excArgumentError	TypeErrortyper{   )r   query_or_sessionrT   s   && r   to_queryBakedQuery.to_query   s    D &00&G(%00&..G**G  
 ;'()  ~~g&&r   c                |    V P                   ^ ,          ! V4      pV P                   R,           F  pV! V4      pK  	  V# )    :   NN)r*   )r   rT   r}   steps   &&  r   r{   BakedQuery._as_query-  s8    

1g&JJrNNDKE # r   )r,   r(   r+   r*   )r*   r,   r(   r+   )r'   )   N)Fr   )r   r   r   r   r   r   r   classmethodr-   r9   r)   rF   rJ   rC   rI   rU   r   r^   rb   rj   rf   r[   r   r   r{   r    r!   r"   s   @r   r%   r%   9   s     =<I H H1-	5%)67!
F+ 2/'b r   r%   c                      a  ] tR tRt o RtRtR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR tR tRtV tR# )rR   i6  a  Invokes a :class:`.BakedQuery` against a :class:`.Session`.

The :class:`_baked.Result` object is where the actual :class:`.query.Query`
object gets created, or retrieved from the cache,
against a target :class:`.Session`, and is then invoked for results.

c                :    Wn         W n        / V n        . V n        R # r   bqrT   _params_post_criteria)r   r   rT   s   &&&r   r   Result.__init__A  s     r   c                    \        V4      ^8X  d   VP                  V^ ,          4       M&\        V4      ^ 8  d   \        P                  ! R4      hV P                  P                  V4       V # )z@Specify parameters to be replaced into the string SQL statement.zFparams() takes zero or one positional argument, which is a dictionary.)lenupdater   r   r   )r   r   kws   &*,r   paramsResult.paramsG  s[     t9>IId1gY]&&)  	Br   c                L    V'       d   V P                   P                  V4       V # r   )r   extend)r   fnss   &&r   _using_post_criteriaResult._using_post_criteriaT  s    &&s+r   c                &    V P                  V.4      # )a|  Add a criteria function that will be applied post-cache.

This adds a function that will be run against the
:class:`_query.Query` object after it is retrieved from the
cache.    This currently includes **only** the
:meth:`_query.Query.params` and :meth:`_query.Query.execution_options`
methods.

.. warning::  :meth:`_baked.Result.with_post_criteria`
   functions are applied
   to the :class:`_query.Query`
   object **after** the query's SQL statement
   object has been retrieved from the cache.   Only
   :meth:`_query.Query.params` and
   :meth:`_query.Query.execution_options`
   methods should be used.


.. versionadded:: 1.2


)r   )r   r>   s   &&r   with_post_criteriaResult.with_post_criteriaY  s    . (("..r   c                    V P                   P                  V P                  4      P                  V P                  4      pV P
                   F  pV! V4      pK  	  V# r   )r   r{   rT   r   r   r   )r   ri   r>   s   &  r   r{   Result._as_queryr  sG    GGdll+224<<@%%B1A &r   c                4    \        V P                  4       4      # r   )strr{   r   s   &r   __str__Result.__str__x  s    4>>#$$r   c                >    V P                  4       P                  4       # r   )_iter__iter__r   s   &r   r   Result.__iter__{  s    zz|$$&&r   c                   V P                   pV P                  P                  '       d   VP                  '       d   V P	                  4       P                  4       # VP                  P                  VP                  V P                  4      R4      w  r#Vf   VP                  V P                  4      w  r#V P                  '       d   VP                  V P                  4      pMTpV P                   F  pV! V4      pK  	  VP                  p\        VP                  4      pVP                  RVP                   RVP                  /4       V P                  P#                  W6VR7      pVP$                  P                  RR4      '       d   VP'                  4       pVP$                  P                  RR4      '       d   VP)                  4       pV# )N_sa_orm_load_optionscompiled_cache)execution_optionsis_single_entityFfiltered)NN)r   rT   enable_baked_queriesr+   r{   r   r,   rz   rb   r   r   r   r   dict_execution_optionsr   load_optionsexecute_attributesscalarsunique)	r   r   r}   r   ri   r>   r   r   results	   &        r   r   Result._iter~  sj   WW||000BKKK>>#))++::>>dll+\
 =!xx5E<<<T\\*AA%%B1A &  !5!56  & "**	
 %%1B & 
 !!"4e<<^^%F!!*e44]]_Fr   c                  a \         P                  ! \        R4      4      oV P                  P	                  V3R l4      pVP                  V P                  4      P                  V P                  4      P                  4       # )zreturn the 'count'.

Equivalent to :meth:`_query.Query.count`.

Note this uses a subquery to ensure an accurate count regardless
of the structure of the original statement.

*c                 &   < V P                  S4      # r   )_legacy_from_self)ri   cols   &r   ro   Result.count.<locals>.<lambda>  s    Q-@-@-Er   )
r   countr   r   rI   rU   rT   r   r   scalar)r   r   r   s   & @r   r   Result.count  sX     jj,-WW""#EF~~dll+224<<@GGIIr   c                     V P                  4       p\        V\        P                  4      '       g   V# V^ ,          #   \        P
                   d     R# i ; i)zReturn the first element of the first result or None
if no rows present.  If multiple rows are returned,
raises MultipleResultsFound.

Equivalent to :meth:`_query.Query.scalar`.

N)onerA   collections_abcSequenceorm_excNoResultFound)r   rets   & r   r   Result.scalar  sK    	((*Cc?#;#;<<
q6M$$ 		s   1= = AAc                   V P                   P                  R 4      pVP                  V P                  4      P	                  V P
                  4      P                  V P                  4      P                  4       P                  4       # )zBReturn the first row.

Equivalent to :meth:`_query.Query.first`.

c                 &    V P                  ^ ^4      # )r   )slice)ri   s   &r   ro   Result.first.<locals>.<lambda>  s    QWWQ]r   )
r   rI   rU   rT   r   r   r   r   r   first)r   r   s   & r   r   Result.first  s[     WW""#:;NN4<<(VDLL!!!$"5"56UWUW	
r   c                >    V P                  4       P                  4       # )z[Return exactly one result or raise an exception.

Equivalent to :meth:`_query.Query.one`.

)r   r   r   s   &r   r   
Result.one       zz|!!r   c                >    V P                  4       P                  4       # )zwReturn one or zero results, or raise an exception for multiple
rows.

Equivalent to :meth:`_query.Query.one_or_none`.

)r   one_or_noner   s   &r   r   Result.one_or_none  s     zz|''))r   c                >    V P                  4       P                  4       # )z;Return all rows.

Equivalent to :meth:`_query.Query.all`.

)r   allr   s   &r   r   
Result.all  r   r   c                    V P                   P                  ^ ,          ! V P                  4      pVP                  WP                  4      # )zPRetrieve an object based on identity.

Equivalent to :meth:`_query.Query.get`.

)r   r*   rT   	_get_impl_load_on_pk_identity)r   identr}   s   && r   rz   
Result.get  s4     a .u&?&?@@r   c                  a aaaa VP                   ^ ,          P                  R,          oSP                  w  ooVVVVV 3R lpS P                  pVP	                  4       pV;P
                  S3,          un        TP                  T\        ;QJ d    . R S 4       F  NK  	  5M! R S 4       4      4      p\        SSP                  4       UUu/ uF  w  rxSV,          P                  VbK  	  p	pp\        VP                  S P                  4      P                  ! R/ V	B 4      p
\        V
4      pV^8  d   \         P"                  ! 4       hV'       d
   V
^ ,          # R# u uppi )z6Load the given primary key identity from the database.parententityc                   < SpV P                  4       pVP                  4        R Vn        R S
9   dW   \        S	P                  S
4       UUu0 uF  w  r4Ve   K  SV,          P
                  kK   	  ppp\        P                  ! W4      p\        P                  ! VRR/4      3Vn	        SP                   F  pV! V4      pK  	  V# u uppi )N
_orm_adaptT)r9   _get_condition	_order_byzipprimary_keyru   sql_utiladapt_criterion_to_null_deep_annotate_where_criteriar   )r}   _lcl_get_clauseri   r   valuenonesr>   _get_clause_get_paramsmapperprimary_key_identityr   s   &      r   setup*Result._load_on_pk_identity.<locals>.setup  s    )OAAK ++ '***,@''
 	 )K$(('   #+"B"B## '',9MN!A ))qE *H%s   CCc              3   (   "   T F  qR J x  K
  	  R # 5ir   r'   ).0elems   & r   	<genexpr>.Result._load_on_pk_identity.<locals>.<genexpr>&  s     G2F$2Fs   Nr'   )_raw_columns_annotationsr   r   r9   r(   rI   rB   r   r   ru   r7   rU   rT   r   r   r   MultipleResultsFound)r   rT   r}   r   r   r   r   id_valr   r   r   lr   r   r   s   f&&f,       @@@r   r   Result._load_on_pk_identity  s7    ##A&33NC#)#5#5 [	 	@ WW
 YY[
+'55G2FG55G2FGG
 (+$f&8&8(
(# $((&0( 	 
 bnnT\\299CFCDKq5..00!9
s   E)r   r   r   rT   Nr   )r   r   r   r   r   r   r   r   r   r   r{   r   r   r   r   r   r   r   r   r   rz   r   r    r!   r"   s   @r   rR   rR   6  sk      =I!
/2%'%NJ 
 "*"AA Ar   rR   )r   collections.abcabcr   logging r   r   r   ormr   	orm.queryr   orm.sessionr   sqlr   r   r   	getLoggerr   logr	   r%   rR   r-   r'   r   r   <module>r     sm    *       !    " !6 6,z zzA AH 
		r   