Francis Niu
Francis Niu

Reputation: 632

Find SQLAlchemy query according to generated sql

We use Flask+SQLAlchemy in our web app. We found some slow sql queries in DB monitor. Is there any good way to find/locate the original SQLAlchemy queries according to generated sql? i.e. code mapping between ORM code and SQL code.

e.g. Add any unique token in generated sql comment, so we can find original ORM code by the token.

Upvotes: 0

Views: 79

Answers (1)

r-m-n
r-m-n

Reputation: 15090

You can add sql comment with suffix_with method

query = Table.query
query = query.suffix_with('-- %s' % query_token)

Upvotes: 1

Related Questions