U a;@sdZddlmZddlmZddlmZddlmZddlmZddl m Z dd l m Z dd l m Z dd lmZd d lmZd dlmZd dlmZd dlmZdddddgZejGddde ZdS)z|MapperProperty implementations. This is a private module which defines the behavior of individual ORM- mapped attributes. )absolute_import) attributes)CompositeProperty)ConcreteInheritedProperty)SynonymProperty)PropComparator)StrategizedProperty)RelationshipProperty)_orm_full_deannotate)log)util) coercions)rolesColumnPropertyrrr rcseZdZdZdZdZdZfddZddZe d d d d Z e d d d dZ ddZ eddZddZfddZddZejfddZddZGddde jeZdd ZZS)!rzDescribes an object attribute that corresponds to a table column. Public constructor is the :func:`_orm.column_property` function. columnT) _orig_columnscolumnsgroupdeferred instrumentcomparator_factory descriptoractive_historyexpire_on_flushinfodoc strategy_keyZ_creation_orderZ_is_polymorphic_discriminatorZ_mapped_by_synonymZ_deferred_column_loaderZ_raise_column_loaderZ_renders_in_subqueries raiseloadcsdtt|dd|D|_dd|D|_|dd|_|dd|_|dd|_|d d |_ |d |j j |_ |d d|_ |d d|_|dd |_d|kr|d|_d|kr|d|_n6t|jD]$}t|dd}|dk r||_qqd|_|r*td|j jdt|ft|d|jfd|j ff|_|jr`|jd7_dS)a4Provide 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 raiseload: if True, indicates the column should raise an error when undeferred, rather than loading the value. This can be altered at query time by using the :func:`.deferred` option with raiseload=False. .. versionadded:: 1.4 .. seealso:: :ref:`deferred_raiseload` .. seealso:: :ref:`column_property_options` - to map columns while including mapping options :ref:`mapper_column_property_sql_expressions` - to map SQL expressions cSsg|]}ttj|qS)rexpectrLabeledColumnExprRole.0cr r ZC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\orm\properties.py sz+ColumnProperty.__init__..cSsg|]}ttjt|qSr )rr!rr"r r#r r r&r's rNrFrZ _instrumentTrrrrrrz.%s received unexpected keyword argument(s): %sz, r))rT)superr__init__rrpoprrrr __class__ Comparatorrrrrrrreversedgetattr TypeError__name__joinsortedkeysrZset_creation_orderr)selfrkwargscolrr+r r&r)HsPT   zColumnProperty.__init__cCsd|jkp||jjkS)N)rT)rparentZ_readonly_propsr4r r r&%_memoized_attr__renders_in_subqueriess  z4ColumnProperty._memoized_attr__renders_in_subquerieszsqlalchemy.orm.statezsqlalchemy.orm.strategiescCs.tjj}tjj}|j|jj||j |j SN rZ preloadedZ orm_stateZorm_strategiesZ InstanceStateZ"_instance_level_callable_processorr8Z class_managerZLoadDeferredColumnskeyr4stateZ strategiesr r r&&_memoized_attr__deferred_column_loaders z5ColumnProperty._memoized_attr__deferred_column_loadercCs0tjj}tjj}|j|jj||j d|j S)NTr<r>r r r&#_memoized_attr__raise_column_loaders z2ColumnProperty._memoized_attr__raise_column_loadercCs|jS)zsAllow the ColumnProperty to work in expression before it is turned into an instrumented attribute. ) expressionr9r r r&__clause_element__sz!ColumnProperty.__clause_element__cCs |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)rr9r r r&rBszColumnProperty.expressioncCs0|js dStj|j|j|||||jddS)N)Z comparator parententityr)rrZregister_descriptorclass_r=rr)r4Zmapperr r r&instrument_classs zColumnProperty.instrument_classcsZtt|t|jdkrVt|jj|jrVt d|j|jd|jd|j fdS)NrzOn mapper %s, primary key column '%s' is being combined with distinct primary key column '%s' in attribute '%s'. Use explicit properties to give each column its own mapped attribute name.r) r(rdo_initlenrsetr8Z primary_key issupersetrwarnr=r9r7r r&rGszColumnProperty.do_initcCst|j|j|j|jdS)N)rrr)rrrrrr9r r r&copy s zColumnProperty.copycCs||jj|||dS)N)passive)get_implr=Zget_committed_value)r4r?Zdict_rrMr r r& _getcommitted(s  zColumnProperty._getcommittedc Cst|js dS|j|krL||j} |s.| ||j<qp||j} | ||| dn$|jrp|j|krp|j||jgdddS)NT)Z no_loader)rr=rNrIZ has_identityZ_expire_attributes) r4sessionZ source_stateZ source_dictZ dest_stateZ dest_dictload _recursiveZ_resolve_conflict_mapvalueimplr r r&merge/s     zColumnProperty.mergec@sLeZdZdZdZddZddZddZd d Zd d Z d dZ ddZ dS)zColumnProperty.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` )rCrZ expressionscCsT|j}||||jjd}|}|jjr>|}|jj|}||d<||d|dS)aannotate and possibly adapt a column to be returned as the mapped-attribute exposed version of the column. The column in this context needs to act as much like the column in an ORM mapped context as possible, so includes annotations to give hints to various ORM functions as to the source entity of this column. It also adapts it to the mapper's with_polymorphic selectable if one is present. )Zentity_namespacerDZ parentmapper proxy_keyZ adapt_columnZorm)Zcompile_state_pluginZplugin_subject)Z _parententitypropr=Z _parentmapperZ_polymorphic_adapterZtraverseZ _annotateZ_set_propagate_attrs)r4rpe annotationsr6Zmapper_local_colr r r&_orm_annotate_column^s  z.ColumnProperty.Comparator._orm_annotate_columncCs4|jr||jjd|jjS||jjdSdS)Nr)adapterrWrr=rZr9r r r&#_memoized_method___clause_element__sz=ColumnProperty.Comparator._memoized_method___clause_element__cCs2|}z|jWStk r,|jjYSXdS)z(The .info dictionary for this attribute.N)rCrAttributeErrorrW)r4Zcer r r&_memoized_attr_infos z-ColumnProperty.Comparator._memoized_attr_infocs6jrfddjjDSfddjjDSdS)zThe full sequence of columns referenced by this attribute, adjusted for any aliasing in progress. .. versionadded:: 1.3.17 csg|]}|jjqSr )r[rWr=r$r6r9r r&r'szHColumnProperty.Comparator._memoized_attr_expressions..csg|]}|qSr )rZr_r9r r&r'sN)r[rWrr9r r9r&_memoized_attr_expressionss  z4ColumnProperty.Comparator._memoized_attr_expressionscCst||S)zproxy attribute access down to the mapped column. this allows user-defined comparison methods to be accessed. )r.rC)r4r=r r r&_fallback_getattrsz+ColumnProperty.Comparator._fallback_getattrcOs||f||Sr;)rC)r4opotherr5r r r&operatesz!ColumnProperty.Comparator.operatecKs|}|||||f|Sr;)rCZ _bind_param)r4rbrcr5r6r r r&reverse_operatesz)ColumnProperty.Comparator.reverse_operateN) r0 __module__ __qualname____doc__ __slots__rZr\r^r`rardrer r r r&r,Is( r,cCst|jjjd|jS)N.)strr8rEr0r=r9r r r&__str__szColumnProperty.__str__)r0rfrgrhZstrategy_wildcard_keyZ inherit_cacherir)r:rZpreload_moduler@rArCpropertyrBrFrGrLrZ PASSIVE_OFFrOrUZ MemoizedSlotsrr,rl __classcell__r r r7r&r's,        kN)rh __future__rrZdescriptor_propsrrrZ interfacesrr Z relationshipsr rr r Zsqlrr__all__Z class_loggerrr r r r&s*