o
    Šåg©Á ã                   @  sp  d dl mZ d dl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 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+ dd(l,m-Z- dd)l,m.Z. dd*l,m/Z/ dd+l,m0Z0 dd,l1m2Z2 dd-l1m3Z3 dd.l1m4Z4 dd/l1m5Z5 dd0l1m6Z6 dd1l1m7Z7 dd2l8m9Z9 dd3l:m;Z; dd4l:m<Z< dd5l=m>Z> dd6l=m?Z? dd7l=m@Z@ dd8l=mAZA dd9l=mBZB dd:l=mCZC dd;l=mDZD dd<l=mEZE dd=lFmGZG e�rÛdd>lHmIZI dd?lHmJZJ dd@lmKZK ddAlLmMZM ddBlNmOZO ddClPmQZQ ddDlPmRZR ddElSmTZT ddFlUmVZV ddGl,mWZW ddHlXmYZY ddIl8mZZZ ddJl:m[Z[ ddKl=m\Z\ ddLl=m]Z] ddMl=m^Z^ ddNl=m_Z_ ddOl=m`Z` ddPlambZb edQedR�ZcejdZee f¡ ZgeCjhZhG dSdT„ dTƒZie fdUdVi¡ZjG dWdX„ dXe4ƒZkG dYdZ„ dZekƒZlG d[d\„ d\ekƒZmG d]d^„ d^ƒZnG d_d`„ d`enƒZoG dadb„ dbenƒZpe&jj4 qdcdd¡G dedf„ dfemƒƒZrG dgdh„ dhe;e6eEe- ƒZse&jj4 qdcdi¡G djdk„ dkele>ƒƒZte&jj4 qdcdl¡G dmdn„ dnemeDƒƒZu		od•d–dxdy„Zvd—d}d~„Zwd—dd€„Zx	d˜d™d…d†„ZyG d‡dˆ„ dˆƒZzG d‰dŠ„ dŠezƒZ{G d‹dŒ„ dŒezƒZ|G d�dŽ„ dŽezƒZ}G d�d�„ d�e}ƒZ~G d‘d’„ d’e}ƒZG d“d”„ d”eƒZ€dS )šé    )ÚannotationsN)ÚAny)Úcast)ÚDict)ÚIterable)ÚList)ÚOptional)ÚSet)ÚTuple)ÚType)ÚTYPE_CHECKING)ÚTypeVar)ÚUnioné   )Ú
attributes)Ú
interfaces)Úloading)Ú_is_aliased_class)ÚORMColumnDescription)ÚORMColumnsClauseRole)ÚPathRegistry)Ú_entity_corresponds_to)Ú_ORMJoin)Ú_TraceAdaptRole)ÚAliasedClass)ÚBundle)Ú
ORMAdapter)ÚORMStatementAdapteré   )Úexc)Úfuture)Úinspect)Úsql)Úutil)Ú	coercions)Ú
expression)Úroles)Úvisitors)Ú_TP)Úis_dml)Úis_insert_update)Úis_select_base)Ú_select_iterables)ÚCacheableOptions)ÚCompileState)Ú
Executable)Ú
Generative)ÚOptions)Ú
UpdateBase)ÚGroupedElement)Ú
TextClause)ÚCompoundSelectState)ÚLABEL_STYLE_DISAMBIGUATE_ONLY)ÚLABEL_STYLE_NONE)ÚLABEL_STYLE_TABLENAME_PLUS_COL)ÚSelect)ÚSelectLabelStyle)ÚSelectState)ÚTypedReturnsRows)ÚInternalTraversal)Ú_InternalEntityType)ÚOrmExecuteOptionsParameter)ÚPostLoad)ÚMapper)ÚQuery)Ú_BindArguments)ÚSession)ÚResult)Ú_CoreSingleExecuteParams)Ú_ColumnsClauseArgument)ÚSQLCompiler)Ú_DMLTableElement)ÚColumnElement)Ú_JoinTargetElement)Ú_LabelConventionCallable)Ú_SetupJoinsElement)ÚExecutableReturnsRows)Ú
SelectBase)Ú
TypeEngineÚ_T)Úboundc                   @  sT   e Zd ZU dZded< ded< ded< G dd	„ d	eƒZ	
	
dddd„Zd dd„Zd
S )!ÚQueryContext)Útop_level_contextÚcompile_stateÚqueryÚuser_passed_queryÚparamsÚload_optionsÚbind_argumentsÚexecution_optionsÚsessionÚ	autoflushÚpopulate_existingÚinvoke_all_eagersÚversion_checkÚrefresh_stateÚcreate_eager_joinsÚpropagated_loader_optionsr   ÚrunidÚpartialsÚpost_load_pathsÚidentity_tokenÚ	yield_perÚloaders_require_bufferingÚloaders_require_uniquingÚintrd   zDict[PathRegistry, PostLoad]rf   ÚORMCompileStaterU   c                   @  s<   e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdS )z!QueryContext.default_load_optionsFTN)Ú__name__Ú
__module__Ú__qualname__Ú_only_return_tuplesÚ_populate_existingÚ_version_checkÚ_invoke_all_eagersÚ
_autoflushÚ_identity_tokenÚ
_yield_perÚ_refresh_stateÚ_lazy_loaded_fromÚ_legacy_uniquingÚ_sa_top_level_orm_contextÚ_is_user_refresh© r|   r|   úR/var/www/html/flaskapp/venv/lib/python3.10/site-packages/sqlalchemy/orm/context.pyÚdefault_load_options†   s    r~   Nr.   Ú	statementú2Union[Select[Any], FromStatement[Any], UpdateBase]rW   rX   rF   r\   rD   rY   úQUnion[Type[QueryContext.default_load_options], QueryContext.default_load_options]r[   ú$Optional[OrmExecuteOptionsParameter]rZ   úOptional[_BindArguments]c	                   sÀ   |ˆ _ |ptˆ _|ptˆ _|ˆ _|ˆ _|ˆ _|ˆ _dˆ _dˆ _	|ˆ _
|jˆ _|jj}	|j}
t‡ fdd„t|	|
ƒD ƒƒˆ _t|jƒˆ _|jˆ _|jˆ _|jˆ _|jˆ _|jˆ _|jˆ _|j ˆ _!d S )NFc                 3  s&   � | ]\}}|j r| ˆ |¡V  qd S ©N)Úpropagate_to_loadersÚ'_adapt_cached_option_to_uncached_option)Ú.0ÚoptÚuncached_opt©Úselfr|   r}   Ú	<genexpr>Æ   s   € ý

ÿz(QueryContext.__init__.<locals>.<genexpr>)"rY   Ú_EMPTY_DICTr[   rZ   rU   rV   rW   r\   ri   rj   rX   rz   rT   Úselect_statementÚ_with_optionsÚtupleÚziprc   Údictr   rt   r]   rq   r^   rs   r_   rr   r`   rw   ra   rv   rh   ru   rg   )r‹   rU   r   rW   rX   r\   rY   r[   rZ   Úcached_optionsÚuncached_optionsr|   rŠ   r}   Ú__init__”   s0   


þzQueryContext.__init__Úreturnc                 C  s
   | j p| S r„   )rT   rŠ   r|   r|   r}   Ú_get_top_level_contextÖ   s   
z#QueryContext._get_top_level_context)NN)rU   r.   r   r€   rW   r€   rX   rF   r\   rD   rY   r�   r[   r‚   rZ   rƒ   )r–   rS   )	rm   rn   ro   Ú	__slots__Ú__annotations__r1   r~   r•   r—   r|   r|   r|   r}   rS   f   s   
 ðBrS   Ú _result_disable_adapt_to_contextTc                      sT   e Zd ZdZdd„ Zed‡ fdd„ƒZedd„ ƒZeddd„ƒZedd„ ƒZ	‡  Z
S )ÚAbstractORMCompileStateFc          	      C  sÈ   i | _ |d u ri  | _}|sJ ‚d S |j | _}|r0d|d< |r.|jD ]
}|jr-| | ¡ q#d S | dd¡r8d S |jd }z|d }W n	 tyL   Y nw |jD ]}|j	r]|jr]| | ¡ qPd|d< d S )NTÚtoplevel_ormFr   Ú
selectable)
r   Úglobal_attributesÚ_global_attributesr�   Ú_is_criteria_optionÚprocess_compile_stateÚgetÚstackÚKeyErrorÚ_is_compile_state)	r‹   r   ÚcompilerÚtoplevelÚprocess_criteria_for_toplevelÚgarˆ   Ústack_0Útoplevel_stmtr|   r|   r}   Ú_init_global_attributesâ   s6   


€
ÿ

€z/AbstractORMCompileState._init_global_attributesr   r/   r¦   rH   Úkwr   r–   r.   c                   s   t ƒ j||fi |¤ŽS )aÇ  Create a context for a statement given a :class:`.Compiler`.

        This method is always invoked in the context of SQLCompiler.process().

        For a Select object, this would be invoked from
        SQLCompiler.visit_select(). For the special FromStatement object used
        by Query to indicate "Query.from_statement()", this is called by
        FromStatement._compiler_dispatch() that would be called by
        SQLCompiler.process().
        )ÚsuperÚcreate_for_statement©Úclsr   r¦   r­   ©Ú	__class__r|   r}   r¯   	  s   z,AbstractORMCompileState.create_for_statementc                 C  ó   t ƒ ‚r„   ©ÚNotImplementedError)r±   r\   r   rX   r[   rZ   Úis_pre_eventr|   r|   r}   Úorm_pre_session_exec  ó   
