Skip to main content

as_flask_sqlalchemy

FunctionSource

db: _SQLAlchemyDB = as_flask_sqlalchemy(db: _SQLAlchemyDB)
db: SQLAlchemyProxy[_SQLAlchemyLiteDB_co, _ModelLite_co] = as_flask_sqlalchemy(
db: _SQLAlchemyLiteDB_co,
model_class: Type[_ModelLite_co],
)

Make db works as flask_sqlalchemy.

Aliases

This function can be acquired by

import flask_sqlalchemy_compat as fsc


fsc.as_flask_sqlalchemy
fsc.flask_sa_api.as_flask_sqlalchemy

Arguments

Requires

ArgumentTypeRequired
Description
db_SQLAlchemyDB | _SQLAlchemyLiteDB_coThe db extension to be wrapped.
model_classType[_ModelLite_co]

The base model class used for mimicking the behavior of db.Model when db is not from flask_sqlalchemy. Note that this value will be modified inplace because some compatibility-related functionalities like auto table name and the query method need to be provided to make its usage aligned with flask_sqlalchemy.SQLAlchemy().Model.

This value should not be used if db is provided by flask_sqlalchemy.

Returns

ArgumentType
Description
dbflask_sqlalchemy.SQLAlchemy | SQLAlchemyProxy(db, model_class)

If db is already provided by flask_sqlalchemy, return as it is.

If db is provided by flask_sqlalchemy_lite, return a proxy wrapper of it. This wrapper has the same APIs of flask_sqlalchemy.SQLAlchemy() but the implementation is based on flask_sqlalchemy_lite.SQLAlchemy().