You will notice that the SQLModel example is very similar to the SQLAlchemy example for fastapi-users. This is because SQLModel is built on top of SQLAlchemy and pydantic.
There are a few important differences you should take note of:
- Removing the
DeclarativeBase
SQLAlchemy base class. - Using
fastapi_users.db.SQLModelBaseUserDB
instead offastapi_users.db.SQLAlchemyBaseUserTable
. - Using
fastapi_users.db.SQLModelUserDatabaseAsync
instead offastapi_users.db.SQLAlchemyUserDatabase
. - Setting the
class_
parameter ofsessionmaker
toAsyncSession
. - Using
SQLModel.metadata.create_all
instead ofBase.metadata.create_all
.
- Using
fastapi_users.db.SQLModelUserDatabaseAsync
instead offastapi_users.db.SQLAlchemyUserDatabase
.