z,AbstractORMCompileState.orm_pre_session_execrE   c                 C  s(   |j ||pi |d�}|  ||||||¡S )N)r[   )ÚexecuteÚorm_setup_cursor_result)r±   r\   r   rX   r[   rZ   ÚconnÚresultr|   r|   r}   Úorm_execute_statement(  s   

ÿúz-AbstractORMCompileState.orm_execute_statementc                 C  r´   r„   rµ   ©r±   r\   r   rX   r[   rZ   r½   r|   r|   r}   r»   >  r¹   z/AbstractORMCompileState.orm_setup_cursor_result)r   r/   r¦   rH   r­   r   r–   r.   )r–   rE   )rm   rn   ro   Úis_dml_returningr¬   Úclassmethodr¯   r¸   r¾   r»   Ú__classcell__r|   r|   r²   r}   r›   ß   s    '
r›   c                   @  s(   e Zd ZdZedd„ ƒZedd„ ƒZdS )ÚAutoflushOnlyORMCompileStatez>ORM compile state that is a passthrough, except for autoflush.c                 C  s4   t j ddh||j¡\}}|s|jr| ¡  ||fS )NÚ_sa_orm_load_optionsr]   )rS   r~   Úfrom_execution_optionsÚ_execution_optionsrt   )r±   r\   r   rX   r[   rZ   r·   rY   r|   r|   r}   r¸   N  s   ÿúý

z1AutoflushOnlyORMCompileState.orm_pre_session_execc                 C  s   |S r„   r|   r¿   r|   r|   r}   r»   k  s   
z4AutoflushOnlyORMCompileState.orm_setup_cursor_resultN)rm   rn   ro   Ú__doc__rÁ   r¸   r»   r|   r|   r|   r}   rÃ   K  s    
rÃ   c                   @  s$  e Zd ZU G dd„ deƒZded< ded< ded< ded< d	ed
< ded< ded< ded< ded< ded< ded< ded< ded< ded< eZded< dZdd „ Z	e
dDd'd(„ƒZe
dEd,d-„ƒZd.d/„ Ze
dFd3d4„ƒZe
d5d6„ ƒZe
d7d8„ ƒZe
d9d:„ ƒZed;d<„ ƒZd=d>„ Zd?d@„ Ze
dAdB„ ƒZdCS )Grl   c                   @  s”   e Zd Zdejfdejfdejfdejfdejfdejfdejfdejfd	ejfd
ejfdejfgZdZdZ	dZ
eZdZdZdZdZdZdZdZdS )z'ORMCompileState.default_compile_optionsÚ_use_legacy_query_styleÚ_for_statementÚ_bake_okÚ_current_pathÚ_enable_single_critÚ_enable_eagerloadsÚ_only_load_propsÚ_set_base_aliasÚ_for_refresh_stateÚ_render_for_subqueryÚ_is_starFTN)rm   rn   ro   r=   Ú
dp_booleanÚdp_has_cache_keyÚdp_plain_objÚ_cache_key_traversalrÈ   rÉ   rÊ   Ú_path_registryrË   rÌ   rÍ   rÎ   rÏ   rÐ   rÑ   rÒ   r|   r|   r|   r}   Údefault_compile_optionsy  s0    õrØ   zDict[Any, Any]r   rž   r€   r   rŽ   úList[_QueryEntity]Ú	_entitiesz%Dict[_InternalEntityType, ORMAdapter]Ú_polymorphic_adaptersz=Union[Type[default_compile_options], default_compile_options]Úcompile_optionszOptional[_QueryEntity]Ú_primary_entityÚboolÚuse_legacy_query_stylerL   Ú_label_conventionzList[ColumnElement[Any]]Úprimary_columnsÚsecondary_columnszSet[ColumnElement[Any]]Údedupe_columnszList[Tuple[Any, ...]]rb   r   Úcurrent_pathFc                 O  r´   r„   rµ   )r‹   Úargr­   r|   r|   r}   r•   µ  ó   zORMCompileState.__init__r/   r¦   rH   r­   r   r–   c                 K  s"   | j td|ƒf|j |dœ|¤ŽS )NúUnion[Select, FromStatement])r§   r¦   )Ú_create_orm_contextr   r£   r°   r|   r|   r}   r¯   ¸  s   ÿýüz$ORMCompileState.create_for_statementrç   r§   úOptional[SQLCompiler]c                K  r´   r„   rµ   )r±   r   r§   r¦   r­   r|   r|   r}   rè   Æ  s   	z#ORMCompileState._create_orm_contextc                 C  s*   | j }||vr| |¡ | |¡ d S d S r„   )rã   ÚaddÚappend)r‹   ÚobjÚcol_collectionÚdeduper|   r|   r}   Ú_append_dedupe_col_collectionÑ  s
   
þz-ORMCompileState._append_dedupe_col_collectionÚlabel_styler:   Úlegacyc                 C  s   |r	ddd„}|S t  |¡S )Nc                 S  s   |r|S t | dƒS )NÚkey)Úgetattr)ÚcolÚcol_namer|   r|   r}   ÚnameÝ  s   
z7ORMCompileState._column_naming_convention.<locals>.namer„   )r;   Ú_column_naming_convention)r±   rð   rñ   rö   r|   r|   r}   r÷   ×  s   

z)ORMCompileState._column_naming_conventionc                 C  s   t |ƒS r„   )Ú_column_descriptions©r±   r   r|   r|   r}   Úget_column_descriptionsç  ó   z'ORMCompileState.get_column_descriptionsc           
      C  sü   t j dh d£||j¡\}}d|v r|d }|jj |j|¡}|s$t}n| t¡}|j	r4| d|j	i¡}t
|jdd ƒrSt|jjƒdkrS| dd¡d urS| d d	d
œ¡}||d< z|jd }	W n tyi   J dƒ‚w |	rq|	j|d< |sz|jrz| ¡  ||fS )NrÄ   >   r]   rh   rg   r^   Úsa_top_level_orm_contextrü   rh   rË   é
   Úcompiled_cacheTz#excess depth for ORM loader options)rþ   Ú_cache_disable_reasonÚclauseÚplugin_subjectFz0statement had 'orm' plugin but no plugin_subjectÚmapper)rS   r~   rÅ   rÆ   rV   Ú
merge_withr[   Ú_orm_load_exec_optionsÚunionrv   ró   Ú_compile_optionsÚlenrË   r¢   Ú_propagate_attrsr¤   r  rt   )
r±   r\   r   rX   r[   rZ   r·   rY   Úctxr  r|   r|   r}   r¸   ë  sT   öýÿ
ÿÿþÿÿ
ÿ

z$ORMCompileState.orm_pre_session_execc              	   C  sJ   |j }|jj}| dtj¡}	|jjr|S t||||||	||ƒ}
t 	||
¡S )NrÄ   )
ÚcontextÚcompiledrU   r¢   rS   r~   rÜ   rÒ   r   Ú	instances)r±   r\   r   rX   r[   rZ   r½   Úexecution_contextrU   rY   Úquerycontextr|   r|   r}   r»   E  s$   
ÿø
z'ORMCompileState.orm_setup_cursor_resultc                 C  s   dd„ | j D ƒS )zºreturn all _MapperEntity objects in the lead entities collection.

        Does **not** include entities that have been replaced by
        with_entities(), with_only_columns()

        c                 S  ó   g | ]	}t |tƒr|‘qS r|   ©Ú
isinstanceÚ_MapperEntity©r‡   Úentr|   r|   r}   Ú
<listcomp>r  ó
    
ÿÿz9ORMCompileState._lead_mapper_entities.<locals>.<listcomp>)rÚ   rŠ   r|   r|   r}   Ú_lead_mapper_entitiesj  s   ÿz%ORMCompileState._lead_mapper_entitiesc              
   C  sL   |j s |jj| jvr"|j ¡ D ]}|  |ttj||j	|d�¡ qdS dS dS )a5  given MapperEntity or ORMColumnEntity, setup polymorphic loading
        if called for by the Mapper.

        As of #8168 in 2.0.0rc1, polymorphic adapters, which greatly increase
        the complexity of the query creation process, are not used at all
        except in the quasi-legacy cases of with_polymorphic referring to an
        alias and/or subquery. This would apply to concrete polymorphic
        loading, and joined inheritance where a subquery is
        passed to with_polymorphic (which is completely unnecessary in modern
        use).

        )Úequivalentsr�   N)
Úis_aliased_classr  Úpersist_selectablerÛ   Úiterate_to_rootÚ"_mapper_loads_polymorphically_withr   r   ÚWITH_POLYMORPHIC_ADAPTERÚ_equivalent_columns)r‹   Úext_infor�   Úmpr|   r|   r}   Ú _create_with_polymorphic_adapterv  s$   ÿÿüþúz0ORMCompileState._create_with_polymorphic_adapterc                 C  s:   |j p|gD ]}|| j|< | ¡ D ]}|| j|j< qqd S r„   )Ú_with_polymorphic_mappersrÛ   r  Úlocal_table)r‹   r  ÚadapterÚm2Úmr|   r|   r}   r  “  s   
ÿýz2ORMCompileState._mapper_loads_polymorphically_withc                 C  s   t dƒ‚)Nz0this method only works for ORMSelectCompileStaterµ   )r±   rV   rñ   r|   r|   r}   Ú_create_entities_collectionš  s   ÿz+ORMCompileState._create_entities_collectionN)r   r/   r¦   rH   r­   r   r–   rl   )
r   rç   r§   rÞ   r¦   ré   r­   r   r–   rl   )rð   r:   rñ   rÞ   r–   rL   )rm   rn   ro   r-   rØ   r™   r×   rä   Ú_has_mapper_entitiesr•   rÁ   r¯   rè   rï   r÷   rú   r¸   r»   Úpropertyr  r!  r  r'  r|   r|   r|   r}   rl   x  sL   
 %


Y
$
rl   c                   @  s,   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	S )
Ú_DMLReturningColFilterzûa base for an adapter used for the DML RETURNING cases

    Has a subset of the interface used by
    :class:`.ORMAdapter` and is used for :class:`._QueryEntity`
    instances to set up their columns as used in RETURNING for a
    DML statement.

    )r  ÚcolumnsÚ__weakref__c                 C  s:   |d ur|j |j ur|| _n|| _t | j¡ | _| _d S r„   )r#  r  r#   ÚWeakPopulateDictÚadapt_check_presentr+  )r‹   Útarget_mapperÚimmediate_dml_mapperr|   r|   r}   r•   ­  s   ÿÿz_DMLReturningColFilter.__init__c                 C  s.   t  |¡D ]}|  |¡}|d ur|  S qd S r„   )Úsql_utilÚ_find_columnsr.  )r‹   rô   Ú	as_filterÚccÚc2r|   r|   r}   Ú__call__¼  s   
