o
    E6d"                     @  sp  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
 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 ddlmZ ddlmZ ddl	mZ ddlmZ ervddlmZ ededZG dd deZG dd deZejj ddG dd deZ!G d d! d!ee Z"G d"d# d#e"e ee Z#d$d% Z$d&S )'zDynamic collection API.

Dynamic collections act like Query() objects for read operations and support
basic add/delete mutation.

.. legacy:: the "dynamic" loader is a legacy feature, superseded by the
 "write_only" loader.


    )annotations)Any)Iterable)Iterator)TYPE_CHECKING)TypeVar   )
attributes)exc)relationships)util)Query)object_session)AbstractCollectionWriter)WriteOnlyAttributeImpl)WriteOnlyHistory)WriteOnlyLoader   )result)Session_T)boundc                   @  s   e Zd ZdddZdS )DynamicCollectionHistoryNc                 C  sb   |rt ||d}t|| _|j| _|j| _d| _d S t | _t | _t | _d| _d S )NFT)AppenderQuery	autoflushr   ZOrderedIdentitySetZunchanged_itemsadded_itemsZdeleted_itemsZ_reconcile_collection)selfattrstateZpassiveZapply_toZcoll r   mC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\sqlalchemy/orm/dynamic.py__init__2   s   




z!DynamicCollectionHistory.__init__N)__name__
__module____qualname__r!   r   r   r   r    r   1   s    r   c                   @  s    e Zd ZdZeZ	dddZdS )DynamicAttributeImplTNc           	      K  sb   t jj| ||||fi | || _|rt|| _|st| _d S t|	 v r*|| _d S t
|| _d S r"   )r	   ZAttributeImplr!   target_mappertupleorder_byr   query_classAppenderMixinmromixin_user_query)	r   class_keyZtypecallabledispatchr'   r)   r*   kwr   r   r    r!   D   s   



zDynamicAttributeImpl.__init__r"   )r#   r$   r%   Z_supports_dynamic_iterationr   Zcollection_history_clsr!   r   r   r   r    r&   @   s
    
r&   Zdynamic)Zlazyc                   @  s   e Zd ZeZdS )
DynaLoaderN)r#   r$   r%   r&   Z
impl_classr   r   r   r    r2   ]   s    r2   c                      s   e Zd ZdZdZ fddZed(ddZejd)ddZdd Z	e
r(d*ddZd+ddZd,ddZd-ddZd.ddZd/d d!Zd.d"d#Zd/d$d%Zd/d&d'Z  ZS )0r+   zTA mixin that expects to be mixing in a Query class with
    AbstractAppender.


    Nc                   s"   t | |jd  t || d S r"   )r   r!   r'   super)r   r   r   	__class__r   r    r!   k   s   zAppenderMixin.__init__returnr   c                 C  sD   t | j}|d ur| jr|jr| j|v r|  t| js d S |S r"   )r   instancer   flushorm_utilZhas_identityr   sessr   r   r    sessiono   s   

zAppenderMixin.sessionr<   Nonec                 C  s
   || _ d S r"   )r;   )r   r<   r   r   r    r<   ~   s   
c                 C  sz   | j }|d u r6t| j}|jrtdt|  t	j
t	| jjjg| jt| jtjjdd S | | S )NzInstance %s is detached, dynamic relationship cannot return a correct result.   This warning will become a DetachedInstanceError in a future release.T)Z_source_supports_scalars)r<   r	   instance_stater7   Zdetachedr   warnr9   	state_strr   ZIteratorResultZSimpleResultMetaDatar   r.   r#   _get_collection_historyPASSIVE_NO_INITIALIZEr   Zscalars	_generate_iter)r   r;   r   r   r   r    rD      s*   
	zAppenderMixin._iterIterator[_T]c                 C  s   d S r"   r   )r   r   r   r    __iter__   s   zAppenderMixin.__iter__indexr   r   c                 C  s<   | j }|d u r| jt| jtj|S | |	|S r"   )
