o
    gu                     @  s  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 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) ej*de+dZ,ej*dej-ej.e ej/ej.ej0 ej.ej1 f dZ2G dd deZ3d!ddZ4G dd  d Z5dS )"    )annotationsN)WeakKeyDictionary)abort)current_app)Flask)has_app_context   )_QueryProperty)	BindMixin)DefaultMeta)DefaultMetaNoName)Model)	NameMixin)
Pagination)SelectPagination)Query)_app_ctx_id)Session_Table_O)bound_FSA_MCTc                   @  s   e Zd ZU ded< dS )	_FSAModelsa.MetaDatametadataN)__name__
__module____qualname____annotations__ r    r    \/var/www/html/ecg_monitoring/venv/lib/python3.10/site-packages/flask_sqlalchemy/extension.pyr   /   s   
 r   model_classreturnKlist[t.Type[t.Union[sa_orm.DeclarativeBase, sa_orm.DeclarativeBaseNoMeta]]]c                 C  s   dd | j D S )Nc                 S  s"   g | ]}t |tjtjfr|qS r    )
issubclasssa_ormDeclarativeBaseDeclarativeBaseNoMeta).0br    r    r!   
<listcomp>6   s    z-_get_2x_declarative_bases.<locals>.<listcomp>)	__bases__)r"   r    r    r!   _get_2x_declarative_bases3   s   r-   c                	   @  sx  e Zd ZdZ	dwddeedddddxddZdyddZdzddZd{d!d"Z	d|d$d%Z
d}d(d)Zd~d-d.Zdd0d1Z	ddd3d4Zdd5d6Zdd8d9Zedd:d;Zedd=d>Zedd?d@Z	dwddCdDZddEddKdLZddEddOdPZddEddQdRZddddddSdd\d]Zdd`daZdddcddZdddedfZdddgdhZddidjZddmdnZddpdqZ ddrdsZ!ddudvZ"dS )
SQLAlchemya[  Integrates SQLAlchemy with Flask. This handles setting up one or more engines,
    associating tables and models with specific engines, and cleaning up connections and
    sessions after each request.

    Only the engine configuration is specific to each application, other things like
    the model, table, metadata, and session are shared for all applications using that
    extension instance. Call :meth:`init_app` to configure the extension on an
    application.

    After creating the extension, create model classes by subclassing :attr:`Model`, and
    table classes with :attr:`Table`. These can be accessed before :meth:`init_app` is
    called, making it possible to define the models separately from the application.

    Accessing :attr:`session` and :attr:`engine` requires an active Flask application
    context. This includes methods like :meth:`create_all` which use the engine.

    This class also provides access to names in SQLAlchemy's ``sqlalchemy`` and
    ``sqlalchemy.orm`` modules. For example, you can use ``db.Column`` and
    ``db.relationship`` instead of importing ``sqlalchemy.Column`` and
    ``sqlalchemy.orm.relationship``. This can be convenient when defining models.

    :param app: Call :meth:`init_app` on this Flask application now.
    :param metadata: Use this as the default :class:`sqlalchemy.schema.MetaData`. Useful
        for setting a naming convention.
    :param session_options: Arguments used by :attr:`session` to create each session
        instance. A ``scopefunc`` key will be passed to the scoped session, not the
        session instance. See :class:`sqlalchemy.orm.sessionmaker` for a list of
        arguments.
    :param query_class: Use this as the default query class for models and dynamic
        relationships. The query interface is considered legacy in SQLAlchemy.
    :param model_class: Use this as the model base class when creating the declarative
        model class :attr:`Model`. Can also be a fully created declarative model class
        for further customization.
    :param engine_options: Default arguments used when creating every engine. These are
        lower precedence than application config. See :func:`sqlalchemy.create_engine`
        for a list of arguments.
    :param add_models_to_shell: Add the ``db`` instance and all model classes to
        ``flask shell``.

    .. versionchanged:: 3.1.0
        The ``metadata`` parameter can still be used with SQLAlchemy 1.x classes,
        but is ignored when using SQLAlchemy 2.x style of declarative classes.
        Instead, specify metadata on your Base class.

    .. versionchanged:: 3.1.0
        Added the ``disable_autonaming`` parameter.

    .. versionchanged:: 3.1.0
        Changed ``model_class`` parameter to accepta SQLAlchemy 2.x
        declarative base subclass.

    .. versionchanged:: 3.0
        An active Flask application context is always required to access ``session`` and
        ``engine``.

    .. versionchanged:: 3.0
        Separate ``metadata`` are used for each bind key.

    .. versionchanged:: 3.0
        The ``engine_options`` parameter is applied as defaults before per-engine
        configuration.

    .. versionchanged:: 3.0
        The session class can be customized in ``session_options``.

    .. versionchanged:: 3.0
        Added the ``add_models_to_shell`` parameter.

    .. versionchanged:: 3.0
        Engines are created when calling ``init_app`` rather than the first time they
        are accessed.

    .. versionchanged:: 3.0
        All parameters except ``app`` are keyword-only.

    .. versionchanged:: 3.0
        The extension instance is stored directly as ``app.extensions["sqlalchemy"]``.

    .. versionchanged:: 3.0
        Setup methods are renamed with a leading underscore. They are considered
        internal interfaces which may change at any time.

    .. versionchanged:: 3.0
        Removed the ``use_native_unicode`` parameter and config.

    .. versionchanged:: 2.4
        Added the ``engine_options`` parameter.

    .. versionchanged:: 2.1
        Added the ``metadata``, ``query_class``, and ``model_class`` parameters.

    .. versionchanged:: 2.1
        Use the same query class across ``session``, ``Model.query`` and
        ``Query``.

    .. versionchanged:: 0.16
        ``scopefunc`` is accepted in ``session_options``.

    .. versionchanged:: 0.10
        Added the ``session_options`` parameter.
    NTF)r   session_optionsquery_classr"   engine_optionsadd_models_to_shelldisable_autonamingappFlask | Noner   sa.MetaData | Noner/   dict[str, t.Any] | Noner0   type[Query]r"   r   r1   r2   boolr3   c          	      C  s   |d u ri }|| _ 	 | || _	 i | _	 |d ur4tt|dkr*tjdtdd n
d |j	d< || jd < | 
 | _	 | j||d| _	 |d u rIi }|| _|  t | _|| _|d ur`| | d S d S )Nr   zWhen using SQLAlchemy 2.x style of declarative classes, the `metadata` should be an attribute of the base class.The metadata passed into SQLAlchemy() is ignored.   
