Created
November 28, 2012 17:13
-
-
Save hhatto/4162611 to your computer and use it in GitHub Desktop.
print raw sql for peewee
This file contains hidden or 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
| from peewee import * | |
| from models import News, database | |
| compiler = database.get_compiler() | |
| print(News.select().where(News.url == 'test').sql(compiler)) |
As per peewee 3.13 you can print SQL queries by first getting the cursor, then calling the mogrify() method for your query.
query = <YOUR PEEWEE QUERY>
cur = database.cursor()
print(cur.mogrify(*query.sql()))Where database is the Peewee Database object representing the connection to your database.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works: