Releases: Friskes/capture-db-queries
Releases · Friskes/capture-db-queries
Downgrade dependencies
Add warning for run pytest xdist with capture queries
v1.2.7 fix readme
Added support capture queries in async context
@pytest.mark.asyncio()
@pytest.mark.django_db(transaction=True)
async def test_1(self):
async with CaptureQueries(number_runs=1, advanced_verb=True) as ctx:
response = await self.client.get(url)
>>> Queries count: 10 | Execution time: 0.04s | Vendor: sqlite
Redesigned architecture, added the ability to add your own output handlers
Customization of the display
To customize the display of SQL queries, you can import a list with handlers and remove handlers from it or expand it with your own handlers.
from capture_db_queries import settings, IHandler
# NOTE: The handler must comply with the specified interface.
class SomeHandler(IHandler):
def handle(self, queries_log):
for query in queries_log:
query.sql = "Hello World!"
return queries_log
settings.PRINTER_HANDLERS.remove("capture_db_queries.handlers.ColorizeSqlHandler")
settings.PRINTER_HANDLERS.append("path.to.your.handler.SomeHandler")
Update documentation
v1.2.4 update documentation
Improved logging, coloring of sql queries, and more
Added a logging system
Fixed exception with 0 requests in the body being checked
Added sql coloring
Redesigned logic and added tests
Swap monotonic to perf_counter timer
v1.2.2 swap monotonic to perf_counter timer
improved display format
v1.2.1 improved display format
Added new parameters, explain and explain_opts to CaptureQueries
# Example of output when using queries and explain:
for _ in CaptureQueries(advanced_verb=True, queries=True, explain=True):
list(Reporter.objects.filter(pk=1))
list(Article.objects.filter(pk=1))
>>> Test №1 | Queries count: 2 | Execution time: 0.22s
>>>
>>>
>>> №[1] time=[0.109] explain=['2 0 0 SEARCH TABLE tests_reporter USING INTEGER PRIMARY KEY (rowid=?)']
>>> SELECT "tests_reporter"."id",
>>> "tests_reporter"."full_name"
>>> FROM "tests_reporter"
>>> WHERE "tests_reporter"."id" = %s
>>>
>>>
>>> №[2] time=[0.109] explain=['2 0 0 SEARCH TABLE tests_article USING INTEGER PRIMARY KEY (rowid=?)']
>>> SELECT "tests_article"."id",
>>> "tests_article"."pub_date",
>>> "tests_article"."headline",
>>> "tests_article"."content",
>>> "tests_article"."reporter_id"
>>> FROM "tests_article"
>>> WHERE "tests_article"."id" = %s
>>>
>>>
>>> Tests count: 1 | Total queries count: 2 | Total execution time: 0.22s | Median time one test is: 0.109s | Vendor: sqlite
Added warning for use number runs > 1 if use class as context manager
v1.1.1 hotfix warning msg