stacklevelbind_key)r3   )r   _make_scoped_sessionsession	metadataslenr-   warningswarnDeprecationWarninginfo_make_table_classTable_make_declarative_baser   _engine_optionsr   _app_engines_add_models_to_shellinit_app)	selfr4   r   r/   r0   r"   r1   r2   r3   r    r    r!   __init__   s@   	


zSQLAlchemy.__init__r#   strc                 C  sb   t  sdt| j dS t| j d| jj }t| jdkr+| dt| jd  }d| dS )N<> r   z +)r   typer   engineurlrA   engines)rM   messager    r    r!   __repr__  s   zSQLAlchemy.__repr__r   Nonec                 C  s  d|j v r	td| |j d< || j | jr"ddlm} || |j	dd}| j
 }||j	di  |j	dd	}|j	d
i }i }| D ]"\}}	| j
 ||< t|	ttjjfrg|	|| d< qL|| |	 qL|durw||d< d|v r|	di | |std| j	|i }
|
r|
 D ]}|  q|
  | D ]$\}}| | |	d| |	d| | || | ||||
|< q|j	dd	rddlm} |
 D ]}|| q|j	dd	rddlm} || j dS dS )aN  Initialize a Flask application for use with this extension instance. This
        must be called before accessing the database engine or session with the app.

        This sets default configuration values, then configures the extension on the
        application and creates the engines for each bind key. Therefore, this must be
        called after the application has been configured. Changes to application config
        after this call will not be reflected.

        The following keys from ``app.config`` are used:

        - :data:`.SQLALCHEMY_DATABASE_URI`
        - :data:`.SQLALCHEMY_ENGINE_OPTIONS`
        - :data:`.SQLALCHEMY_ECHO`
        - :data:`.SQLALCHEMY_BINDS`
        - :data:`.SQLALCHEMY_RECORD_QUERIES`
        - :data:`.SQLALCHEMY_TRACK_MODIFICATIONS`

        :param app: The Flask application to initialize.
        
