File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11Version 3.1.0
22-------------
33
4- Unreleased
4+ Released 2023-09-10
55
66- Drop support for Python 3.7. :pr: `1251 `
77- Add support for the SQLAlchemy 2.x API via ``model_class `` parameter. :issue: `1140 `
Original file line number Diff line number Diff line change 22
33from .extension import SQLAlchemy
44
5- __version__ = "3.1.0.dev "
5+ __version__ = "3.1.0"
66
77__all__ = [
88 "SQLAlchemy" ,
Original file line number Diff line number Diff line change @@ -708,6 +708,34 @@ def engine(self) -> sa.engine.Engine:
708708 """
709709 return self .engines [None ]
710710
711+ def get_engine (
712+ self , bind_key : str | None = None , ** kwargs : t .Any
713+ ) -> sa .engine .Engine :
714+ """Get the engine for the given bind key for the current application.
715+ This requires that a Flask application context is active.
716+
717+ :param bind_key: The name of the engine.
718+
719+ .. deprecated:: 3.0
720+ Will be removed in Flask-SQLAlchemy 3.2. Use ``engines[key]`` instead.
721+
722+ .. versionchanged:: 3.0
723+ Renamed the ``bind`` parameter to ``bind_key``. Removed the ``app``
724+ parameter.
725+ """
726+ warnings .warn (
727+ "'get_engine' is deprecated and will be removed in Flask-SQLAlchemy"
728+ " 3.2. Use 'engine' or 'engines[key]' instead. If you're using"
729+ " Flask-Migrate or Alembic, you'll need to update your 'env.py' file." ,
730+ DeprecationWarning ,
731+ stacklevel = 2 ,
732+ )
733+
734+ if "bind" in kwargs :
735+ bind_key = kwargs .pop ("bind" )
736+
737+ return self .engines [bind_key ]
738+
711739 def get_or_404 (
712740 self ,
713741 entity : type [_O ],
You can’t perform that action at this time.
0 commit comments