+
    iC                       R 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
 ^ 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 ^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" ^RI!H#t# ]'       da   ^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. ^R"I/H0t0 ^R#IH1t1 ^R$IH2t2 ^R%IH3t3 ^R&I4H5t5 ^R'I6H7t7 ^R(I8H9t9 ^R)I:H;t; R*R+.t<]! R,]R-7      t=]>t? ! R. R/]"4      t@ ! R0 R1]"4      tA ! R2 R+]]=,          4      tB ! R3 R*] 4      tC ! R4 R5]4      tDR6 R7 ltER8# )9a  Horizontal sharding support.

Defines a rudimental 'horizontal sharding' system which allows a Session to
distribute queries and persistence operations across multiple databases.

For a usage example, see the :ref:`examples_sharding` example included in
the source distribution.

.. deepalchemy:: The horizontal sharding extension is an advanced feature,
   involving a complex statement -> database interaction as well as
   use of semi-public APIs for non-trivial cases.   Simpler approaches to
   referring to multiple database "shards", most commonly using a distinct
   :class:`_orm.Session` per "shard", should always be considered first
   before using this more complex and less-production-tested system.



)annotations)Any)Callable)Dict)Iterable)Optional)Tuple)Type)TYPE_CHECKING)TypeVar)Union)event)exc)inspect)util)PassiveFlag)OrmExecuteOptionsParameter)	ORMOption)Mapper)Query)_BindArguments)_PKIdentityArgument)Session)Protocol)Self)
Connection)Engine)OptionEngine)IteratorResult)Result)LoaderCallableStatus)_O)BulkUDCompileState)QueryContext)_EntityBindKey)_SessionBind)ORMExecuteState)InstanceState)
Executable)_TP)ClauseElementShardedSessionShardedQuery_T)boundc                  "    ] tR t^PtR R ltRtR# )ShardChooserc               (    V ^8  d   QhRRRRRRRR/# )   mapperOptional[Mapper[_T]]instancer   clauseOptional[ClauseElement]return )formats   "yC:\Users\petid\OneDrive\Desktop\Maestro\MAESTRO\maestro-backend\venv\Lib\site-packages\sqlalchemy/ext/horizontal_shard.py__annotate__ShardChooser.__annotate__Q   s2      $  (	
 
    c                	    R # Nr9   )selfr3   r5   r6   s   &&&&r;   __call__ShardChooser.__call__Q   s    
 r>   r9   N__name__
__module____qualname____firstlineno__rB   __static_attributes__r9   r>   r;   r0   r0   P   s     r>   r0   c                  "    ] tR t^YtR R ltRtR# )IdentityChooserc               4    V ^8  d   QhRRRRRRRRR	R
RRRR/# r2   r3   z
Mapper[_T]primary_keyr   lazy_loaded_fromOptional[InstanceState[Any]]execution_optionsr   bind_argumentsr   kwr   r8   r9   )r:   s   "r;   r<   IdentityChooser.__annotate__Z   sP     	 		 )	
 7	 6	 '	 	 
	r>   c               	    R # r@   r9   )rA   r3   rN   rO   rQ   rR   rS   s   &&&$$$,r;   rB   IdentityChooser.__call__Z   s     r>   r9   NrD   r9   r>   r;   rK   rK   Y   s    	 	r>   rK   c                  >   a  ] tR t^ftRtR V 3R lltR R ltRtV ;t# )r,   a  Query class used with :class:`.ShardedSession`.

.. legacy:: The :class:`.ShardedQuery` is a subclass of the legacy
   :class:`.Query` class.   The :class:`.ShardedSession` now supports
   2.0 style execution via the :meth:`.ShardedSession.execute` method.

c               $    V ^8  d   QhRRRRRR/# )r2   argsr   kwargsr8   Noner9   )r:   s   "r;   r<   ShardedQuery.__annotate__o   s!      c S T r>   c                	   < \         SV `  ! V/ VB  \        V P                  \        4      '       g   Q hV P                  P
                  V n        V P                  P                  V n        R V n        R # r@   )super__init__
isinstancesessionr+   identity_chooserexecute_chooser	_shard_id)rA   rY   rZ   	__class__s   &*,r;   r_   ShardedQuery.__init__o   sW    $)&)$,,7777 $ = =#||;;r>   c                    V ^8  d   QhRRRR/# )r2   shard_idShardIdentifierr8   r   r9   )r:   s   "r;   r<   r\   w   s     = =/ =d =r>   c                &    V P                  VR7      # )ae  Return a new query, limited to a single shard ID.

All subsequent operations with the returned query will
be against the single shard regardless of other state.