sqlalchemyzlA 'SQLAlchemy' instance has already been registered on this Flask app. Import and use that instance instead.r   )r2   SQLALCHEMY_DATABASE_URINSQLALCHEMY_ENGINE_OPTIONSSQLALCHEMY_ECHOFSQLALCHEMY_BINDSrU   zCEither 'SQLALCHEMY_DATABASE_URI' or 'SQLALCHEMY_BINDS' must be set.echo	echo_poolSQLALCHEMY_RECORD_QUERIES)record_queriesSQLALCHEMY_TRACK_MODIFICATIONS)track_modifications)
extensionsRuntimeErrorteardown_appcontext_teardown_sessionrK   clir2   shell_context_processorconfig
setdefaultrI   copyupdateitems
isinstancerO   sarT   URLrJ   valuesdisposeclear_make_metadata_apply_driver_defaults_make_engine rb   _listenrd   r?   )rM   r4   r2   	basic_uribasic_engine_optionsr_   config_bindsr1   keyvaluerV   rT   optionsrb   rd   r    r    r!   rL   #  sh   





zSQLAlchemy.init_appr   dict[str, t.Any]sa_orm.scoped_session[Session]c                 C  s"   | dt}| |}t||S )aX  Create a :class:`sqlalchemy.orm.scoping.scoped_session` around the factory
        from :meth:`_make_session_factory`. The result is available as :attr:`session`.

        The scope function can be customized using the ``scopefunc`` key in the
        ``session_options`` parameter to the extension. By default it uses the current
        thread or greenlet id.

        This method is used for internal setup. Its signature may change at any time.

        :meta private:

        :param options: The ``session_options`` parameter from ``__init__``. Keyword
            arguments passed to the session factory. A ``scopefunc`` key is popped.

        .. versionchanged:: 3.0
            The session is scoped to the current app context.

        .. versionchanged:: 3.0
            Renamed from ``create_scoped_session``, this method is internal.
        	scopefunc)popr   _make_session_factoryr&   scoped_session)rM   r   scopefactoryr    r    r!   r>     s   
zSQLAlchemy._make_scoped_sessionsa_orm.sessionmaker[Session]c                 C  s.   | dt | d| j tjdd| i|S )a  Create the SQLAlchemy :class:`sqlalchemy.orm.sessionmaker` used by
        :meth:`_make_scoped_session`.

        To customize, pass the ``session_options`` parameter to :class:`SQLAlchemy`. To
        customize the session class, subclass :class:`.Session` and pass it as the
        ``class_`` key.

        This method is used for internal setup. Its signature may change at any time.

        :meta private:

        :param options: The ``session_options`` parameter from ``__init__``. Keyword
            arguments passed to the session factory.

        .. versionchanged:: 3.0
            The session class can be customized.

        .. versionchanged:: 3.0
            Renamed from ``create_session``, this method is internal.
        class_	query_clsdbNr    )rl   r   r   r&   sessionmaker)rM   r   r    r    r!   r     s   z SQLAlchemy._make_session_factoryexcBaseException | Nonec                 C  s   | j   dS )zuRemove the current session at the end of the request.

        :meta private:

        .. versionadded:: 3.0
        N)r?   remove)rM   r   r    r    r!   rh     s   zSQLAlchemy._teardown_sessionr=   
str | Noner   c                 C  sN   || j v r
| j | S |dur| dj}nd}tj|d|id}|| j |< |S )a$  Get or create a :class:`sqlalchemy.schema.MetaData` for the given bind key.

        This method is used for internal setup. Its signature may change at any time.

        :meta private:

        :param bind_key: The name of the metadata being created.

        .. versionadded:: 3.0
        Nr=   )naming_conventionrE   )r@   rv   r   rq   MetaData)rM   r=   r   r   r    r    r!   rv     s   


zSQLAlchemy._make_metadatatype[_Table]c                   s   G  fdddt }|S )aL  Create a SQLAlchemy :class:`sqlalchemy.schema.Table` class that chooses a
        metadata automatically based on the ``bind_key``. The result is available as
        :attr:`Table`.

        This method is used for internal setup. Its signature may change at any time.

        :meta private:

        .. versionadded:: 3.0
        c                      s&   e Zd Zddd fd