ÿz_DMLReturningColFilter.__call__c                 C  r´   r„   rµ   )r‹   rô   r|   r|   r}   r.  Ä  ræ   z*_DMLReturningColFilter.adapt_check_presentN)rm   rn   ro   rÇ   r˜   r•   r6  r.  r|   r|   r|   r}   r*  ¡  s    	r*  c                   @  ó   e Zd ZdZdd„ ZdS )Ú _DMLBulkInsertReturningColFiltera[  an adapter used for the DML RETURNING case specifically
    for ORM bulk insert (or any hypothetical DML that is splitting out a class
    hierarchy among multiple DML statements....ORM bulk insert is the only
    example right now)

    its main job is to limit the columns in a RETURNING to only a specific
    mapped table in a hierarchy.

    c                 C  s.   | j }|j |d ¡}|d u rd S |jj |¡S r„   )r  Ú_columntopropertyr¢   r#  ÚcÚcorresponding_column©r‹   rô   r  Úpropr|   r|   r}   r.  Ó  s
   z4_DMLBulkInsertReturningColFilter.adapt_check_presentN©rm   rn   ro   rÇ   r.  r|   r|   r|   r}   r8  È  ó    
r8  c                   @  r7  )Ú"_DMLUpdateDeleteReturningColFiltera_  an adapter used for the DML RETURNING case specifically
    for ORM enabled UPDATE/DELETE

    its main job is to limit the columns in a RETURNING to include
    only direct persisted columns from the immediate selectable, not
    expressions like column_property(), or to also allow columns from other
    mappers for the UPDATE..FROM use case.

    c                 C  s.   | j }|j |d ¡}|d ur|jj |¡S |S r„   )r  r9  r¢   r  r:  r;  r<  r|   r|   r}   r.  æ  s
   z6_DMLUpdateDeleteReturningColFilter.adapt_check_presentNr>  r|   r|   r|   r}   r@  Û  r?  r@  ÚormÚorm_from_statementc                   @  sp   e Zd ZU dZdZded< ded< dZded< dZdZdZ	dZ
eZeZeddd„ƒZdd„ Zdd„ Zdd„ ZdS )ÚORMFromStatementCompileStateNFÚFromStatementÚstatement_containerz)Union[SelectBase, TextClause, UpdateBase]Úrequested_statementzOptional[_DMLTableElement]Ú	dml_tabler   rç   r§   rÞ   r¦   ré   r­   r   r–   c                K  sò  |}t |tƒs	J ‚|d ur|jrt d¡‚|  | ¡}d |_|jj|_	| |_
|_|j |_}|jr8|j|_d|_g |_i |_|j|_|j	r]t |tjƒr]|js]|js]|jtu r]| t¡|_n||_| |jsk|jsk|jnt|j	¡|_tj ||j!|jdd� |jj"|_#|j$||ddd� |j%r›|j%D ]
}|j&rš| '|¡ q�|j(rª|j(D ]\}}	||ƒ q¡g |_)g |_*t+ƒ |_,g |_-g |_.d |_/t |jtj0ƒrìi |_1|jD ]}
|
 2|¡ qÊd |_3|_4d|_5|j)D ]}|j6|d|j7d� qÞ|S t8t9j:|j|j;d�|_<|S )NzšThe ORM FromStatement construct only supports being invoked as the topmost statement, as it is only intended to define how result rows should be returned.T©Úis_current_entitiesF)r¨   r§   )Úwithin_columns_clauseÚadd_to_result_map)Úadapt_on_names)=r  rD  r£   Úsa_excÚCompileErrorÚ__new__rÝ   r  rÈ   rß   rE  rŽ   ÚelementrF  r)   ÚtablerG  rÀ   rÚ   rÛ   rÜ   r%   rO   Ú_is_textualÚ_label_styler7   Úset_label_styler8   r   r÷   rà   Ú_QueryEntityÚto_compile_stateÚ_raw_columnsrË   rä   r¬   r�   r¥   r¡   Ú_with_context_optionsrá   râ   Úsetrã   rb   Ú_fallback_from_clausesÚorder_byr4   Úextra_criteria_entitiesÚsetup_compile_stateÚ_ordered_columnsÚ_textual_ordered_columnsÚ_loose_column_name_matchingÚprocessÚ_add_to_result_mapr   r   ÚADAPT_FROM_STATEMENTÚ_adapt_on_namesÚ_from_obj_alias)r±   r   r§   r¦   r­   rE  r‹   rˆ   Úfnrò   Úentityr:  r|   r|   r}   rè     s¬   	ÿ
ÿÿ
þýü
ÿÿÿú	ü
ü

€


ÿ
ýúýz0ORMFromStatementCompileState._create_orm_contextc                 C  s   |S r„   r|   ©r‹   ÚcolsÚcurrent_adapterr|   r|   r}   Ú_adapt_col_listŠ  ó   z,ORMFromStatementCompileState._adapt_col_listc                 C  ó   d S r„   r|   rŠ   r|   r|   r}   Ú_get_current_adapter�  rl  z1ORMFromStatementCompileState._get_current_adapterc                 C  s€   | j j dd¡}| j jrt||ƒ}n| j js| j jr t||ƒ}nd}| jj	r2t
| jƒdkr2t d¡‚| jD ]}| | |¡ q5dS )zused by BulkORMInsert, Update, Delete to set up a handler
        for RETURNING to return ORM objects and expressions

        r  Nr   úsCan't generate ORM query that includes multiple expressions at the same time as '*'; query for '*' alone if present)r   r  r¢   Ú	is_insertr8  Ú	is_updateÚ	is_deleter@  rÜ   rÒ   r  rÚ   rM  rN  Ú!setup_dml_returning_compile_state)r‹   Ú
dml_mapperr/  r$  rg  r|   r|   r}   rs  �  s&   ÿÿÿÿ
ÿz>ORMFromStatementCompileState.setup_dml_returning_compile_state)
r   rç   r§   rÞ   r¦   ré   r­   r   r–   rC  )rm   rn   ro   re  r(  r™   rG  Ú_has_orm_entitiesÚmulti_row_eager_loadersÚeager_adding_joinsÚcompound_eager_adapterr�   r\  Úeager_joinsrÁ   rè   rk  rn  rs  r|   r|   r|   r}   rC  ó  s$   
  rC  c                      sÎ   e Zd ZU dZdZejZejZ	dZ
ded< ded< dejfdejfgej Zed	ejfg Zd
Z	
dd dd„Zdd„ Zedd„ ƒZdd„ Z‡ fdd„Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZ‡  ZS )!rD  a*  Core construct that represents a load of ORM objects from various
    :class:`.ReturnsRows` and other classes including:

    :class:`.Select`, :class:`.TextClause`, :class:`.TextualSelect`,
    :class:`.CompoundSelect`, :class`.Insert`, :class:`.Update`,
    and in theory, :class:`.Delete`.

    rB  Nú(Union[ExecutableReturnsRows, TextClause]rP  rÞ   rd  rW  r  TÚentitiesú%Iterable[_ColumnsClauseArgument[Any]]c                   sf   ‡ fdd„t  |¡D ƒˆ _|ˆ _|jˆ _|jˆ _|jˆ _|jˆ _|jˆ _t	|ƒr+|j
nd ˆ _
|ˆ _d S )Nc                   s    g | ]}t jtj|ˆ d d�‘qS )T)Úapply_propagate_attrsÚpost_inspect)r$   Úexpectr&   ÚColumnsClauseRoler  rŠ   r|   r}   r  Õ  s    úüÿz*FromStatement.__init__.<locals>.<listcomp>)r#   Úto_listrW  rP  r)   Ú	is_selectrr  rp  rq  r+   rS  rd  )r‹   r{  rP  rd  r|   rŠ   r}   r•   Ï  s   
ù	ÿ
zFromStatement.__init__c                 K  s:   | j | |fi |¤Ž}|j }|r||_|j|jfi |¤ŽS )z›provide a fixed _compiler_dispatch method.

        This is roughly similar to using the sqlalchemy.ext.compiler
        ``@compiles`` extension.

        )Ú_compile_state_factoryr£   rU   ra  r   )r‹   r¦   r­   rU   r§   r|   r|   r}   Ú_compiler_dispatché  s
   z FromStatement._compiler_dispatchc                 C  s   t tt | ¡ƒj}|| ƒS )a@  Return a :term:`plugin-enabled` 'column descriptions' structure
        referring to the columns which are SELECTed by this statement.

        See the section :ref:`queryguide_inspection` for an overview
        of this feature.

        .. seealso::

            :ref:`queryguide_inspection` - ORM background

        )r   ÚORMSelectCompileStater;   Úget_plugin_classrú   )r‹   Úmethr|   r|   r}   Úcolumn_descriptionsú  s   
ÿþz!FromStatement.column_descriptionsc                 C  s   | S r„   r|   rŠ   r|   r|   r}   Ú_ensure_disambiguated_names  rl  z)FromStatement._ensure_disambiguated_namesc                 +  s<   � t j dd„ | jD ƒ¡E d H  tƒ jdi |¤ŽE d H  d S )Nc                 s  ó   � | ]}|j V  qd S r„   )Ú_from_objects©r‡   rP  r|   r|   r}   rŒ     ó   € 
ÿz-FromStatement.get_children.<locals>.<genexpr>r|   )Ú	itertoolsÚchainÚfrom_iterablerW  r®   Úget_children)r‹   r­   r²   r|   r}   r‘    s
   €ÿzFromStatement.get_childrenc                 C  ó   | j jS r„   )rP  Ú_all_selected_columnsrŠ   r|   r|   r}   r“    rû   z#FromStatement._all_selected_columnsc                 C  ó   t | jƒr	| jjS d S r„   )r)   rP  Ú_return_defaultsrŠ   r|   r|   r}   r•    ó   zFromStatement._return_defaultsc                 C  r”  r„   )r)   rP  Ú
