Reputation: 267
we are using SQL alchemy as the ORM for our project. i am trying to get & analyze the raw SQL that gets generated (via SQL alchemy) for performance purposes. can somebody please let me know if there is a way to gather the raw SQL before it gets committed to the database.
Upvotes: 4
Views: 2502
Reputation: 1535
You can set echo=True
when instantiating your engine:
>>> from sqlalchemy import create_engine
>>> engine = create_engine("mysql://localhost/mydb", echo=True)
This causes all SQL statements to be logged via normal Python logging. You can easily capture these messages to a file by using the appropriate log configuration, as shown in these Python logging examples.
Reference: SQLAlchemy Engine Configuration
Upvotes: 3