File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -708,6 +708,34 @@ def engine(self) -> sa.engine.Engine:
708
708
"""
709
709
return self .engines [None ]
710
710
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
+
711
739
def get_or_404 (
712
740
self ,
713
741
entity : type [_O ],
You can’t perform that action at this time.
0 commit comments