Last active
May 4, 2018 18:12
-
-
Save dahlia/445d8bc2e8f0c7fb045685cda5a498ac to your computer and use it in GitHub Desktop.
Print SQLAlchemy queries (including bind params).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Print SQLAlchemy queries (including bind params). | |
See also: http://docs.sqlalchemy.org/en/latest/faq/sqlexpressions.html#faq-sql-expression-string | |
""" | |
def show_query(query): | |
qc = query.statement.compile( | |
dialect=query.session.bind.dialect, | |
compile_kwargs={'literal_binds': True} | |
) | |
return str(query) | |
def print_query(query): | |
print(show_query(query)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment