A Django middleware package that helps inspect and trace SQL query executions in your terminal. - Used to easily debug a bunch of intertwined SQL queries in your terminal.
I started developing this tool in response to a challenge I encountered while working on a pre-existing Django application. Upon joining the project, I discovered the project had numerous bugs in its SQL queries, and its logic was convoluted, which made debugging quite a difficult task. I had to map out all the SQL relationships by hand to be able to move on with the application development irrespective of its intertwined SQL logic. During that period, I longed for a solution that would systematically trace and examine every executed SQL query within the application in an orderly manner for the purpose of debugging. That's why I embarked on building this tool.
- Trace SQL queries
- Inspect and check traces of repeated SQL queries
-
Python3
- Install Python3 for linux/mac/windows
-
Pip & Venv
- Setup pip and venv here
-
Pip install
dg-sqltrace
in your application directorypip install dg-sqltrace
-
Navigate to your
settings.py
file and at the top add this line:from dg-sqltrace import middleware
-
Next move down in your settings.py file to your
MIDDLEWARE
array and addmiddleware
to one of the array elements like this:... , ... , middleware
-
Re-run your server
-
Check your terminal and you should be good to go to inspect all executed SQL queries in your application.
-
Fork repository
-
Clone the forked repository in prefered directory
git clone <project-url>
-
Enter project directory
cd dg-sqltrace
-
Create a virtual enviroment
python3 -m venv env
-
Activate virtual environment
source env/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Run
python3 manage.py runserver
-
Visit localhost:8000/
This step automatically populate an SQLite database, query and inspect 1 query by default in your terminal.
if you will like to make a contribution or suggest anything to the project, will be happy to hear from you in issues or PRs section :)