_returningrŠ   r|   r|   r}   r—    r–  zFromStatement._returningc                 C  r”  r„   )r*   rP  Ú_inlinerŠ   r|   r|   r}   r˜  !  r–  zFromStatement._inline©T)r{  r|  rP  rz  rd  rÞ   ) rm   rn   ro   rÇ   Ú__visit_name__rC  rØ   r  r¯   rƒ  Ú_for_update_argr™   r=   Údp_clauseelement_listÚdp_clauseelementr/   Ú_executable_traverse_internalsÚ_traverse_internalsrÔ   rÖ   Úis_from_statementr•   r„  r)  rˆ  r‰  r‘  r“  r•  r—  r˜  rÂ   r|   r|   r²   r}   rD  ®  s@   
 	þýÿü



rD  Úcompound_selectc                   @  s   e Zd ZdS )ÚCompoundSelectCompileStateN)rm   rn   ro   r|   r|   r|   r}   r¢  &  s    r¢  Úselectc                   @  sP  e Zd ZdZeZdZdZdZdZ	dZ
dZdZdZdZdZedIdd„ƒZdd„ Zdd„ Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ ZdJd'd(„Zd)d*„ Zd+d,„ Z d-d.„ Z!d/d0„ Z"d1d2„ Z#d3d4„ Z$d5d6„ Z%d7d8„ Z&d9d:„ Z'd;d<„ Z(d=d>„ Z)d?d@„ Z*e+dAdB„ ƒZ,e+dCdD„ ƒZ-dEdF„ Z.dGdH„ Z/dS )Kr…  r|   NFr   rç   r§   rÞ   r¦   ré   r­   r   r–   c          
        s  |   | ¡‰ |}| j |j¡|_|jr| ¡ ˆ _t ¡ ˆ j_n|ˆ _|jj	ˆ _
|jjˆ _g ˆ _d ˆ _i ˆ _|jˆ _|sDˆ  jdddœ7  _ˆ jrXˆ jjtu rXˆ j
sTtˆ _n	tˆ _nˆ jjˆ _|jrk‡ fdd„|jD ƒˆ _ˆ  |jˆ j¡ˆ _tjˆ |jˆ jdd� |jjˆ _dˆ _ˆ j |||dd� |rÄ|j!s˜|jrÄ|jD ]}|j!D ]}|j"r³| #ˆ d	d
„ ˆ j| D ƒ¡ q q›ˆ jj!D ]
}|j"rÃ| $ˆ ¡ q¹|j%rÓ|j%D ]\}}	|ˆ ƒ qÊg ˆ _&g ˆ _'t(ƒ ˆ _)i ˆ _*i ˆ _+g ˆ _,g ˆ _-ˆ  .dd„ |j/D ƒ¡ˆ _0ˆ  1¡  t2j3ˆ ˆ j4|fi |¤Ž ˆ S )NFT)rÍ   rÑ   c              	     s"   i | ]}|t jˆ |jg d d�“qS )FrH  )rU  rV  rW  )r‡   Úmemoized_entitiesrŠ   r|   r}   Ú
<dictcomp>ƒ  s    úüÿz=ORMSelectCompileState._create_orm_context.<locals>.<dictcomp>rH  r|   )r§   r¨   c                 S  r  r|   r  r  r|   r|   r}   r  ´  s    ûÿz=ORMSelectCompileState._create_orm_context.<locals>.<listcomp>c                 s  rŠ  r„   )r�   )r‡   Úinfor|   r|   r}   rŒ   ×  r�  z<ORMSelectCompileState._create_orm_context.<locals>.<genexpr>)5rO  rØ   Ú
safe_merger  rÆ   Ú_clonerŽ   r#   ÚimmutabledictrÉ   Úfor_statementrÈ   rß   rÚ   rÝ   rÛ   rÜ   rS  ÚLABEL_STYLE_LEGACY_ORMr8   rð   r6   Ú_memoized_select_entitiesÚ_memoized_entitiesr÷   rà   rU  rV  rW  rË   rä   Úeager_order_byr¬   r�   r¥   Ú'process_compile_state_replaced_entitiesr¡   rX  rá   râ   rY  rã   ry  r\  rb   rZ  Ú_normalize_fromsÚ	_from_objÚfrom_clausesÚ_setup_for_generater;   r•   r   )
r±   r   r§   r¦   r­   rŽ   r¤  rˆ   rf  rò   r|   rŠ   r}   rè   @  s²   

ÿ

ÿ
þ
ÿ

øÿü
üÿþþ
ÿþþ€þ
€


ÿz)ORMSelectCompileState._create_orm_contextc                 C  sÄ   t dƒ t d| j› �ƒ | jD ]P}t|tƒr>|d dkr>t dt |d ¡› �ƒ t d| j| › �ƒ t d| j| j› �ƒ qt|tƒr_|d dkr_t d	t |d ¡› �ƒ t d| j| › �ƒ qd S )
Nz5
---------------------------------------------------
zcurrent path: r   Úloaderz
Loader:           r   z    Úpath_with_polymorphicz
With Polymorphic: )Úprinträ   r   r  r�   r   ÚcoerceÚ__dict__)r‹   rò   r|   r|   r}   Ú_dump_option_structã  s   
€ùz)ORMSelectCompileState._dump_option_structc                   sÎ  | j }d | _d| _| jjr|  ¡  |jD ]}|jr#|  |j| j	| ¡ q|jr/|  |j| j
¡ |  ¡ ‰ |jrI|j| _ˆ rIt‡ fdd„| jD ƒƒ| _ˆ rW|jdvrW|  |jˆ ¡n|j| _|jrkt‡ fdd„|jD ƒƒ| _ˆ r||jdvr||  t |j¡ˆ ¡n|jp€d | _| jr’| jd j}| | j¡| _|jrž|  |jˆ ¡| _nd| _|j| _|jr·tt dd„ |jD ƒ¡ƒ| _n|j d urËtt dd„ |j D ƒ¡ƒ| _!n|j"sÑd	| _|j#| _#| jj$råt%| j
ƒd
kråt& 'd¡‚| j
D ]}| (| ¡ qè| j)D ]}|d }|| g|d
d … ¢R Ž  qó| jj*�r|  +¡  | j,�s!| jj-�rJ dƒ‚t& .d¡‚| j�s+t/| j0ƒ| _| jdu �r4d | _| j1�rF| j2�rF| j3�rF|  4¡ | _n|  5¡ | _| j6�rc|  7¡ }|d u�re| j 8d|i¡| _d S d S d S )Nr|   c                 3  s   � | ]}ˆ |d ƒV  qdS ©TNr|   ©r‡   Úcrit©rj  r|   r}   rŒ   	  s
   € ÿ
ÿz<ORMSelectCompileState._setup_for_generate.<locals>.<genexpr>©NFc                 3  s"   � | ]}ˆ rˆ |d ƒn|V  qdS rº  r|   r»  r½  r|   r}   rŒ     s
   € ÿ
ÿr   c                 s  ó&   � | ]}|d urt  |¡nd V  qd S r„   ©r1  Úsurface_selectables©r‡   Úsr|   r|   r}   rŒ   7  ó
   € ÿ
ÿc                 s  r¿  r„   rÀ  rÂ  r|   r|   r}   rŒ   >  rÄ  r„   r   ro  Fz,no columns were included in _only_load_propsz4Query contains no columns with which to SELECT from.Ú
deepentity)9rŽ   r   Ú_join_entitiesrÜ   rÏ   Ú_set_select_from_aliasr¬  Ú_setup_joinsÚ_joinr­  rÚ   rn  Ú_where_criteriar�   Ú_order_by_clausesrk  r[  Ú_having_criteriaÚ_group_by_clausesr#   Úflatten_iteratorÚgroup_byr®  r²  Ú_target_adapterÚcopy_and_processÚ_distinct_onÚdistinct_onÚ	_distinctÚdistinctÚ
_correlateÚ	correlateÚ_correlate_exceptÚcorrelate_exceptÚ_auto_correlater›  rÒ   r  rM  rN  r]  rb   rÌ   Ú_adjust_for_extra_criteriará   rÎ   ÚInvalidRequestErrorÚlistrZ  rv  rw  Ú_should_nest_selectableÚ_compound_eager_statementÚ_simple_statementrª  Ú_mapper_zeroÚ	_annotate)r‹   rV   r¤  r$  rg  ÚrecÚstrategyÚezeror|   r½  r}   r³  ï  sÈ   
þ€
þ
ÿ
ÿý
þ	ý
ýÿûÿ
þÿ

þÿÿ



ÿÿþý


ÿûz)ORMSelectCompileState._setup_for_generatec                 C  sF   |   | ¡}g |_d|_i |_| |j|¡|_tj||j	|jdd� |S )a  Creates a partial ORMSelectCompileState that includes
        the full collection of _MapperEntity and other _QueryEntity objects.

        Supports a few remaining use cases that are pre-compilation
        but still need to gather some of the column  / adaption information.

        NTrH  )
rO  rÚ   rÝ   rÛ   r÷   rS  rà   rU  rV  rW  )r±   rV   rñ   r‹   r|   r|   r}   r'  |  s   
	ÿÿz1ORMSelectCompileState._create_entities_collectionc                 C  s   |j }t|d ƒS r„   )rÈ  Ú_determine_last_joined_entity)r±   r   Úsetup_joinsr|   r|   r}   Údetermine_last_joined_entity–  s   
z2ORMSelectCompileState.determine_last_joined_entityc                 c  sl   � |j D ]/}|jr+d|jv r+|jd }|js"|js"t|gƒE d H  qt|jƒE d H  qt|gƒE d H  qd S )NÚentity_namespace)rW  Úis_selectableÚ_annotationsÚ	is_mapperr  r,   Ú_all_column_expressions)r±   r   rP  Úensr|   r|   r}   Úall_selected_columnsœ  s   €
ÿ

õz*ORMSelectCompileState.all_selected_columnsc                 C  s   |   tj dd„ |jD ƒ¡¡S )Nc                 s  s0   � | ]}d |j vr|jn|j d   ¡ gV  qdS )ÚparententityN)rë  r‹  Ú__clause_element__rŒ  r|   r|   r}   rŒ   ®  s   € 