dZ  ZS )z+SQLAlchemy._make_table_class.<locals>.TableN)r=   argst.Anyr=   r   kwargsr#   rG   c                  sr   |rt |dkrt|d tjrt j| g|R i |S |}t j| g|d |g|dd  R i |S )Nr:   r   r   )rA   rp   rq   r   super__new__rv   )clsr=   r   r   r   )	__class__rM   r    r!   r     s    
.z3SQLAlchemy._make_table_class.<locals>.Table.__new__)r   r   r=   r   r   r   r#   rG   )r   r   r   r   __classcell__r    rM   )r   r!   rG     s    rG   r   )rM   rG   r    r   r!   rF     s   zSQLAlchemy._make_table_classt.Type[_FSAModel]c                   s  t |}t|dkrtd|jt|dkrFt|j |  d< ttt	g}|r-|
t tdg ||jR dt|d i fdd}nt|tjsa| d	}|rUtnt}tj||d
|d}n|}d	| jvrud	|jjd< |j| jd	< n| jd	 |_| j|_t |_| |_|S )a  Create a SQLAlchemy declarative model class. The result is available as
        :attr:`Model`.

        To customize, subclass :class:`.Model` and pass it as ``model_class`` to
        :class:`SQLAlchemy`. To customize at the metaclass level, pass an already
        created declarative model class as ``model_class``.

        This method is used for internal setup. Its signature may change at any time.

        :meta private:

        :param model_class: A model base class, or an already created declarative model
        class.

        :param disable_autonaming: Turns off automatic tablename generation in models.

        .. versionchanged:: 3.1.0
            Added support for passing SQLAlchemy 2.x base class as model class.
            Added optional ``disable_autonaming`` parameter.

        .. versionchanged:: 3.0
            Renamed with a leading underscore, this method is internal.

        .. versionchanged:: 2.3
            ``model`` can be an already created declarative model class.
        r   z>Only one declarative base can be passed to SQLAlchemy. Got: {}__fsa__FlaskSQLAlchemyBase	metaclassr   c                   s
   |   S N)rn   )nsbodyr    r!   <lambda>(  s   
 z3SQLAlchemy._make_declarative_base.<locals>.<lambda>Nr   )r   r   namer   r=   )r-   rA   
ValueErrorformatr,   dict__dict__r
   r   r   r   types	new_classrS   rp   r&   DeclarativeMetarv   r   r   declarative_baser@   r   rE   r   r0   r	   queryr   )rM   r"   r3   declarative_basesmixin_classesmodelr   r   r    r   r!   rH     sB    





z!SQLAlchemy._make_declarative_basec                 C  s,  t j|d }|jdv rj|jdu s|jdv r-t jj|d< d|vr%i |d< d|d d< dS |jd	d}|r>|jd
d }n|j}t	j
|sht	j|jdd t	j
|j|}|r^d| }|j|d|d< dS dS |jdrd|vs||d t jju r|dd d|jvr|ddi|d< dS dS dS )a  Apply driver-specific configuration to an engine.

        SQLite in-memory databases use ``StaticPool`` and disable ``check_same_thread``.
        File paths are relative to the app's :attr:`~flask.Flask.instance_path`,
        which is created if it doesn't exist.

        MySQL sets ``charset="utf8mb4"``, and ``pool_timeout`` defaults to 2 hours.

        This method is used for internal setup. Its signature may change at any time.

        :meta private:

        :param options: Arguments passed to the engine.
        :param app: The application that the engine configuration belongs to.

        .. versionchanged:: 3.0
            SQLite paths are relative to ``app.instance_path``. It does not use
            ``NullPool`` if ``pool_size`` is 0. Driver-level URIs are supported.

        .. versionchanged:: 3.0
            MySQL sets ``charset="utf8mb4". It does not set ``pool_size`` to 10. It
            does not set ``pool_recycle`` if not using a queue pool.

        .. versionchanged:: 3.0
            Renamed from ``apply_driver_hacks``, this method is internal. It does not
            return anything.

        .. versionchanged:: 2.5
            Returns ``(sa_url, options)``.
        rU   >   sqlite+pysqlitesqliteN>   :memory:ry   	poolclassconnect_argsFcheck_same_threaduri   T)exist_okzfile:)databasemysql
pool_classpool_recyclei   charsetutf8mb4)rq   rT   make_url
drivernamer   pool
StaticPoolr   getospathisabsmakedirsinstance_pathjoinset
startswith	QueuePoolrl   update_query_dict)rM   r   r4   rU   is_uridb_strr    r    r!   rw   @  s4   