The shard_id can be passed for a 2.0 style execution to the
bind_arguments dictionary of :meth:`.Session.execute`::

    results = session.execute(stmt, bind_arguments={"shard_id": "my_shard"})

)_sa_shard_id)rQ   )rA   rh   s   &&r;   	set_shardShardedQuery.set_shardw   s     %%8%<<r>   )rd   rc   rb   )	rE   rF   rG   rH   __doc__r_   rl   rI   __classcell__re   s   @r;   r,   r,   f   s     = =r>   c                     a  ] tR t^t$ R]R&   R]R&   R]R&   RRR]3RRR	R/R
 V 3R lllltR]P                  R]	P                  R3R V 3R llltR R ltRR R lltRRRRRRR/R R llltR R ltRtV ;t# )r+   r0   shard_chooserrK   rb   z*Callable[[ORMExecuteState], Iterable[Any]]rc   N
id_chooserquery_chooserc               <    V ^8  d   QhRRRRRRRRR	R
RRRRRRRR/	# )r2   rr   r0   rb   zOptional[IdentityChooser]rc   z4Optional[Callable[[ORMExecuteState], Iterable[Any]]]shardszOptional[Dict[str, Any]]	query_clszType[Query[_T]]rs   z<Optional[Callable[[Query[_T], Iterable[_T]], Iterable[Any]]]rt   z/Optional[Callable[[Executable], Iterable[Any]]]rZ   r   r8   r[   r9   )r:   s   "r;   r<   ShardedSession.__annotate__   sp     n. n.#n. 4n.
	n. )n. #n.
n. Gn. n. 
n.r>   c               h  <a aa \         SS `  ! RRV/VB  \        P                  ! S R\        RR7       VS n        V'       d,   Vo\        P                  ! RR4       R VV 3R llp	V	S n        M&V'       d	   VS n        M\        P                  ! R	4      hV'       dG   Vo\        P                  ! R
R4       V'       d   \        P                  ! R4      hR V3R llp
Vf   T
pVf   \        P                  ! R4      hVS n        / S n        Ve$   V F  pS P                  WV,          4       K  	  R# R# )aN  Construct a ShardedSession.

:param shard_chooser: A callable which, passed a Mapper, a mapped
  instance, and possibly a SQL clause, returns a shard ID.  This id
  may be based off of the attributes present within the object, or on
  some round-robin scheme. If the scheme is based on a selection, it
  should set whatever state on the instance to mark it in the future as
  participating in that shard.

:param identity_chooser: A callable, passed a Mapper and primary key
 argument, which should return a list of shard ids where this
 primary key might reside.

  .. versionchanged:: 2.0  The ``identity_chooser`` parameter
     supersedes the ``id_chooser`` parameter.

:param execute_chooser: For a given :class:`.ORMExecuteState`,
  returns the list of shard_ids
  where the query should be issued.  Results from all shards returned
  will be combined together into a single listing.

  .. versionchanged:: 1.4  The ``execute_chooser`` parameter
     supersedes the ``query_chooser`` parameter.

:param shards: A dictionary of string shard names
  to :class:`~sqlalchemy.engine.Engine` objects.

rw   do_orm_executeT)retvalzLThe ``id_chooser`` parameter is deprecated; please use ``identity_chooser``.z2.0c               4    V ^8  d   QhRRRRRRRRR	R
RRRR/# rM   r9   )r:   s   "r;   r<   -ShardedSession.__init__.<locals>.__annotate__   sN     3 3"303 #?	3
 $>3 !/3 3 3r>   c               h   < SP                  V 4      pV'       d   VP                  V4      pS! Wa4      # r@   )query_set_lazyload_from)	r3   rN   rO   rQ   rR   rS   q_id_chooserrA   s	   &&$$$, r;   _legacy_identity_chooser9ShardedSession.__init__.<locals>._legacy_identity_chooser   s2     JJv&#,,-=>A"122r>   z*identity_chooser or id_chooser is requiredzNThe ``query_chooser`` parameter is deprecated; please use ``execute_chooser``.z1.4z>Can't pass query_chooser and execute_chooser at the same time.c                    V ^8  d   QhRRRR/# )r2   orm_contextr&   r8   zIterable[Any]r9   )r:   s   "r;   r<   r}      s     = =,==r>   c                (   < S! V P                   4      # r@   )	statement)r   _query_choosers   &r;   _default_execute_chooser9ShardedSession.__init__.<locals>._default_execute_chooser   s     &k&;&;<<r>   Nz,execute_chooser or query_chooser is requiredr9   )r^   r_   r   listenexecute_and_instancesrr   r   warn_deprecatedrb   r   ArgumentErrorrc   _ShardedSession__shards
bind_shard)rA   rr   rb   rc   rv   rw   rs   rt   rZ   r   r   kr   r   re   s   f&&&&&$$,   @@r;   r_   ShardedSession.__init__   s5   X 	7977"$9$	
 +$K  33 3 %=D!$4D!##<  *N  2
 ''( 
= =
 &":"##>   /=?!9-  r>   c               <    V ^8  d   QhRRRRRRRRR	R
RRRRRRRR/	# )r2   r3   z
Mapper[_O]primary_key_identityzUnion[Any, Tuple[Any, ...]]identity_tokenOptional[Any]passiver   rO   rP   rQ   r   rR   zOptional[_BindArguments]rS   r   r8   z)Union[Optional[_O], LoaderCallableStatus]r9   )r:   s   "r;   r<   rx      sd     / // :/ &	/
 / 7/ 6/ 1/ / 
3/r>   c           	        < Ve   \         SV `  ! VV3RV/VB p	V	# T P                  TTTTV'       d   \        V4      M/ R7       F!  p
\         SV `  ! VV3RV
RV/VB pVf   K  Vu # 	  R# )a7  override the default :meth:`.Session._identity_lookup` method so
that we search for a given non-token primary key identity across all
possible identity tokens (e.g. shard ids).

.. versionchanged:: 1.4  Moved :meth:`.Session._identity_lookup` from
   the :class:`_query.Query` object to the :class:`.Session`.

Nr   )rO   rQ   rR   rO   )r^   _identity_lookuprb   dict)rA   r3   r   r   r   rO   rQ   rR   rS   objrh   obj2re   s   &&&&&&&&,   r;   r   ShardedSession._identity_lookup   s    ( %'*$  . 	C J 11$!1"37EtN32 2  w/( $, &6	
  #K" r>   c               (    V ^8  d   QhRRRRRRRR/# )r2   r3   Optional[_EntityBindKey[_O]]r5   r   rS   r8   r9   )r:   s   "r;   r<   rx   ,  s2      ,  	
 
r>   c                	&   VeW   \        V4      pVP                  '       d   VP                  ^,          pVf   Q hV# VP                  '       d   VP                  # \        V\        4      '       g   Q hV P
                  ! W3/ VB pVe   VXn        V# r@   )r   keyr   r`   r   rr   )rA   r3   r5   rS   statetokenrh   s   &&&,   r;   _choose_shard_and_assign'ShardedSession._choose_shard_and_assign,  s     H%Eyyy		!(((%%%+++&&))))%%f="=#+E r>   c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r2   r3   r4   r5   r   rh   Optional[ShardIdentifier]rS   r   r8   r   r9   )r:   s   "r;   r<   rx   A  s<      $   ,	
  
