-
-
Save kanghyojun/095734c1125a08d2aa070dd421ad5f17 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).""" | |
def show_query(query): | |
from sqlalchemy.dialects.postgresql import dialect | |
qc = query.statement.compile(dialect=dialect()) | |
return str(query) % {n: repr(b.value) for n, b in qc.binds.items()} | |
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