z!SQLAlchemy._apply_driver_defaultssa.engine.Enginec                 C  s   t j|ddS )a  Create the :class:`sqlalchemy.engine.Engine` for the given bind key and app.

        To customize, use :data:`.SQLALCHEMY_ENGINE_OPTIONS` or
        :data:`.SQLALCHEMY_BINDS` config. Pass ``engine_options`` to :class:`SQLAlchemy`
        to set defaults for all engines.

        This method is used for internal setup. Its signature may change at any time.

        :meta private:

        :param bind_key: The name of the engine being created.
        :param options: Arguments passed to the engine.
        :param app: The application that the engine configuration belongs to.

        .. versionchanged:: 3.0
            Renamed from ``create_engine``, this method is internal.
        ry   )prefix)rq   engine_from_config)rM   r=   r   r4   r    r    r!   rx     s   zSQLAlchemy._make_enginec                 C  
   | j d S )zdThe default metadata used by :attr:`Model` and :attr:`Table` if no bind key
        is set.
        N)r@   r   r    r    r!   r     s   
zSQLAlchemy.metadata't.Mapping[str | None, sa.engine.Engine]c                 C  s$   t  }|| jvrtd| j| S )a  Map of bind keys to :class:`sqlalchemy.engine.Engine` instances for current
        application. The ``None`` key refers to the default engine, and is available as
        :attr:`engine`.

        To customize, set the :data:`.SQLALCHEMY_BINDS` config, and set defaults by
        passing the ``engine_options`` parameter to the extension.

        This requires that a Flask application context is active.

        .. versionadded:: 3.0
        zThe current Flask app is not registered with this 'SQLAlchemy' instance. Did you forget to call 'init_app', or did you create multiple 'SQLAlchemy' instances?)r   _get_current_objectrJ   rf   )rM   r4   r    r    r!   rV     s   

zSQLAlchemy.enginesc                 C  r   )a  The default :class:`~sqlalchemy.engine.Engine` for the current application,
        used by :attr:`session` if the :attr:`Model` or :attr:`Table` being queried does
        not set a bind key.

        To customize, set the :data:`.SQLALCHEMY_ENGINE_OPTIONS` config, and set
        defaults by passing the ``engine_options`` parameter to the extension.

        This requires that a Flask application context is active.
        N)rV   r   r    r    r!   rT     s   
zSQLAlchemy.enginer   r   c                 K  s,   t jdtdd d|v r|d}| j| S )a  Get the engine for the given bind key for the current application.
        This requires that a Flask application context is active.

        :param bind_key: The name of the engine.

        .. deprecated:: 3.0
            Will be removed in Flask-SQLAlchemy 3.2. Use ``engines[key]`` instead.

        .. versionchanged:: 3.0
            Renamed the ``bind`` parameter to ``bind_key``. Removed the ``app``
            parameter.
        z'get_engine' is deprecated and will be removed in Flask-SQLAlchemy 3.2. Use 'engine' or 'engines[key]' instead. If you're using Flask-Migrate or Alembic, you'll need to update your 'env.py' file.r:   r;   bind)rB   rC   rD   r   rV   )rM   r=   r   r    r    r!   
get_engine  s   

zSQLAlchemy.get_enginedescriptionentitytype[_O]identr   r   c                K  s.   | j j||fi |}|du rtd|d |S )a  Like :meth:`session.get() <sqlalchemy.orm.Session.get>` but aborts with a
        ``404 Not Found`` error instead of returning ``None``.

        :param entity: The model class to query.
        :param ident: The primary key to query.
        :param description: A custom message to show on the error page.
        :param kwargs: Extra arguments passed to ``session.get()``.

        .. versionchanged:: 3.1
            Pass extra keyword arguments to ``session.get()``.

        .. versionadded:: 3.0
        N  r   )r?   r   r   )rM   r   r   r   r   r   r    r    r!   