ùÿÿý
üzAORMSelectCompileState.get_columns_clause_froms.<locals>.<genexpr>)r°  rŽ  r�  r�  rW  rù   r|   r|   r}   Úget_columns_clause_froms«  s
   
öÿz.ORMSelectCompileState.get_columns_clause_fromsc                 C  s>   t jtj||d�}t|j|ƒ}|jj|j|j	|j
|jd� |S )N)r}  )r�   rX  rÆ   r  )r$   r  r&   ÚReturnsRowsRolerD  rW  r¸  Úupdater�   rX  rÆ   r  )r±   r   Úfrom_statementÚstmtr|   r|   r}   rõ  ¼  s   ýüz$ORMSelectCompileState.from_statementc                 C  sX   | j }| jjs	J ‚t|jƒdksJ ‚|  |jd ¡}|r*|  jddi7  _|| _dS dS )ú used only for legacy Query casesr   r   rÌ   FN)rŽ   rÜ   rÏ   r  r±  Ú_get_select_from_alias_from_objre  )r‹   rV   r$  r|   r|   r}   rÇ  Î  s   
þz,ORMSelectCompileState._set_select_from_aliasc                 C  st   |}d|j v r|j d }t|dƒr|jst d¡‚|jS t|jtjj	ƒr8|  
¡ }||ju s/J ‚ttj|j|d�S dS )r÷  rð  r  zPA selectable (FromClause) instance is expected when the base alias is being set.©r  N)rë  Úhasattrr  rM  ÚArgumentErrorÚ_adapterr  r�   r"   ÚAliasedReturnsRowsÚ_all_equivsr   r   ÚLEGACY_SELECT_FROM_ALIAS)r‹   Úfrom_objr¦  Úequivsr|   r|   r}   rø  Û  s$   


ÿýz5ORMSelectCompileState._get_select_from_alias_from_objc                 C  s   | j d jS )z8return the Mapper associated with the first QueryEntity.r   )rÚ   r  rŠ   r|   r|   r}   rá  ÷  ó   z"ORMSelectCompileState._mapper_zeroc                 C  sD   | j D ]}d|jv r|jd   S q| jD ]
}|jr|j  S qdS )z›Return the 'entity' (mapper or AliasedClass) associated
        with the first QueryEntity, or alternatively the 'select from'
        entity if specified.rð  N)r²  rë  rÚ   Úentity_zero)r‹   r  Úqentr|   r|   r}   Ú_entity_zeroû  s   

ÿ

ÿz"ORMSelectCompileState._entity_zeroc                 C  s$   | j | jgkrt d| ¡‚| jjS )Nz4%s() can only be used against a single mapped class.)rÚ   rÝ   rM  rÜ  r  )r‹   Úmethnamer|   r|   r}   Ú_only_full_mapper_zero	  s   ÿÿz,ORMSelectCompileState._only_full_mapper_zeroc                 C  s$   t | jƒdkrt |pd¡‚|  ¡ S )Nr   z8This operation requires a Query against a single mapper.)r  rÚ   rM  rÜ  r  )r‹   Ú	rationaler|   r|   r}   Ú_only_entity_zero  s   þz'ORMSelectCompileState._only_entity_zeroc                 C  s^   i }| j  ¡ D ]}dd„ |D ƒD ]	}| |jj¡ qqdd„ | jD ƒD ]	}| |jj¡ q#|S )Nc                 S  r  r|   r  r  r|   r|   r}   r    s    ýÿz5ORMSelectCompileState._all_equivs.<locals>.<listcomp>c                 S  r  r|   r  r  r|   r|   r}   r  %  r  )r­  Úvaluesrô  r  r  rÚ   )r‹   r  r¤  r  r|   r|   r}   rþ    s   
þû
ÿz!ORMSelectCompileState._all_equivsc                   sJ  ˆ j rdd„ ˆ j D ƒ}t ˆ j|¡}ng }d }ˆ jˆ j‡ fdd„|D ƒ ˆ jˆ jˆ jˆ jˆ j fˆ j	ˆ j
jˆ j
jˆ jˆ jdœˆ j¤Ž}| ¡ }ˆ  ¡ }ttj||d�ˆ _tj|gˆ j Ž }ˆ j|_ˆ j	d uroˆ j	jd u roˆ j	|_	|}ˆ j ¡ D ]
}t |||j¡}qv|j  ||¡ |r˜|j j |gˆ j !|¡¢R Ž  |j j |gˆ j"¢R Ž  |S )Nc                 S  s$   g | ]}t |tjjƒr|jn|‘qS r|   )r  r"   ÚelementsÚ_label_referencerP  )r‡   Úelemr|   r|   r}   r  7  s    ýÿüzCORMSelectCompileState._compound_eager_statement.<locals>.<listcomp>c                   s   g | ]	}|ˆ j vr|‘qS r|   )rã   )r‡   r:  rŠ   r|   r}   r  K  s    ©Ú
for_updateÚhintsÚstatement_hintsr×  rÙ  rù  )#r[  r1  Ú expand_column_list_from_order_byrá   Ú_select_statementr²  rÊ  rÌ  rð   r›  rŽ   Ú_hintsÚ_statement_hintsr×  rÙ  Ú_select_argsÚaliasrþ  r   r   ÚCOMPOUND_EAGER_STATEMENTrx  r    r£  râ   rS  Úofry  r
  Úsplice_joinsÚstop_onÚselect_fromÚnon_generativerÑ  r®  )r‹   Úunwrapped_order_byÚorder_by_col_exprÚinnerr  r   Úfrom_clauseÚ
eager_joinr|   rŠ   r}   rß  +  sn   ú	ÿÿùôóÿ
ÿ
ÿÿÿþz/ORMSelectCompileState._compound_eager_statementc                 C  s|   | j | j| j t| jƒt| j ¡ ƒ | j| j| j	| j
f| j| jj| jj| j| jdœ| j¤Ž}| jr<|j
j|g| j¢R Ž  |S )Nr  )r  rá   râ   r�   r²  ry  r
  rÊ  rÌ  rð   r[  r›  rŽ   r  r  r×  rÙ  r  r®  r  )r‹   r   r|   r|   r}   rà  †  s&   
úõôz'ORMSelectCompileState._simple_statementc                 C  s  t j|||d�}|r||_|r||_|r| jt|ƒ7  _|r*|jj|g|¢R Ž  n|r2|j |¡ |r=| jt|ƒ7  _||_	||_
||_||_||_||_|rT||_|rY||_||_|ra||_|	rf|	|_|
rr|jj|g|
¢R Ž  |d ur€|jj|g|¢R Ž  |S )N)rW  r±  rS  )r9   Ú_create_raw_selectrÊ  rÌ  rË  r�   rÕ  r  rÍ  Ú_limit_clauseÚ_offset_clauseÚ_fetch_clauseÚ_fetch_clause_optionsÚ_independent_ctesÚ_independent_ctes_optsÚ	_prefixesÚ	_suffixesr›  r  r  r×  rÙ  )r‹   Úraw_columnsr   Úwhere_criteriaÚhaving_criteriarð   r[  r  r  r  r×  rÙ  Úlimit_clauseÚoffset_clauseÚfetch_clauseÚfetch_clause_optionsrÕ  rÓ  ÚprefixesÚsuffixesrÏ  Úindependent_ctesÚindependent_ctes_optsr   r|   r|   r}   r  š  sR   ýÿÿz'ORMSelectCompileState._select_statementc                 C  sx   d|j v r|j d }| j |d ¡}|r| |¡S t|tjƒr!|}nt|dƒr*|j}nd S | j |d ¡}|r:| |¡S d S )Nrð  rQ  )	rë  rÛ   r¢   Úadapt_clauser  r%   Ú
FromClauserú  rQ  )r‹   rP  Úsearchr  r|   r|   r}   Ú_adapt_polymorphic_elementç  s   




ÿz0ORMSelectCompileState._adapt_polymorphic_elementc                   s   ˆ r‡ fdd„|D ƒS |S )Nc                   s   g | ]}ˆ |d ƒ‘qS r™  r|   )r‡   Úor½  r|   r}   r  û  s    z9ORMSelectCompileState._adapt_col_list.<locals>.<listcomp>r|   rh  r|   r½  r}   rk  ù  s   z%ORMSelectCompileState._adapt_col_listc                   sJ   g ‰ | j rˆ  d| j jf¡ | jrˆ  d| jf¡ ˆ sd S ‡ fdd„}|S )NTFc                   s   ‡ fdd„}t  | i |¡S )Nc                   sF   d| j v p	d| j v }ˆ D ]\}}|s|r || ƒ}|d ur |  S qd S )NÚ
_orm_adaptrð  )rë  )r  Úis_orm_adaptÚalways_adaptr$  Úe©Úadaptersr|   r}   Úreplace   s   
þ€üzRORMSelectCompileState._get_current_adapter.<locals>._adapt_clause.<locals>.replace)r'   Úreplacement_traverse)r   r3  rB  r@  r|   r}   Ú_adapt_clause  s   zAORMSelectCompileState._get_current_adapter.<locals>._adapt_clause)re  rë   rB  rÛ   r:  )r‹   rD  r|   r@  r}   rn  ÿ  s   
þÿ
z*ORMSelectCompileState._get_current_adapterc                 C  s¤  |D ]Í\}}}}|d }|d }t |ƒ}|d urt |ƒ}t|tjƒr0|d ur+t d¡‚|}d }n
d|jv r:|jd }|d u rK|jsKt|dƒsKt 	d¡‚d }	t|tjƒr·t
|dd ƒ}	|d u r|	rb|	}n|j}z|j}W n ty~ }
 zt 	d| ¡|
‚d }
~
ww |j}|j}t|tjƒs�|}|||jf| jv r—q|d ur¶||ur¶|j dd ¡|ur¶t d	|j d|¡|f ¡‚n|d urÀd }|}nd  }}|  |||||||¡ qd S )
NÚisouterÚfullzUNo 'on clause' argument may be passed when joining to a relationship path as a targetrð  r  z9Expected mapped entity or selectable/table as join targetÚ_of_typez0Join target %s does not refer to a mapped entityzMexplicit from clause %s does not match left side of relationship attribute %s)r!   r  r   ÚPropComparatorrM  rÜ  rë  rê  rú  rû  ró   r)  rg  ÚAttributeErrorÚ_parententityr   ÚQueryableAttributerò   Ú_already_joined_edgesr¢   Ú_join_left_to_right)r‹   ÚargsÚentities_collectionÚrightÚonclauseÚfrom_ÚflagsrE  rF  Úof_typeÚerrÚleftr=  r|   r|   r}   rÉ  /  s�   ÿ

