id1dZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lmZdd l m Z d gZ e jGd d eZdS)z|MapperProperty implementations. This is a private module which defines the behavior of individual ORM- mapped attributes. )absolute_import) attributes)PropComparator)StrategizedProperty)_orm_full_deannotate)log)util expressionColumnPropertyceZdZdZdZdZejdfdZej ddd Z d Z e d Z d Zfd ZdZejfdZdZGddejeZdZxZS)rzDescribes an object attribute that corresponds to a table column. Public constructor is the :func:`_orm.column_property` function. column) _orig_columnscolumnsgroupdeferred instrumentcomparator_factory descriptor extensionactive_historyexpire_on_flushinfodoc strategy_key_creation_order_is_polymorphic_discriminator_mapped_by_synonym_deferred_column_loader)z0.7z:class:`.AttributeExtension` is deprecated in favor of the :class:`.AttributeEvents` listener interface. The :paramref:`.column_property.extension` parameter will be removed in a future release.)rc Ftt|d|D|_d|D|_|dd|_|dd|_|dd|_|d |j j |_ |d d|_ |d d|_ |d d|_|d d|_d|vr|d|_d|vr|d|_n:t%|jD]}t'|dd}| ||_nd|_|rPt)|j jddt/|t3j|d|jfd|jff|_dS)a Provide a column-level property for use with a mapping. Column-based properties can normally be applied to the mapper's ``properties`` dictionary using the :class:`_schema.Column` element directly. Use this function when the given column is not directly present within the mapper's selectable; examples include SQL expressions, functions, and scalar SELECT queries. The :func:`_orm.column_property` function returns an instance of :class:`.ColumnProperty`. Columns that aren't present in the mapper's selectable won't be persisted by the mapper and are effectively "read-only" attributes. :param \*cols: list of Column objects to be mapped. :param active_history=False: When ``True``, indicates that the "previous" value for a scalar attribute should be loaded when replaced, if not already loaded. Normally, history tracking logic for simple non-primary-key scalar values only needs to be aware of the "new" value in order to perform a flush. This flag is available for applications that make use of :func:`.attributes.get_history` or :meth:`.Session.is_modified` which also need to know the "previous" value of the attribute. :param comparator_factory: a class which extends :class:`.ColumnProperty.Comparator` which provides custom SQL clause generation for comparison operations. :param group: a group name for this property when marked as deferred. :param deferred: when True, the column property is "deferred", meaning that it does not load immediately, and is instead loaded when the attribute is first accessed on an instance. See also :func:`~sqlalchemy.orm.deferred`. :param doc: optional string that will be applied as the doc on the class-bound descriptor. :param expire_on_flush=True: Disable expiry on flush. A column_property() which refers to a SQL expression (and not a single table-bound column) is considered to be a "read only" property; populating it has no effect on the state of data, and it can only return database state. For this reason a column_property()'s value is expired whenever the parent object is involved in a flush, that is, has any kind of "dirty" state within a flush. Setting this parameter to ``False`` will have the effect of leaving any existing value present after the flush proceeds. Note however that the :class:`.Session` with default expiration settings still expires all attributes after a :meth:`.Session.commit` call, however. :param info: Optional data dictionary which will be populated into the :attr:`.MapperProperty.info` attribute of this object. :param extension: an :class:`.AttributeExtension` instance, or list of extensions, which will be prepended to the list of attribute listeners for the resulting descriptor placed on the class. .. seealso:: :ref:`column_property_options` - to map columns while including mapping options :ref:`mapper_column_property_sql_expressions` - to map SQL expressions c6g|]}tj|S)r _labeled.0cs N/opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/orm/properties.py z+ColumnProperty.__init__..s#FFFj1!44FFFcPg|]#}tjt|$Sr$)r r%rr&s r)r*z+ColumnProperty.__init__..s9   =>J  4Q 7 7 8 8   r+rNrF _instrumentTrrrrrrrz* received unexpected keyword argument(s): z, r)superr__init__rrpoprrr __class__ Comparatorrrrrrrrreversedgetattr TypeError__name__joinsortedkeysr set_creation_orderr)selfrkwargscolrr1s r)r/zColumnProperty.__init__:s n nd##,,...FFgFFF  BI    ZZ..  :u55  **]D99"(** $.";# # !**\488K66$jj)95AA%zz*;TBB V   6**DI F??zz%((DHH --  c5$//?"DHE#   >***DIIfV[[]]6K6K,L,L,LN  %%% ' 4? + r+zsqlalchemy.orm.statezsqlalchemy.orm.strategiesc|j|jj||j|jSN) InstanceState"_instance_level_callable_processorparent class_managerLoadDeferredColumnskey)r;state strategiess r)&_memoized_attr__deferred_column_loaderz5ColumnProperty._memoized_attr__deferred_column_loaders="EE K %  * *48 4 4 H   r+c|jS)zsAllow the ColumnProperty to work in expression before it is turned into an instrumented attribute. r r;s r)__clause_element__z!ColumnProperty.__clause_element__s r+c|jdS)aReturn the primary column or expression for this ColumnProperty. E.g.:: class File(Base): # ... name = Column(String(64)) extension = Column(String(8)) filename = column_property(name + '.' + extension) path = column_property('C:/' + filename.expression) .. seealso:: :ref:`mapper_column_property_sql_expressions_composed` r)rrJs r)r zColumnProperty.expressions(|Ar+c|jsdStj|j|j|||||jdS)N) comparator parententityr)rrregister_descriptorclass_rErr)r;mappers r)instrument_classzColumnProperty.instrument_classsZ  F& M H..tV<<       r+c rtt|t|jdkrtt |jj|jrEtj d|jd|jdd|jdd|j d dSdSdS)Nrz On mapper z, primary key column 'z6' is being combined with distinct primary key column 'rz' in attribute 'zM'. Use explicit properties to give each column its own mapped attribute name.) r.rdo_initlenrsetrB primary_key issupersetr warnrE)r;r1s r)rUzColumnProperty.do_inits nd##++--- t|  q S)@%A%A%L%L L& &  II;;; Qa$((( L      ! r+cFt|j|j|j|jdS)N)rrr)rrrrrrJs r)copyzColumnProperty.copys2\]*.    r+cb||j|||S)N)passive)get_implrEget_committed_value)r;rFdict_rr^s r) _getcommittedzColumnProperty._getcommitteds6~~dh'';; 5'<   r+c ,|jsdS|j|vrO||j} |s | ||j<dS||j} | ||| ddS|jr)|j|vr"|||jgddSdSdS)NT) no_loader)rrEr_rW has_identity_expire_attributes) r;session source_state source_dict dest_state dest_dictload _recursive_resolve_conflict_mapvalueimpls r)mergezColumnProperty.merge s  F X $ $)E =&+ $(###!**4844Yt<<<<<  $ )B)B  ) )DH: *       )B)Br+c:eZdZdZdZdZdZdZdZdZ dZ d S) ColumnProperty.ComparatoraProduce boolean, comparison, and other operators for :class:`.ColumnProperty` attributes. See the documentation for :class:`.PropComparator` for a brief overview. .. seealso:: :class:`.PropComparator` :class:`.ColumnOperators` :ref:`types_operators` :attr:`.TypeEngine.comparator_factory` )rKr expressionsc|jr%||jjdS|jjd|j|jdS)Nr)rO parentmapper)adapterpropr _annotate _parententityrJs r)#_memoized_method___clause_element__z=ColumnProperty.Comparator._memoized_method___clause_element__:sb| ||DI$5a$8999y(+55(,(:(,(:r+cr|} |jS#t$r|jjcYSwxYw)z(The .info dictionary for this attribute.)rKrAttributeErrorrx)r;ces r)_memoized_attr_infoz-ColumnProperty.Comparator._memoized_attr_infoGsL((**B &w! & & &y~%%% &s 66crjrfdjjDSfdjjDS)zThe full sequence of columns referenced by this attribute, adjusted for any aliasing in progress. .. versionadded:: 1.3.17 c:g|]}|Sr$)rwr'r=r;s r)r*zHColumnProperty.Comparator._memoized_attr_expressions..Xs%GGGc S))GGGr+cjg|]/}|jjjjd0S))rOrvorm_key)ryrzrxrErs r)r*zHColumnProperty.Comparator._memoized_attr_expressions..\sV   MM,0,>,0,>'+y}   r+)rwrxrrJs`r)_memoized_attr_expressionsz4ColumnProperty.Comparator._memoized_attr_expressionsPs`| GGGGTY5FGGGG     $y0    r+cFt||S)zproxy attribute access down to the mapped column. this allows user-defined comparison methods to be accessed. )r4rK)r;rEs r)_fallback_getattrz+ColumnProperty.Comparator._fallback_getattrgs 42244c:: :r+c>||g|Ri|Sr?)rK)r;opotherr<s r)operatez!ColumnProperty.Comparator.operatens.2d--//B%BBB6BB Br+c f|}|||||fi|Sr?)rK _bind_param)r;rrr<r=s r)reverse_operatez)ColumnProperty.Comparator.reverse_operateqs;))++C2coob%00#@@@@ @r+N) r6 __module__ __qualname____doc__ __slots__r{rrrrrr$r+r)r2rs%s  $@     & & &   . ; ; ; C C C A A A A Ar+r2cTt|jjjdz|jzS)N.)strrBrQr6rErJs r)__str__zColumnProperty.__str__us$4;%.//#5@@r+)r6rrrstrategy_wildcard_keyrr deprecated_paramsr/ dependenciesrHrKpropertyr rSrUr\r PASSIVE_OFFrbrq MemoizedSlotsrr2r __classcell__)r1s@r)rrs %I(T w w w w w rT-/JKK  LK X*            -7,B    4NANANANANAT'NANANA`AAAAAAAr+N)r __future__rr interfacesrrr rr sqlr __all__ class_loggerrr$r+r)rs '&&&&&&&&&&&++++++&&&&&&  YAYAYAYAYA(YAYAYAYAYAr+