Debian Codegraph @

src/flask_sqlalchemy/cli.py

raw
1 from __future__ import annotations
2
3 import typing as t
4
5 from flask import current_app
6
7
8 def add_models_to_shell() -> dict[str, t.Any]:
9 """Registered with :meth:`~flask.Flask.shell_context_processor` if
10 ``add_models_to_shell`` is enabled. Adds the ``db`` instance and all model classes
11 to ``flask shell``.
12 """
13 db = current_app.extensions["sqlalchemy"]
14 out = {m.class_.__name__: m.class_ for m in db.Model._sa_registry.mappers}
15 out["db"] = db
16 return out