ÿ
ÿÿý€ÿÿþþÿ€ù¬zORMSelectCompileState._joinc              	   C  s  |du r|du s
J ‚|   ||||¡\}}}	n|  ||¡\}}	||u r+t d||f ¡‚|  ||||¡\}
}}|
js?|  |
¡}nd}|durh| j| }| jd|… t||||||d�g | j|d d…  | _dS |	dur{t	||	 t
ƒsuJ ‚||	 j}n|}| jt||
||||d�g | _dS )zÆgiven raw "left", "right", "onclause" parameters consumed from
        a particular key within _join(), add a real ORMJoin object to
        our _from_obj list (or augment an existing one)

        Nz>Can't construct a join from %s to %s, they are the same entityr|   )rE  rF  Ú_extra_criteriar   )Ú"_join_determine_implicit_left_sideÚ_join_place_explicit_left_siderM  rÜ  Ú _join_check_and_adapt_right_siderê  Ú_get_extra_criteriar²  r   r  r  r�   )r‹   rO  rV  rP  rQ  r=  Ú	outerjoinrF  Úreplace_from_obj_indexÚuse_entity_indexÚr_infoÚextra_criteriaÚleft_clauser|   r|   r}   rM  Ž  sr   ÿü
ýÿÿ
ÿ
úÿÿõÿÿúÿz)ORMSelectCompileState._join_left_to_rightc                 C  sJ  t |ƒ}d }}| jr7t | j|j|¡}t|ƒdkr$|d }| j| }n|t|ƒdkr/t d¡‚t d|f ¡‚|r›i }	t|ƒD ])\}
}|j	}|du rKq?t |ƒ}||u rTq?t
|tƒra|
|f|	|j< q?d|f|	|j< q?t|	 ¡ ƒ}t ||j|¡}t|ƒdkrˆ|	||d   \}}nt|ƒdkr“t d¡‚t d|f ¡‚t d¡‚|||fS )z­When join conditions don't express the left side explicitly,
        determine if an existing FROM or entity in this query
        can serve as the left hand side.

        Nr   r   a  Can't determine which FROM clause to join from, there are multiple FROMS which can join to this entity. Please use the .select_from() method to establish an explicit left side, as well as providing an explicit ON clause if not present already to help resolve the ambiguity.zÇDon't know how to join to %r. Please use the .select_from() method to establish an explicit left side, as well as providing an explicit ON clause if not present already to help resolve the ambiguity.zgNo entities to join from; please use select_from() to establish the left entity/selectable of this join)r!   r²  r1  Úfind_left_clause_to_join_fromr�   r  rM  rÜ  Ú	enumerateÚentity_zero_or_selectabler  r  rÝ  Úkeys)r‹   rO  rV  rP  rQ  r_  r]  r^  ÚindexesÚ	potentialÚentity_indexr  rg  Úent_infoÚall_clausesr|   r|   r}   rX  ñ  sb   
ÿÿ	üÿ
ÿÿ	üÿÿ
z8ORMSelectCompileState._join_determine_implicit_left_sidec           	      C  sš   d }}t |ƒ}| jr$t | j|j¡}t|ƒdkrt d¡‚|r$|d }|du rI|rIt|dƒrIt	|ƒD ]\}}t
|tƒrH| |¡rH|} ||fS q3||fS )zøWhen join conditions express a left side explicitly, determine
        where in our existing list of FROM clauses we should join towards,
        or if we need to make a new join, and if so is it from one of our
        existing entities.

        Nr   zrCan't identify which entity in which to assign the left side of this join.   Please use a more specific ON clause.r   r  )r!   r²  r1  Ú#find_left_clause_that_matches_givenr�   r  rM  rÜ  rú  rc  r  r  Úcorresponds_to)	r‹   rO  rV  r]  r^  Úl_inforf  Úidxr  r|   r|   r}   rY  [  s0   ÿÿ
ÿþ€ z4ORMSelectCompileState._join_place_explicit_left_sidec              	   C  sz  t |ƒ}t |ƒ}d}t|ddƒ}|r8|jst|jtjƒr8| jp"|jgD ]}	t	 
|j|	¡r7t	 
|	|j¡r7d} nq#|rH|j|ju rHt d|j ¡‚t|ddƒ|jt|ddƒ}}
}|rl|rl| |j¡slt d||f ¡‚t|dƒry|  j|f7  _d}|jrÆ|rƒ|j}|
jr”|  ¡ }|dur“||dƒ}n2|rÆ|
 |j¡s¨t d|
j|jjf ¡‚t|
tjƒr·t tj|
¡}
d}t||
ƒ}tjd	| d
dd� |oÌ| oÌ|}|sâ|rât|dd�}d}tjd| dd� |rú|sèJ ‚tt j!t |ƒ|j"d�}|  #||¡ n|j�s|�s|j$�r|  #|tt j%||j|j"d�¡ t|tj&ƒ�r'|  ¡ }|�r'||dƒ}|�r6|  j'|||j(ff7  _'t |ƒ||fS )zútransform the "right" side of the join as well as the onclause
        according to polymorphic mapping translations, aliasing on the query
        or on the join, special cases where the right and left side have
        overlapping tables.

        Fr  NTz*Can't join table/selectable '%s' to itselfr  zIJoin target %s does not correspond to the right side of join condition %sz(Selectable '%s' is not derived from '%s'zÕAn alias is being generated automatically against joined entity %s for raw clauseelement, which is deprecated and will be removed in a later release. Use the aliased() construct explicitly, see the linked example.z1.4Úxaj1)Úcode)Úflatz÷An alias is being generated automatically against joined entity %s due to overlapping tables.  This is a legacy pattern which may be deprecated in a later release.  Use the aliased(<entity>, flat=True) construct explicitly, see the linked example.Úxaj2rù  )r�   r  ))r!   ró   Úwith_polymorphicr  r  r%   ÚJoinr²  r�   r1  Úselectables_overlaprM  rÜ  Úcommon_parentr  rú  rÆ  Úis_clause_elementÚ_is_lateralrn  Úis_derived_fromÚdescriptionrO   r$   r  r&   ÚFromClauseRoler   r#   Úwarn_deprecatedÚwarnr   r   Ú DEPRECATED_JOIN_ADAPT_RIGHT_SIDEr  r  Ú#_has_aliased_polymorphic_fromclauseÚ#WITH_POLYMORPHIC_ADAPTER_RIGHT_JOINÚClauseElementrL  rò   )r‹   rV  rP  rQ  r=  rm  r_  ÚoverlapÚright_mapperr   Úright_selectableÚright_is_aliasedÚneed_adapterrj  Úaliased_entityr$  r|   r|   r}   rZ  �  sè   ÿþÿÿþ€ÿÿ


ýÿþ
ýÿÿ

€ÿþÿÿ
ÿ
ûøûù
ý
ÿþýüþ
z6ORMSelectCompileState._join_check_and_adapt_right_sidec                 C  sF   | j j| j j| j| j| j j| j j| jpd | j j| j j	| j j
| j jdœS )N)r/  r0  rÕ  rÓ  r3  r4  rÏ  r1  r2  r5  r6  )rŽ   r$  r%  rÕ  rÓ  r*  r+  rÏ  r&  r'  r(  r)  rŠ   r|   r|   r}   r  Z	  s   òz"ORMSelectCompileState._select_argsc                 C  sF   | j }| d¡d up"| d¡d up"| dd¡p"| dd¡p"| dd¡S )Nr/  r0  rÕ  FrÓ  r|   rÏ  )r  r¢   )r‹   Úkwargsr|   r|   r}   rÞ  n	  s   ÿ
þ
ý
ûz-ORMSelectCompileState._should_nest_selectablec                   s8   dˆ j fˆjv rt‡ ‡fdd„ˆjdˆ j f D ƒƒS dS )NÚadditional_entity_criteriac                 3  s4   � | ]}|j s|jˆ u r| ˆ¡r| ˆ ¡V  qd S r„   )Úinclude_aliasesrg  Ú_should_includeÚ_resolve_where_criteria)r‡   Úae©r  r‹   r|   r}   rŒ   ~	  s   € û
ÿüûz<ORMSelectCompileState._get_extra_criteria.<locals>.<genexpr>r|   )r  rž   r�   )r‹   r  r|   rŽ  r}   r[  y	  s   þýÿþ	z)ORMSelectCompileState._get_extra_criteriac           	      C  s
  | j D ]+}|j dd¡}|r.|jjdusd|jf| jv r.|| jvr.||jr(|jndf| j|< qt	| j 
¡ ƒ}|D ]J\}}|| jv rBq8|jj}| jjrMg }n|  |¡}|dur[||f7 }|  ¡ }|D ] }|rj| |¡}|ryt |ddi¡}||dƒ}|  j|f7  _qaq8dS )aà  Apply extra criteria filtering.

        For all distinct single-table-inheritance mappers represented in
        the columns clause of this query, as well as the "select from entity",
        add criterion to the WHERE
        clause of the given QueryContext such that only the appropriate
        subtypes are selected from the total results.

        Additionally, add WHERE criteria originating from LoaderCriteriaOptions
        associated with the global context.

        rð  Nr‰  r<  TF)r²  rë  r¢   r  Ú_single_table_criterionrž   r\  r  rü  rY  r
  rÆ  rÜ   rÐ   r[  rn  Útraverser1  Ú_deep_annotaterÊ  )	r‹   Ú
fromclauser  r9  r$  Úsingle_critr‰  rj  r¼  r|   r|   r}   rÛ  ‰	  sB   
ÿÿ

þ€




