zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
U
¸ý°dÂ"ã@spdZddlmZddlmZddlmZddlmZddlmZddlmZdd    l    m
Z
dd
l    m Z dd l    m Z dd l    mZdd lmZddlmZddlmZddlmZddlmZddlmZdd l    mZddlmZerìddlmZededZGdd„deƒZGdd„deƒZe jj ddGdd„deƒƒZ!Gd d!„d!eeƒZ"Gd"d#„d#e"eeeƒZ#d$d%„Z$d&S)'zâDynamic 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@seZdZddd„ZdS)ÚDynamicCollectionHistoryNcCs`|r8t||ƒ d¡}t |¡|_|j|_|j|_d|_n$t ¡|_t ¡|_t ¡|_d|_dS)NFT)Ú AppenderQueryÚ    autoflushr ZOrderedIdentitySetZunchanged_itemsÚ added_itemsZ deleted_itemsZ_reconcile_collection)ÚselfÚattrÚstateZpassiveZapply_toZcoll©rúMd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/orm/dynamic.pyÚ__init__2s 
 
 
z!DynamicCollectionHistory.__init__)N)Ú__name__Ú
__module__Ú __qualname__r!rrrr r1src@seZdZdZeZddd„ZdS)ÚDynamicAttributeImplTNc    KsZtjj|||||f|Ž||_|r,t|ƒ|_|s8t|_nt|     ¡krL||_n
t
|ƒ|_dS©N) r    Z AttributeImplr!Ú target_mapperÚtupleÚorder_byrÚ query_classÚ AppenderMixinÚmroÚmixin_user_query)    rÚclass_ÚkeyZ typecallableÚdispatchr'r)r*Úkwrrr r!Ds" ÿÿ
 zDynamicAttributeImpl.__init__)N)r"r#r$Z_supports_dynamic_iterationrZcollection_history_clsr!rrrr r%@s
ør%Zdynamic)Zlazyc@seZdZeZdS)Ú
DynaLoaderN)r"r#r$r%Z
impl_classrrrr r2]sr2csÞeZdZdZdZ‡fdd„Zeddœdd„ƒZejdd    d
œd d„ƒZd d „Z    e
r^ddœdd„Z dddœdd„Z ddœdd„Z d(dd„Zdd    dœdd„Zdd    dœd d!„Zdd    dœd"d#„Zdd    dœd$d%„Zdd    dœd&d'„Z‡ZS))r+zTA mixin that expects to be mixing in a Query class with
    AbstractAppender.
 
 
    Ncs"t ||jd¡tƒ ||¡dSr&)r r!r'Úsuper)rrr©Ú    __class__rr r!kszAppenderMixin.__init__r)ÚreturncCsHt|jƒ}|dk    r0|jr0|jr0|j|kr0| ¡t |j¡s@dS|SdSr&)rÚinstancerÚflushÚorm_utilZ has_identity©rÚsessrrr Úsessionos
ÿþýü zAppenderMixin.sessionÚNone)r<r6cCs
||_dSr&)r;)rr<rrr r<~scCs~|j}|dkrlt |j¡}|jr4t dt |¡¡t    j
t      |j j jg¡|j  t |j¡tj¡jdd ¡S| |¡ ¡SdS)Nz•Instance %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_stater7Zdetachedr Úwarnr9Z    state_strrZIteratorResultZSimpleResultMetaDatarr.r"Ú_get_collection_historyÚPASSIVE_NO_INITIALIZErZscalarsÚ    _generateÚ_iter)rr;rrrr rC‚s$ ýÿ
þú
    zAppenderMixin._iterz Iterator[_T]cCsdSr&r)rrrr Ú__iter__›szAppenderMixin.__iter__rr)Úindexr6cCs@|j}|dkr,|j t |j¡tj¡ |¡S| |¡     |¡SdSr&)
r<rr@r    r>r7rAZindexedrBÚ __getitem__)rrEr;rrr rFžs
þýzAppenderMixin.__getitem__ÚintcCs>|j}|dkr,t|j t |j¡tj¡jƒS|     |¡ 
¡SdSr&) r<Úlenrr@r    r>r7rArrBÚcountr:rrr rI¨s
þÿzAppenderMixin.countcCs~|j}|dkr:t|ƒ}|dkr:t dt |¡|jjf¡‚|jrT|j|jj    |d}n| 
|jj    ¡}|j |_ |j |_ |j |_ |S)NzŒParent instance %s is not bound to a Session, and no contextual session is established; lazy load operation of attribute '%s' cannot proceed)r<)r7rÚorm_excZDetachedInstanceErrorr9Z instance_strrr/r*r'ÚqueryZ_where_criteriaZ    _from_objZ_order_by_clauses)rr;r7rKrrr rB´s ýÿzAppenderMixin._generatez Iterable[_T])Úiteratorr6cCs| |¡dS)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©rrLrrr Úadd_allÎs zAppenderMixin.add_all)Úitemr6cCs| |g¡dS)apAdd 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
 
        NrM©rrPrrr ÚaddÜs zAppenderMixin.addcCs| |¡dS)zÊ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.
 
        NrMrNrrr ÚextendêszAppenderMixin.extendcCs| |g¡dS)z¿Append 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.
 
        NrMrQrrr ÚappendószAppenderMixin.appendcCs| |¡dS)z¨Remove 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_implrQrrr ÚremoveüszAppenderMixin.remove)N)r"r#r$Ú__doc__r*r!Úpropertyr<ÚsetterrCrrDrFrIrBrOrRrSrTrUÚ __classcell__rrr4r r+bs$ 
 
        r+c@seZdZdZdS)rzÞA 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$rVrrrr rsrcCsd|j}t|t|fd|iƒS)zAReturn a new class with AppenderQuery functionality layered over.ZAppenderr*)r"Útyper+)ÚclsÚnamerrr r-s
r-N)%rVÚ
__future__rÚtypingrrrrrÚr    r
rJr r r9rKr r<rZ    writeonlyrrrrZenginerrrrr%ZRelationshipPropertyZ strategy_forr2r+rr-rrrr Ú<module>
s:                     %