Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to clear django.db.connection.queries?

I want to monitor query time in my system(built with Django models).

Finally I found django.db.connection.queries.

It shows all queries and time taking for it.

Using this, I want to print the list of which I have done queries at regular interval and then I want to clear the list I printed after printing.

It seems to have methods for a list object(pop, remove and so on).

But Even though I call pop(), It doesn't have any effect, still showing the same length.

How can I clear the list..?

Or Is there any other methods for my intention?

p.s I also found Django-debug-toolbar but it seems only for view part.

like image 734
SangminKim Avatar asked Oct 21 '15 17:10

SangminKim


People also ask

What are connection queries in Django?

It's a list of dictionaries in order of query execution. Each dictionary has the following: ``sql`` -- The raw SQL statement ``time`` -- How long the statement took to execute, in seconds. connection. queries includes all SQL statements – INSERTs, UPDATES, SELECTs, etc.

How can you see the raw SQL queries that Django is running?

Django gives you two ways of performing raw SQL queries: you can use Manager. raw() to perform raw queries and return model instances, or you can avoid the model layer entirely and execute custom SQL directly. Explore the ORM before using raw SQL!


Video Answer


1 Answers

You can call reset_queries() from the django.db module.

from django.db import reset_queries
reset_queries()
like image 83
Daniel Roseman Avatar answered Nov 08 '22 23:11

Daniel Roseman