ùñz0ORMSelectCompileState._adjust_for_extra_criteria)
r   rç   r§   rÞ   r¦   ré   r­   r   r–   r…  r„   )0rm   rn   ro   rL  r�   r­  re  r(  ru  rv  rw  rx  r×  rÙ  rÊ  rÌ  rÁ   rè   r¹  r³  r'  rè  rï  rò  rõ  rÇ  rø  rá  r  r  r	  rþ  rß  rà  r  r:  rk  rn  rÉ  rM  rX  rY  rZ  r)  r  rÞ  r[  rÛ  r|   r|   r|   r}   r…  -  sl     # 





	[M0_cjB >


r…  FÚquery_or_select_stmtú#Union[Query, Select, FromStatement]rU   úOptional[ORMSelectCompileState]rñ   rÞ   r–   úList[ORMColumnDescription]c                 C  s8   |d u rt j| |d�}|}dd„ dd„ |jD ƒD ƒ}|S )N)rñ   c              
   S  sJ   g | ]!\}}|j |jt|d dƒ|j|jdur|jst|ddƒnddœ‘qS )r  FNrg  )rö   ÚtypeÚaliasedÚexprrg  )Ú_label_namer˜  ró   rš  r  rw  )r‡   r  Úinsp_entr|   r|   r}   r  Í	  s    õ

ÿÿ÷ÿz(_column_descriptions.<locals>.<listcomp>c                 S  s   g | ]}||j f‘qS r|   ©r  )r‡   Ú_entr|   r|   r}   r  Ú	  s    
ÿ)r…  r'  rÚ   )r”  rU   rñ   r	  Údr|   r|   r}   rø   Ã	  s   ÿÿórø   Úquery_or_augmented_selectúUnion[Query[Any], Select[Any]]ú"Optional[_InternalEntityType[Any]]c                 C  sJ   | }|j r|j}|d ur|S |jr!d|jd jv r!|jd jd S t|ƒS )Nrð  r   )rÈ  Ú_last_joined_entityr±  rë  Ú_entity_from_pre_ent_zero)r   r‹   r£  r|   r|   r}   Ú_legacy_filter_by_entity_zeroá	  s   r¥  c                 C  sT   | }|j sd S |j d }d|jv r|jd S t|tƒr|jS d|jv r(|jd S |S )Nr   rð  Úbundle)rW  rë  r  r   rg  )r   r‹   r  r|   r|   r}   r¤  ð	  s   





r¤  rç  úTuple[_SetupJoinsElement, ...]r  ú=Optional[Union[_InternalEntityType[Any], _JoinTargetElement]]c                 C  s.   | sd S | d \}}}}t |tjƒr|jS |S )Néÿÿÿÿ)r  r   rK  rg  )rç  r  ÚtargetrQ  rR  rS  r|   r|   r}   ræ  
  s   þræ  c                   @  sr   e Zd ZU dZdZded< dZdZdZded< ded	< d
ed< ded< ddd„Z	ddd„Z
dd„ Zedd„ ƒZdS )rU  z:represent an entity column returned within a Query result.r|   rÞ   Úsupports_single_entityFzOptional[str]r›  z!Union[Type[Any], TypeEngine[Any]]r˜  z.Union[_InternalEntityType, ColumnElement[Any]]rš  zOptional[_InternalEntityType]r  rU   rl   r–   ÚNonec                 C  r´   r„   rµ   ©r‹   rU   r|   r|   r}   r]  %
  ræ   z _QueryEntity.setup_compile_stater$  ú Optional[_DMLReturningColFilter]c                 C  r´   r„   rµ   ©r‹   rU   r$  r|   r|   r}   rs  (
  s   z._QueryEntity.setup_dml_returning_compile_statec                 C  r´   r„   rµ   )r‹   r
  r½   r|   r|   r}   Úrow_processor/
  ræ   z_QueryEntity.row_processorc                 C  sÚ   t |ƒD ]f\}}|jr|jr|  ||j||¡ q|j}|jra|jr9d|jv r.t||||ƒ qt	 
||j|||¡ q|j dd¡rHt||||ƒ q|jrVt	 
||j|||¡ qt	 
||g|||¡ q|jrjt|||ƒ q|S )Nrð  r¦  F)rc  Ú_is_lambda_elementÚ_is_sequencerV  Ú	_resolvedrw  rê  rë  r  Ú_ColumnEntityÚ_for_columnsÚ_select_iterabler¢   Ú_BundleEntityÚ_is_clause_listÚ	is_bundle)r±   rU   r{  rO  rI  rn  rg  r|   r|   r}   rV  2
  sj   ü
üûüûû€z_QueryEntity.to_compile_stateN)rU   rl   r–   r¬  ©rU   rl   r$  r®  r–   r¬  )rm   rn   ro   rÇ   r˜   r™   Ú_non_hashable_valueÚ_null_column_typeÚuse_id_for_hashr]  rs  r°  rÁ   rV  r|   r|   r|   r}   rU  
  s    
 