r>   c                R   Vf   V P                  W4      pV P                  4       '       d)   V P                  4       pVf   Q hVP                  WR7      # V P	                  WVR7      p\        V\        4      '       d   VP                  ! R/ VB # \        V\        4      '       g   Q hV# )zQProvide a :class:`_engine.Connection` to use in the unit of work
flush process.

)rh   )r3   rh   r5   r9   )	r   in_transactionget_transaction
connectionget_bindr`   r   connectr   )rA   r3   r5   rh   rS   transbinds   &&&&,  r;   connection_callable"ShardedSession.connection_callableA  s     44VFH  ((*E$$$##F#>>==8 ! D $''||)b))!$
3333r>   rh   r5   r6   c               0    V ^8  d   QhRRRRRRRRR	R
RR/# )r2   r3   r   rh   r   r5   r   r6   r7   rS   r   r8   r%   r9   )r:   s   "r;   r<   rx   _  sF     ' ',' ,	'
  ' (' ' 
'r>   c               	b    Vf   V P                  WVR7      pVf   Q hV P                  V,          # )N)r5   r6   )r   r   )rA   r3   rh   r5   r6   rS   s   &&$$$,r;   r   ShardedSession.get_bind_  sA     44& 5 H '''}}X&&r>   c               $    V ^8  d   QhRRRRRR/# )r2   rh   ri   r   zUnion[Engine, OptionEngine]r8   r[   r9   )r:   s   "r;   r<   rx   o  s$     ' '''/J'	'r>   c                	"    W P                   V&   R # r@   )r   )rA   rh   r   s   &&&r;   r   ShardedSession.bind_shardo  s     #'hr>   )__shardsrc   rb   rr   )NNNr@   )rE   rF   rG   rH   __annotations__r,   r_   r   PASSIVE_OFFr   
EMPTY_DICTr   r   r   r   r   rI   ro   rp   s   @r;   r+   r+      s    %%??
 7; +/%1n. n. JNn. n.h )-*669=8<37/ /b*<' /3	'
 #'' +/' ' ' 'r>   c                  .    ] tR tRtRtRtRR R lltRtR# )	set_shard_idiu  a  a loader option for statements to apply a specific shard id to the
primary query as well as for additional relationship and column
loaders.

The :class:`_horizontal.set_shard_id` option may be applied using
the :meth:`_sql.Executable.options` method of any executable statement::

    stmt = (
        select(MyObject)
        .where(MyObject.name == "some name")
        .options(set_shard_id("shard1"))
    )

Above, the statement when invoked will limit to the "shard1" shard
identifier for the primary query as well as for all relationship and
column loading strategies, including eager loaders such as
:func:`_orm.selectinload`, deferred column loaders like :func:`_orm.defer`,
and the lazy relationship loader :func:`_orm.lazyload`.

In this way, the :class:`_horizontal.set_shard_id` option has much wider
scope than using the "shard_id" argument within the
:paramref:`_orm.Session.execute.bind_arguments` dictionary.


.. versionadded:: 2.0.0

c                    V ^8  d   QhRRRR/# )r2   rh   ri   propagate_to_loadersboolr9   )r:   s   "r;   r<   set_shard_id.__annotate__  s     9 9'9?C9r>   c                    Wn         W n        R# )a   Construct a :class:`_horizontal.set_shard_id` option.

:param shard_id: shard identifier
:param propagate_to_loaders: if left at its default of ``True``, the
 shard option will take place for lazy loaders such as
 :func:`_orm.lazyload` and :func:`_orm.defer`; if False, the option
 will not be propagated to loaded objects. Note that :func:`_orm.defer`
 always limits to the shard_id of the parent row in any case, so the
 parameter only has a net effect on the behavior of the
 :func:`_orm.lazyload` strategy.

Nrh   r   )rA   rh   r   s   &&&r;   r_   set_shard_id.__init__  s     !$8!r>   )r   rh   Nr   )T)rE   rF   rG   rH   rn   	__slots__r_   rI   r9   r>   r;   r   r   u  s    8 5I9 9r>   r   c                    V ^8  d   QhRRRR/# )r2   r   r&   r8   &Union[Result[_T], IteratorResult[_TP]]r9   )r:   s   "r;   r<   r<     s     7. 7. 7.+7.r>   c                  a  S P                   '       d   S P                  pM3S P                  '       g   S P                  '       d   S P                  pMR pS P
                  p\        V\        4      '       g   Q hR V 3R llpS P                   F'  p\        V\        4      '       g   K  VP                  p Mq	  V'       d   VP                  e   VP                  pMLRS P                  9   d   S P                  R,          pM'RS P                  9   d   S P                  R,          pMR pVe	   V! V4      # . pVP                  S 4       F  pV! V4      pVP                  V4       K  	  V^ ,          P                   ! VR,          !  # )Nc                    V ^8  d   QhRRRR/# )r2   rh   ri   r8   r   r9   )r:   s   "r;   r<   +execute_and_instances.<locals>.__annotate__  s      K K!K	/Kr>   c                ~   < \        SP                  4      pWR &   SP                  V R7       SP                  VR7      # )rh   )r   )rR   )r   rR   update_execution_optionsinvoke_statement)rh   rR   r   s   & r;   iter_for_shard-execute_and_instances.<locals>.iter_for_shard  sB     k889%-z",,H,E++>+JJr>   rk   rh   :   NN)	is_selectload_options	is_update	is_deleteupdate_delete_optionsra   r`   r+   _non_compile_orm_optionsr   rh   _identity_tokenrQ   rR   rc   appendmerge)r   active_optionsra   r   orm_optrh   partialresult_s   f       r;   r   r     sT    $11				+"7"7"7$::!!Gg~....K K 77 g|,,''H 8 n<<H%55H{<<<"44^DH;555"11*=HHh''//<H$X.GNN7# = qz--r>   N)Frn   
__future__r   typingr   r   r   r   r   r   r	   r
   r   r    r   r   r   r   ormr   orm._typingr   orm.interfacesr   
orm.mapperr   	orm.queryr   orm.sessionr   r   r   util.typingr   r   engine.baser   r   r   engine.resultr   r   r    r!   orm.bulk_persistencer"   orm.contextr#   r$   r%   r&   	orm.stater'   sqlr(   sql._typingr)   sql.elementsr*   __all__r-   strri   r0   rK   r,   r+   r   r   r9   r>   r;   <module>r      s   $ #                 4 &   ( - ! " ($*.&* 9*,*-) !,^
,T 8 
h 
=59 =@l'W l'^/99 /9d7.r>   