Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Peewee to print generated queries

Is there a way or setting in Peewee where I can get it to print out all the queries being executed in order to debug and understand potential performance issues.

like image 745
valanto Avatar asked Aug 02 '17 09:08

valanto


People also ask

How do I use peewee in Python?

When starting a project with peewee, it's typically best to begin with your data model, by defining one or more Model classes: from peewee import * db = SqliteDatabase('people. db') class Person(Model): name = CharField() birthday = DateField() class Meta: database = db # This model uses the "people.

What is an n 1 query?

What is the N+1 query problem? The N+1 query problem is one of the common performance antipatterns in ORMs. It happens when a query is executed on each result of the previous query, in other words, when an application gets data from the database and then loop through the result of that data.

How do I select a query in Visual Studio?

In Visual Studio Code, press Ctrl+Shift+P (or F1) to open the Command Palette. Select MS SQL:Connect and choose Enter. Select Create Connection Profile. Follow the prompts to specify the new profile's connection properties.

What is Query Builder in Python?

PyPika is a python SQL query builder that exposes the full richness of the SQL language using a syntax that reflects the resulting query. PyPika excels at all sorts of SQL queries but is especially useful for data analysis.


1 Answers

Yes, it is documented: http://docs.peewee-orm.com/en/latest/peewee/database.html#logging-queries

# Print all queries to stderr.
import logging
logger = logging.getLogger('peewee')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
like image 58
coleifer Avatar answered Sep 17 '22 22:09

coleifer