You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-22Lines changed: 40 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Class that supports the function of decorator, iterator and context manager for measuring the time and number of database queries
1
+
# Class to simplify the search for slow and suboptimal sql queries to the database in django projects.
2
2
3
3
<divalign="center">
4
4
@@ -11,55 +11,73 @@
11
11
12
12
</div>
13
13
14
-
> Class that supports the function of decorator, iterator and context manager for measuring the time and number of database queries
14
+
## About class
15
+
- Class allows you to track any sql queries that are executed inside the body of a loop, a decorated function, or a context manager, the body can be executed a specified number of times to get the average query execution time.
16
+
17
+
- The class allows you to display formatted output data containing brief information about the current iteration of the measurement, display sql queries and explain information on them, as well as summary information containing data on all measurements.
18
+
19
+
> **Do not use the class inside the business logic of your application, this will greatly slow down the execution of the queries, the class is intended only for the test environment.**
15
20
16
21
## Install
17
22
1. Install package
18
23
```bash
19
24
pip install capture-db-queries
20
25
```
21
26
22
-
## About decorator
23
-
`CaptureQueries` class as decorator can call the body of the decorated functionor class as iterator can run code inside for loop the specified number of timesfor multiple measurements, it can validate the total number of queries.
24
-
The functionality of the classic context manager is also available.
27
+
## About class parameters
28
+
>*All parameters are purely optional.*
25
29
26
30
- Optional parameters:
27
-
- `assert_q_count`: The expected number of database requests is otherwise "AssertionError: N not less than or equal to N queries"
28
-
- `number_runs`: The number of runs of the testfunction/testfor loop
29
-
- `verbose`: Displaying the final results of the test measurements
30
-
- `advanced_verb`: Displaying the result of each test measurement
31
-
- `auto_call_func`: Autorun of the decorated function(without arguments)
32
-
- `queries`: Displaying raw SQL queries to the database
33
-
- `explain`: Displaying additional information about each request (has no effect on the orig. requests)
34
-
- `explain_opts`: For more information about the parameters for explain, see the documentation for your DBMS
31
+
- `assert_q_count`: The expected number of database queries during all `number_runs`, otherwise an exception will be raised: **"AssertionError: `N` not less than or equal to `N` queries"**.
32
+
- `number_runs`: The number of runs of the decoratedfunctionortestfor loop.
33
+
- `verbose`: Displaying the final results of test measurements within all `number_runs`.
34
+
- `advanced_verb`: Displaying the result of each test measurement.
35
+
- `auto_call_func`: Autorun of the decorated function. *(without passing arguments to the function, since the launch takes place inside the class)*.
36
+
- `queries`: Displaying colored and formatted SQL queries to the database.
37
+
- `explain`: Displaying explain information about each query. (has no effect on the original query).
38
+
- `explain_opts`: Parameters for explain. *(for more information about the parameters for explain, see the documentation for your DBMS).*
35
39
- `connection`: Connecting to your database, by default: django.db.connection
36
40
37
41
## Usage examples
38
42
39
43
```python
40
-
from capture_db_queries.decorators import CaptureQueries
displays detailed information about the measurements,
219
-
validates the number of requests.
217
+
#### Class to simplify the search for slow and suboptimal sql queries\
218
+
to the database in django projects.
220
219
221
220
---
222
221
223
-
UseCases::
222
+
#### About class
223
+
- Class allows you to track any sql queries that are executed inside the body of a loop,
224
+
a decorated function, or a context manager,
225
+
the body can be executed a specified number of times to get the average query execution time.
226
+
227
+
- The class allows you to display formatted output data
228
+
containing brief information about the current iteration of the measurement,
229
+
display sql queries and explain information on them,
230
+
as well as summary information containing data on all measurements.
231
+
232
+
`Do not use the class inside the business logic of your application,
233
+
this will greatly slow down the execution of the queries,
234
+
the class is intended only for the test environment.`
235
+
236
+
---
237
+
238
+
#### - Optional parameters:
239
+
- `assert_q_count`: The expected number of database queries during all `number_runs`, otherwise an exception will be raised: "AssertionError: `N` not less than or equal to `N` queries".
240
+
- `number_runs`: The number of runs of the decorated function or test for loop.
241
+
- `verbose`: Displaying the final results of test measurements within all `number_runs`.
242
+
- `advanced_verb`: Displaying the result of each test measurement.
243
+
- `auto_call_func`: Autorun of the decorated function. (without passing arguments to the function, since the launch takes place inside the class).
244
+
- `queries`: Displaying colored and formatted SQL queries to the database.
245
+
- `explain`: Displaying explain information about each query. (has no effect on the original query).
246
+
- `explain_opts`: Parameters for explain. (for more information about the parameters for explain, see the documentation for your DBMS).
247
+
- `connection`: Connecting to your database, by default: django.db.connection
248
+
249
+
---
250
+
251
+
#### Usage examples::
224
252
225
253
for ctx in CaptureQueries(number_runs=2, advanced_verb=True):
0 commit comments