rU  c                   @  sœ   e Zd ZU dZdZded< ded< ded< ded	< d
ed< ded< dd„ ZdZdZdZ	e
dd„ ƒZe
dd„ ƒZdd„ Zdd„ Zdd„ Zd&d!d"„Zd#d$„ Zd%S )'r  z mapper/class/AliasedClass entity)
rš  r  r  r  ÚpathÚ_extra_entitiesr›  r"  r�   Ú_polymorphic_discriminatorr>   rš  zMapper[Any]r  r  rÞ   r  r   r¾  Ústrr›  c                 C  sÄ   |  | ¡ |r|jd u r| |_d|_d|_|jd }|j | }| _|j}|| _|j	 | _	}| jf| _
|jr;|j| _n|jj| _|j| _|j| _|j| _|j| _|j| _|jr`| || j¡ d S d S )NTrð  )rë   rÝ   r(  ru  rë  Ú_post_inspectr  rg  rš  r  r¿  r  rö   r›  Úclass_rm   r×   r¾  r�   Úwith_polymorphic_mappersr"  Úpolymorphic_onrÀ  Ú _should_select_with_poly_adapterr!  )r‹   rU   rg  rO  rI  r  r  r|   r|   r}   r•   ‹
  s4   






ÿÿz_MapperEntity.__init__Tc                 C  r’  r„   )r  rÃ  rŠ   r|   r|   r}   r˜  µ
  rû   z_MapperEntity.typec                 C  s   | j S r„   r�  rŠ   r|   r|   r}   rd  ¹
  s   z'_MapperEntity.entity_zero_or_selectablec                 C  s   t | j|ƒS r„   )r   r  ©r‹   rg  r|   r|   r}   rl  ½
  s   z_MapperEntity.corresponds_toc                 C  sV   d }| j s|jr|j | jd ¡}n| jj}|r&|jr"| |j¡}|S |}|S |j}|S r„   )r  rÛ   r¢   r  r  rü  re  Úwrap)r‹   rU   r$  Úretr|   r|   r}   Ú_get_entity_clausesÀ
  s    ÿ€üþz!_MapperEntity._get_entity_clausesc                 C  s„   |j }|  |¡}|jr|r| |j¡}n|s|j}|j| u r&|jj}|j}nd  }}tj	| | j
||| j|||| jd�	}|| j| jfS )N)Úonly_load_propsra   Úpolymorphic_discriminator)rU   rÊ  rx  rÈ  rÝ   rÜ   rÎ   ra   r   Ú_instance_processorr  r¾  rÀ  r›  r¿  )r‹   r
  r½   rU   r$  rË  ra   Ú	_instancer|   r|   r}   r°  Õ
  s,   


÷z_MapperEntity.row_processorrU   rl   r$  r®  r–   r¬  c                 C  s.   t j|| j| | j||j| j|jj| jd�	 d S )N©rs  rË  rÌ  )	r   Ú_setup_entity_queryr  r¾  rá   r"  rÜ   rÎ   rÀ  r¯  r|   r|   r}   rs  ò
  s   
÷z/_MapperEntity.setup_dml_returning_compile_statec                 C  s†   |   |¡}| jj}|d usd| jf|jv r%| j}||jr|jnd f|j|< tj	|| j| | j
||j| j|jj| jd�	 |j | j¡ d S )Nr‰  rÏ  )rÊ  r  r�  rž   r  r  rü  r\  r   rÐ  r¾  rá   r"  rÜ   rÎ   rÀ  rZ  rë   r�   )r‹   rU   r$  Úsingle_table_critr  r|   r|   r}   r]    s,   
ÿ
þ÷z!_MapperEntity.setup_compile_stateNrº  )rm   rn   ro   rÇ   r˜   r™   r•   r«  r»  r½  r)  r˜  rd  rl  rÊ  r°  rs  r]  r|   r|   r|   r}   r  t
  s,   
 %


r  c                   @  sš   e Zd ZU dZdZded< ded< ded< d	ed
< ded< ded< 		d&dd„Zedd„ ƒZedd„ ƒZ	dd„ Z
edd„ ƒZdd„ Zd'd"d#„Zd$d%„ ZdS )(r·  r|   )r¦  rš  r˜  r›  rÚ   r«  rÙ   rÚ   r   r¦  z	Type[Any]r˜  rÁ  r›  rÞ   r«  rš  TNc              	   C  sâ   d|_ |jd }|r|j | ¡ n| | ¡ t|tjtjfƒr$| 	¡ }n|}| | _
| _t|ƒ| _|j| _g | _|rj|jD ],}d|jv rNt||||| d� q=t|tƒr]t||||| d� q=tj||g|d || d� q=| j
j| _d S )NTr¦  ©Úparent_bundle)ru  rë  rÚ   rë   r  r   rK  r   rH  rñ  r¦  rš  r˜  rö   r›  Úexprsr·  r   Ú_ORMColumnEntityrµ  Úsingle_entityr«  )r‹   rU   rš  rO  rI  Úsetup_entitiesrÓ  r¦  r|   r|   r}   r•   3  sR   	

ÿ



û
ûú	z_BundleEntity.__init__c                 C  s   | j }|d ur
|jS d S r„   )r  r  )r‹   rå  r|   r|   r}   r  n  s   z_BundleEntity.mapperc                 C  ó&   | j D ]}|j}|d ur|  S qd S r„   )rÚ   r  ©r‹   r  rå  r|   r|   r}   r  v  ó   
ÿz_BundleEntity.entity_zeroc                 C  ó   dS r¾  r|   rÇ  r|   r|   r}   rl    s   z_BundleEntity.corresponds_toc                 C  rØ  r„   )rÚ   rd  rÙ  r|   r|   r}   rd  „  rÚ  z'_BundleEntity.entity_zero_or_selectablec                 C  s   | j D ]}| |¡ qd S r„   )rÚ   r]  )r‹   rU   r  r|   r|   r}   r]  �  s   
ÿz!_BundleEntity.setup_compile_staterU   rl   r$  r®  r–   r¬  c                 C  ó
   |   |¡S r„   ©r]  r¯  r|   r|   r}   rs  ‘  ó   
z/_BundleEntity.setup_dml_returning_compile_statec                   s@   t ‡ ‡fdd„| jD ƒŽ \}}}| j ˆ j||¡}|| j| jfS )Nc                   s   g | ]}|  ˆ ˆ¡‘qS r|   )r°  r  ©r
  r½   r|   r}   r  š  s    z/_BundleEntity.row_processor.<locals>.<listcomp>)r‘   rÚ   r¦  Úcreate_row_processorrV   r›  r¿  )r‹   r
  r½   ÚprocsÚlabelsÚextraÚprocr|   rß  r}   r°  ˜  s
   
ÿz_BundleEntity.row_processorrº  rº  )rm   rn   ro   r¿  r˜   r™   r•   r)  r  r  rl  rd  r]  rs  r°  r|   r|   r|   r}   r·     s,   
 	
ù;



r·  c                   @  sL   e Zd ZdZe	ddd„ƒZedd„ ƒZedd„ ƒZed	d
„ ƒZ	dd„ Z
dS )r´  )Ú_fetch_columnÚ_row_processorÚraw_column_indexÚtranslate_raw_columnNc           
   
   C  s„   |D ]=}|j }d|v r|d }	nt |d¡}	|	r5d|j v r)t||||	|||d� qt||||	|||d� qt||||||d� qd S )Nrð  rg   rÒ  )rë  r1  Úextract_first_column_annotationÚ_IdentityTokenEntityrÕ  Ú_RawColumnEntity)
r±   rU   r+  rO  rç  rI  rÓ  Úcolumnr   Ú_entityr|   r|   r}   rµ  ª  sH   

ÿ
ù
ù
úáz_ColumnEntity._for_columnsc                 C  r’  r„   )rì  r˜  rŠ   r|   r|   r}   r˜  Ü  rû   z_ColumnEntity.typec                 C  s   | j jj S r„   )rì  r˜  ÚhashablerŠ   r|   r|   r}   r»  à  r  z!_ColumnEntity._non_hashable_valuec                 C  s
   | j jjS r„   )rì  r˜  Ú_isnullrŠ   r|   r|   r}   r¼  ä  s   
z_ColumnEntity._null_column_typec           	      C  sÔ   |j }| jd ur | j\}}}| jr||jj| j f7 }|||fS | jd ur)| j}n| j}|jr5|jj	| }|j
r<| ¡ }|jrE|jj	| }| |¡}|| j| jf}|| _| jrh| j|jj| j f }|| j|fS |S r„   )rU   ræ  rè  rV   rW  rç  rå  rì  re  r+  rë  Ú_deannotaterx  Ú_getterr›  r¿  )	r‹   r
  r½   rU   ÚgetterÚ
label_nameÚextra_entitiesrì  rÉ  r|   r|   r}   r°  è  s4   
ÿ


ÿz_ColumnEntity.row_processorr„   )rm   rn   ro   r˜   rÁ   rµ  r)  r˜  r»  r¼  r°  r|   r|   r|   r}   r´  ¢  s    ù1


r´  c                   @  sB   e Zd ZdZdZdZdZ	ddd„Zdd„ Zddd„Z	dd„ Z
dS )rë  NF)rš  rì  r›  rd  r¿  c                 C  s´   || _ || _|d u| _|jr| jddi7  _|r|jr d | _n|r'|j| _n| |¡| _|r6|j	 
| ¡ n| 
| ¡ || _| jjrH| jjd nd | _| j | jf| _d  | _| _d S )NrÒ   Tr   )rš  rç  rè  rÒ   rÜ   Ú_is_text_clauser›  Ú
_proxy_keyrà   rÚ   rë   rì  r‹  rd  r¿  rå  ræ  )r‹   rU   rì  rO  rç  rI  rÓ  r|   r|   r}   r•   (  s$   	



ÿz_RawColumnEntity.__init__c                 C  rÛ  r¾  r|   rÇ  r|   r|   r}   rl  L  rl  z_RawColumnEntity.corresponds_torU   rl   r$  r®  r–   r¬  c                 C  rÜ  r„   rÝ  r¯  r|   r|   r}   rs  O  rÞ  z2_RawColumnEntity.setup_dml_returning_compile_statec                 C  s\   |  ¡ }|r|| jdƒ}|d u rd S n| j}|jr| ¡ }|j |¡ |j |¡ || _d S r¾  )	rn  rì  rë  rð  rã   rê   rá   rë   rå  )r‹   rU   rj  rì  r|   r|   r}   r]  V  s   ÿ
z$_RawColumnEntity.setup_compile_stater„   rº  )rm   rn   ro   r  r  r«  r˜   r•   rl  rs  r]  r|   r|   r|   r}   rë    s    
ù$
rë  c                   @  s>   e Zd ZdZdZdZ	ddd„Zdd„ Zddd„Zdd„ Z	dS )rÕ  zColumn/expression based entity.F)rš  r  rì  r›  rd  r  r¿  Nc                 C  s  |j }|}	| dd ¡}
| d|	¡}|
rt|j|
ƒ| _d| _n|| _|d u| _|| _|r?|r6|
r1|
n|j| _n|j	||
d�| _nd | _|	j
 |	 | _ | _}|	j | _}|r\|j | ¡ n| | ¡ d|_|| _d  | _| _| j| jf| _|jr€| ||j¡ d S d S )NÚ	proxy_keyÚproxy_ownerF)rõ   T)rë  r¢   ró   rg  rš  rè  rç  rö  r›  rà   rÂ  r  rd  r  rÚ   rë   ru  rì  rå  ræ  r¿  rÆ  r!  r�   )r‹   rU   rì  rO  rð  rç  rI  rÓ  r   rí  Úorm_keyrø  rå  r  r|   r|   r}   r•   x  s@   


ÿ
ÿÿz_ORMColumnEntity.__init__c                 C  s*   t |ƒr	|| ju S t | jƒ o| | j¡S r„   )r   r  rv  rÇ  r|   r|   r}   rl  »  s   
ÿ
þz_ORMColumnEntity.corresponds_torU   rl   r$  r®  r–   r¬  c                 C  sB   | j  | _}|r||dƒ}|d ur|j |¡ |j |¡ d S d S r¾  )rì  rå  rã   rê   rá   rë   )r‹   rU   r$  rì  r|   r|   r}   rs  Ä  s   
þz2_ORMColumnEntity.setup_dml_returning_compile_statec                 C  sØ   |  ¡ }|r|| jdƒ}|d u r|jsJ ‚| j| _d S n| j}| j}| jj}|d us2d| jf|jv r?||jr9|j	nd f|j
|< |jrI|jsI| ¡ }t| jjƒ |jj¡r[|j |j¡ |j |¡ |j |¡ || _d S )NFr‰  )rn  rì  rÀ   rå  r  r  r�  rž   r  rü  r\  rë  Ú_expression_labelrð  rY  r‹  Úintersectionr�   rZ  rë   rã   rê   rá   )r‹   rU   rj  rì  rå  rÑ  r|   r|   r}   r]  Ò  s6   
ýÿ
þÿ
z$_ORMColumnEntity.setup_compile_stater„   rº  )
rm   rn   ro   rÇ   r«  r˜   r•   rl  rs  r]  r|   r|   r|   r}   rÕ  i  s    
øC
	rÕ  c                   @  s    e Zd ZdZdd„ Zdd„ ZdS )rê  Fc                 C  rm  r„   r|   r­  r|   r|   r}   r]    rl  z(_IdentityTokenEntity.setup_compile_statec                   s   ‡ fdd„}|| j | jfS )Nc                   s   ˆ j jS r„   )rY   ru   )Úrow©r
  r|   r}   rò    s   z2_IdentityTokenEntity.row_processor.<locals>.getter)r›  r¿  )r‹   r
  r½   rò  r|   rý  r}   r°    s   z"_IdentityTokenEntity.row_processorN)rm   rn   ro   rè  r]  r°  r|   r|   r|   r}   rê  þ  s    rê  r¾  )r”  r•  rU   r–  rñ   rÞ   r–   r—  )r   r¡  r–   r¢  r„   )rç  r§  r  r¢  r–   r¨  )�Ú
__future__r   rŽ  Útypingr   r   r   r   r   r   r	   r
   r   r   r   r   Ú r   r   r   Úbaser   r   r   Úpath_registryr   r#   r   r   r   r   r   r   r   r   rM  r    r!   r"   r$   r%   r&   r1  r'   Úsql._typingr(   r)   r*   r+   Úsql.baser,   r-   r.   r/   r0   r1   Úsql.dmlr2   Úsql.elementsr3   r4   Úsql.selectabler5   r6   r7   r8   r9   r:   r;   r<   Úsql.visitorsr=   Ú_typingr>   r?   r@   r  rA   rV   rB   r\   rC   rD   ÚenginerE   Úengine.interfacesrF   rG   Úsql.compilerrH   rI   rJ   rK   rL   rM   rN   rO   Úsql.type_apirP   rQ   Úrootr×   r©  r�   r«  rS   r  r›   rÃ   rl   r*  r8  r@  Ú
plugin_forrC  rD  r¢  r…  rø   r¥  r¤  ræ  rU  r  r·  r´  rë  rÕ  rê  r|   r|   r|   r}   Ú<module>   s  tÿl-  +' ;x
ÿ           "ý

þ_ - yN 