U
    ÓZj@
  ã                   @  sp   d dl mZ d dlZd dlZd dlZd dlZd dlm	Z	 ej
rJddlmZ G dd„ dejjƒZdd	œd
d„ZdS )é    )ÚannotationsN)Úapp_ctxé   )Ú
SQLAlchemyc                      sF   e Zd ZdZddddœ‡ fdd„Zdd	d	d
dddœ‡ fdd„Z‡  ZS )ÚSessiona�  A SQLAlchemy :class:`~sqlalchemy.orm.Session` class that chooses what engine to
    use based on the bind key associated with the metadata associated with the thing
    being queried.

    To customize ``db.session``, subclass this and pass it as the ``class_`` key in the
    ``session_options`` to :class:`.SQLAlchemy`.

    .. versionchanged:: 3.0
        Renamed from ``SignallingSession``.
    r   zt.AnyÚNone)ÚdbÚkwargsÚreturnc                   s   t ƒ jf |Ž || _i | _d S )N)ÚsuperÚ__init__Ú_dbZ_model_changes)Úselfr   r	   ©Ú	__class__© ú[/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/flask_sqlalchemy/session.pyr      s    zSession.__init__Nzt.Any | Nonez.sa.engine.Engine | sa.engine.Connection | Nonez'sa.engine.Engine | sa.engine.Connection)ÚmapperÚclauseÚbindr	   r
   c              
     sæ   |dk	r|S |dk	rlzt  |¡}W nB t jjk
rd } z t|tƒrRt jj |¡|‚‚ W 5 d}~X Y nX |j}| j	j
}t|t jƒr¼d|jjkr¼|jjd }||kr´t j d|› d�¡‚|| S d|krÌ|d S tƒ jf |||dœ|—ŽS )az  Select an engine based on the ``bind_key`` of the metadata associated with
        the model or table being queried. If no bind key is set, uses the default bind.

        .. versionchanged:: 3.0
            The implementation more closely matches the base SQLAlchemy implementation.

        .. versionchanged:: 2.1
            Support joining an external transaction.
        NZbind_keyz
Bind key 'z&' is not in 'SQLALCHEMY_BINDS' config.)r   r   r   )ÚsaÚinspectÚexcZNoInspectionAvailableÚ
isinstanceÚtypeÚormZUnmappedClassErrorZpersist_selectabler   ÚenginesÚTableÚmetadataÚinfoZUnboundExecutionErrorr   Úget_bind)r   r   r   r   r	   Úer   Úkeyr   r   r   r       s*    

ÿzSession.get_bind)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    Ú__classcell__r   r   r   r   r      s      ür   Úint)r
   c                   C  s   t t ¡ ƒS )zJGet the id of the current Flask application context for the session scope.)Úidr   Z_get_current_objectr   r   r   r   Ú_app_ctx_idO   s    r*   )Ú
__future__r   ÚtypingÚtZ
sqlalchemyr   Zsqlalchemy.excZsqlalchemy.ormZflask.globalsr   ÚTYPE_CHECKINGÚ	extensionr   r   r   r*   r   r   r   r   Ú<module>   s   A