get_or_404  s   zSQLAlchemy.get_or_404	statementsa.sql.Select[t.Any]c                C  s(   | j | }|du rtd|d |S )a@  Like :meth:`Result.scalar() <sqlalchemy.engine.Result.scalar>`, but aborts
        with a ``404 Not Found`` error instead of returning ``None``.

        :param statement: The ``select`` statement to execute.
        :param description: A custom message to show on the error page.

        .. versionadded:: 3.0
        Nr   r   )r?   executescalarr   )rM   r   r   r   r    r    r!   first_or_404  s   zSQLAlchemy.first_or_404c             	   C  s<   z	| j | W S  tjtjfy   td|d Y dS w )as  Like :meth:`Result.scalar_one() <sqlalchemy.engine.Result.scalar_one>`,
        but aborts with a ``404 Not Found`` error instead of raising ``NoResultFound``
        or ``MultipleResultsFound``.

        :param statement: The ``select`` statement to execute.
        :param description: A custom message to show on the error page.

        .. versionadded:: 3.0
        r   r   N)r?   r   
scalar_onesa_excNoResultFoundMultipleResultsFoundr   )rM   r   r   r    r    r!   
one_or_404  s
   zSQLAlchemy.one_or_404)pageper_pagemax_per_page	error_outcountselectr   
int | Noner   r   r   r   r   c             	   C  s   t ||  |||||dS )a  Apply an offset and limit to a select statment based on the current page and
        number of items per page, returning a :class:`.Pagination` object.

        The statement should select a model class, like ``select(User)``. This applies
        ``unique()`` and ``scalars()`` modifiers to the result, so compound selects will
        not return the expected results.

        :param select: The ``select`` statement to paginate.
        :param page: The current page, used to calculate the offset. Defaults to the
            ``page`` query arg during a request, or 1 otherwise.
        :param per_page: The maximum number of items on a page, used to calculate the
            offset and limit. Defaults to the ``per_page`` query arg during a request,
            or 20 otherwise.
        :param max_per_page: The maximum allowed value for ``per_page``, to limit a
            user-provided value. Use ``None`` for no limit. Defaults to 100.
        :param error_out: Abort with a ``404 Not Found`` error if no items are returned
            and ``page`` is not 1, or if ``page`` or ``per_page`` is less than 1, or if
            either are not ints.
        :param count: Calculate the total number of values by issuing an extra count
            query. For very complex queries this may be inaccurate or slow, so it can be
            disabled and set manually if necessary.

        .. versionchanged:: 3.0
            The ``count`` query is more efficient.

        .. versionadded:: 3.0
        )r   r?   r   r   r   r   r   )r   r?   )rM   r   r   r   r   r   r   r    r    r!   paginate"  s   %zSQLAlchemy.paginatestr | None | list[str | None]op_namec              	   C  s   |dkr
t | j}n|du st|tr|g}n|}|D ]3}z| j| }W n ty@   d| d}|du r:d| }t|dw | j| }t|||d qdS )a  Call a method on each metadata.

        :meta private:

        :param bind_key: A bind key or list of keys. Defaults to all binds.
        :param op_name: The name of the method to call.

        .. versionchanged:: 3.0
            Renamed from ``_execute_for_all_tables``.
        __all__Nz
Bind key 'z&' is not in 'SQLALCHEMY_BINDS' config.z-'SQLALCHEMY_DATABASE_URI' config is not set. )r   )	listr@   rp   rO   rV   KeyErrorr   UnboundExecutionErrorgetattr)rM   r=   r   keysr~   rT   rW   r   r    r    r!   _call_for_bindsQ  s"   

zSQLAlchemy._call_for_bindsr   c                 C     |  |d dS )af  Create tables that do not exist in the database by calling
        ``metadata.create_all()`` for all or some bind keys. This does not
        update existing tables, use a migration library for that.

        This requires that a Flask application context is active.

        :param bind_key: A bind key or list of keys to create the tables for. Defaults
            to all binds.

        .. versionchanged:: 3.0
            Renamed the ``bind`` parameter to ``bind_key``. Removed the ``app``
            parameter.

        .. versionchanged:: 0.12
            Added the ``bind`` and ``app`` parameters.
        
