Open kamilglod opened 2 months ago
Have you tried to store db instance in fastapi app state? following this way you can easily get wrapper instance in admin
@Vasiliy566 I don't follow. Could you share some example code?
@kamilglod I think the change should be really simple, we have to refactor this: https://github.com/aminalaee/sqladmin/blob/d99817aa25edf9039e381f42f5ea2a351457e012/sqladmin/application.py#L84C21-L89C85 I will take a look when I get a chance, or feel free to pick it up.
Checklist
Is your feature related to a problem? Please describe.
I want to setup sqladmin for project in which we're using google IAM auth for PostgreSQL and our function that creates SqlAlchemy engine is async:
and now it's quite tricky to get an instance of the engine when creating FastAPI app (and Admin instance).
Similar problem might have someone that share connection pool between app and admin and creates engine inside of the lifespan https://fastapi.tiangolo.com/advanced/events/ - which happens after FastAPI app is created.
Describe the solution you would like.
I would like to have an option to create app with an admin instance without passing engine or sessionmaker yet. and then have an option (like dedicated Admin method) to set proper sessionmaker or engine inside of the
lifespan
. Something like:Describe alternatives you considered
I tried to create whole Admin inside of the
lifespan
but it didn't work. It looks like it's already too late and we need to set it up when creating FastAPI app.Additional context
No response