r<   r   rA   r	   r>   r7   rB   ZindexedrC   __getitem__)r   rG   r;   r   r   r    rH      s   
zAppenderMixin.__getitem__intc                 C  s:   | j }|d u rt| jt| jtjjS | 	|
 S r"   )r<   lenr   rA   r	   r>   r7   rB   r   rC   countr:   r   r   r    rK      s   
zAppenderMixin.countc                 C  s~   | j }|d u rt|}|d u rtdt|| jjf | jr*| j| jj	|d}n|
| jj	}| j|_| j|_| j|_|S )NzParent instance %s is not bound to a Session, and no contextual session is established; lazy load operation of attribute '%s' cannot proceed)r<   )r7   r   orm_excZDetachedInstanceErrorr9   Zinstance_strr   r/   r*   r'   queryZ_where_criteriaZ	_from_objZ_order_by_clauses)r   r;   r7   rM   r   r   r    rC      s    zAppenderMixin._generateiteratorIterable[_T]c                 C     |  | dS )a~  Add an iterable of items to this :class:`_orm.AppenderQuery`.

        The given items will be persisted to the database in terms of
        the parent instance's collection on the next flush.

        This method is provided to assist in delivering forwards-compatibility
        with the :class:`_orm.WriteOnlyCollection` collection class.

        .. versionadded:: 2.0

        NZ_add_all_implr   rN   r   r   r    add_all   s   zAppenderMixin.add_allitemc                 C     |  |g dS )ap  Add an item to this :class:`_orm.AppenderQuery`.

        The given item will be persisted to the database in terms of
        the parent instance's collection on the next flush.

        This method is provided to assist in delivering forwards-compatibility
        with the :class:`_orm.WriteOnlyCollection` collection class.

        .. versionadded:: 2.0

        NrQ   r   rT   r   r   r    add   s   zAppenderMixin.addc                 C  rP   )zAdd an iterable of items to this :class:`_orm.AppenderQuery`.

        The given items will be persisted to the database in terms of
        the parent instance's collection on the next flush.

        NrQ   rR   r   r   r    extend      zAppenderMixin.extendc                 C  rU   )zAppend an item to this :class:`_orm.AppenderQuery`.

        The given item will be persisted to the database in terms of
        the parent instance's collection on the next flush.

        NrQ   rV   r   r   r    append   s   zAppenderMixin.appendc                 C  rP   )zRemove an item from this :class:`_orm.AppenderQuery`.

        The given item will be removed from the parent instance's collection on
        the next flush.

        N)Z_remove_implrV   r   r   r    remove   rY   zAppenderMixin.remove)r6   r   )r<   r   r6   r=   )r6   rE   )rG   r   r6   r   )r6   rI   r"   )rN   rO   r6   r=   )rT   r   r6   r=   )r#   r$   r%   __doc__r*   r!   propertyr<   setterrD   r   rF   rH   rK   rC   rS   rW   rX   rZ   r[   __classcell__r   r   r4   r    r+   b   s&    








		r+   c                   @  s   e Zd ZdZdS )r   zA dynamic query that supports basic collection storage operations.

    Methods on :class:`.AppenderQuery` include all methods of
    :class:`_orm.Query`, plus additional methods used for collection
    persistence.


    N)r#   r$   r%   r\   r   r   r   r    r     s    r   c                 C  s   d| j  }t|t| fd| iS )zAReturn a new class with AppenderQuery functionality layered over.ZAppenderr*   )r#   typer+   )clsnamer   r   r    r-     s   
r-   N)%r\   
__future__r   typingr   r   r   r   r    r	   r
   rL   r   r   r9   rM   r   r<   r   Z	writeonlyr   r   r   r   Zenginer   r   r   r   r&   ZRelationshipPropertyZstrategy_forr2   r+   r   r-   r   r   r   r    <module>   s<   	 %