SQLAlchemy model N+1 debugger
Project description
QueryCounter
SQLAlchemy model N+1 debugger.
About
This module will help identify N+1 DB calls made through SQLAlchemy. It takes advantage of the SQLAlchemy event listener for do_orm_execute
.
QueryCounter will provide insights into which model DB calls are made multiple times, with optional tracebacks and heuristics to determine where these calls originate.
By default, QueryCounter will log results with an optional config to raise an Exception.
Installation
TODO
Configuration
TODO
Usage
Usage: Create QueryCounter with optional config and initialize
when you would like to start tracking requests:
query_counter = QueryCounter(session=session, config=query_counter_config)
query_counter.initialize()
Run analyze
to dig into queries that ran since initialization:
query_counter.analyze()
This also works as a context manager:
with QueryCounter(
session=session, config=QueryAnalysisConfig(alert_threshold=0)
) as counter:
session.query(User).first()
counter.analyze()
Setting a breakpoint in the analyze function will allow you to inspect all of the queries and their stack traces.
TODO
- Linting
- Tests
- Pipeline
License
QueryCounter is distributed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for query_counter-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98bd218972a653d61452e6e6478d1b85be60be69d235aec8de66d7a7ae03c657 |
|
MD5 | 312829058c2efae7e6f3151a31562b00 |
|
BLAKE2b-256 | 8b956abee4758f529bcd8865832b4281695c0d0a3a405cd27e94a0f77851fc95 |