get_flask_sqlalchemy
FunctionSource
db: flask_sqlalchemy.SQLAlchemy = get_flask_sqlalchemy(
model_class: type[sa_orm.DeclarativeBase],
app: Flask | None = None,
engine_options: Mapping[str, Any] | None = None,
session_options: Mapping[str, Any] | None = None,
)
Get the Flask SQLAlchemy DB instance in the compatible mode.
This method will attempt to get the flask_sqlalchemy.SQLAlchemy
DB instance.
If the attempt fails (package is not installed), will fallback to use
flask_sqlalchemy_lite.SQLAlchemy
to imitate the interfaces of
flask_sqlalchemy.SQLAlchemy
.
Aliases
This function can be acquired by
import flask_sqlalchemy_compat as fsc
fsc.get_flask_sqlalchemy
fsc.auto.get_flask_sqlalchemy
Arguments
Requires
Argument | Type | Required | |
---|---|---|---|
model_class | type[sa.orm.DeclarativeBase] | The base model type applied to the whole database. If flask_sqlalchemy is available, this type will be used as model_class argument for creating the db-specific base model type. However, if the db instance fallback to the version provided by flask_sqlalchemy_lite , this type will be modified inplace to imitate the behavior of flask_sqlalchemy.SQLAlchemy().Model . | |
app | Flask | None | Call init_app on this Flask application. If not specified, will not call init_app . | |
engine_options | Mapping[str, Any] | None | Default arguments passed to sqlalchemy.create_engine for each configured engine. | |
session_options | Mapping[str, Any] | None | Arguments to configure sessionmaker with. |
Returns
Argument | Type | |
---|---|---|
db | flask_sqlalchemy.SQLAlchemy | The SQLAlchemy extension instance. It will be an instance of If the package is not available, will attempt to return a |