mongkok / fastapi-debug-toolbar

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

support for SqlModel #38

Closed kemalbastak closed 9 months ago

kemalbastak commented 11 months ago

Is it possible to add SqlModel panel support for query monitoring

mongkok commented 9 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.