mongkok / fastapi-debug-toolbar

A debug toolbar for FastAPI.
https://fastapi-debug-toolbar.domake.io
BSD 3-Clause "New" or "Revised" License
138 stars 14 forks source link

support for SqlModel #38

Closed kemalbastak closed 8 months ago

kemalbastak commented 10 months ago

Is it possible to add SqlModel panel support for query monitoring

mongkok commented 8 months ago

Hey @kemalbastak , you can create a custom panel based on SQLAlchemyPanel:

from debug_toolbar.panels.sqlalchemy import SQLAlchemyPanel
from fastapi import Request
from sqlmodel import create_engine

engine = create_engine("sqlite://")

class SQLModelPanel(SQLAlchemyPanel):
    async def add_engines(self, request: Request):
        self.engines.add(engine)

...and add this panel toDebugToolbarMiddleware:

app.add_middleware(
    DebugToolbarMiddleware,
    panels=["path.to.SQLModelPanel"],
)

I close the issue, if you have any questions please let me know.