create_allNr   rM   r=   r    r    r!   r   s  s   zSQLAlchemy.create_allc                 C  r   )a  Drop tables by calling ``metadata.drop_all()`` for all or some bind keys.

        This requires that a Flask application context is active.

        :param bind_key: A bind key or list of keys to drop the tables from. Defaults to
            all binds.

        .. versionchanged:: 3.0
            Renamed the ``bind`` parameter to ``bind_key``. Removed the ``app``
            parameter.

        .. versionchanged:: 0.12
            Added the ``bind`` and ``app`` parameters.
        drop_allNr   r  r    r    r!   r    s   zSQLAlchemy.drop_allc                 C  r   )a  Load table definitions from the database by calling ``metadata.reflect()``
        for all or some bind keys.

        This requires that a Flask application context is active.

        :param bind_key: A bind key or list of keys to reflect the tables from. Defaults
            to all binds.

        .. versionchanged:: 3.0
            Renamed the ``bind`` parameter to ``bind_key``. Removed the ``app``
            parameter.

        .. versionchanged:: 0.12
            Added the ``bind`` and ``app`` parameters.
        reflectNr   r  r    r    r!   r    s   zSQLAlchemy.reflectc                 C  sJ   | d| j d|v r#|d }t|tr|i f}|d  d| j dS dS )zApply the extension's :attr:`Query` class as the default for relationships
        and backrefs.

        :meta private:
        r0   backrefr   N)rl   r   rp   rO   )rM   r   r  r    r    r!   _set_rel_query  s   
zSQLAlchemy._set_rel_queryr   "sa_orm.RelationshipProperty[t.Any]c                 O  s   |  | tj|i |S )zA :func:`sqlalchemy.orm.relationship` that applies this extension's
        :attr:`Query` class for dynamic relationships and backrefs.

        .. versionchanged:: 3.0
            The :attr:`Query` class is set on ``backref``.
        r  r&   relationship)rM   r   r   r    r    r!   r    s   
	zSQLAlchemy.relationshipargumentc                 K  s   |  | tj|fi |S )zA :func:`sqlalchemy.orm.dynamic_loader` that applies this extension's
        :attr:`Query` class for relationships and backrefs.

        .. versionchanged:: 3.0
            The :attr:`Query` class is set on ``backref``.
        )r  r&   dynamic_loader)rM   r	  r   r    r    r!   r
    s   
	zSQLAlchemy.dynamic_loaderc                 O  s   |  | tj}||i |S )aM  A :func:`sqlalchemy.orm.relationship` that applies this extension's
        :attr:`Query` class for dynamic relationships and backrefs.

        SQLAlchemy 2.0 removes this name, use ``relationship`` instead.

        :meta private:

        .. versionchanged:: 3.0
            The :attr:`Query` class is set on ``backref``.
        r  )rM   r   r   fr    r    r!   	_relation  s   
zSQLAlchemy._relationr   c                 C  sZ   |dkr| j S |dkrtS |drt|ttfD ]}t||r(t||  S qt|)Nrelationevent_)r  sa_eventr   AttributeErrorrq   r&   hasattrr   )rM   r   modr    r    r!   __getattr__  s   

zSQLAlchemy.__getattr__r   )r4   r5   r   r6   r/   r7   r0   r8   r"   r   r1   r7   r2   r9   r3   r9   )r#   rO   )r4   r   r#   rY   )r   r   r#   r   )r   r   r#   r   )r   r   r#   rY   )r=   r   r#   r   )r#   r   )F)r"   r   r3   r9   r#   r   )r   r   r4   r   r#   rY   )r=   r   r   r   r4   r   r#   r   )r#   r   )r#   r   )r#   r   )r=   r   r   r   r#   r   )
r   r   r   r   r   r   r   r   r#   r   )r   r   r   r   r#   r   )r   r   r   r   r   r   r   r   r   r9   r   r9   r#   r   )r=   r   r   rO   r#   rY   )r   )r=   r   r#   rY   )r   r   r#   rY   )r   r   r   r   r#   r  )r	  r   r   r   r#   r  )r   rO   r#   r   )#r   r   r   __doc__r   r   rN   rX   rL   r>   r   rh   rv   rF   rH   rw   rx   propertyr   rV   rT   r   r   r   r   r   r   r   r  r  r  r  r
  r  r  r    r    r    r!   r.   =   sh    h
t

`


	

I
E!
/"



r.   )r"   r   r#   r$   )6
__future__r   r   r   typingtrB   weakrefr   rZ   rq   sqlalchemy.eventr  r  sqlalchemy.excr   r   sqlalchemy.ormormr&   flaskr   r   r   r   r   r	   r
   r   r   r   r   
paginationr   r   r   r   r?   r   r   tabler   TypeVarobjectr   UnionTyper   r'   r(   r   r   r-   r.   r    r    r    r!   <module>   sP    



