GithubHelp home page GithubHelp logo

django-sql-middleware's Introduction

Django SQL Middleware

A simple middleware aimed to capture all queries in a request and provide basic SQL profiling such as execution time, execution plan, and query traceback.

This package is only intended to run in development mode for non-sqlite database.

Currently, this package only tested in projects that uses psycopg2 (postgres) as default database engine.

How To Install

  1. Get the package from pypi: pip install django-sql-middleware

  2. In settings.py add:

    INSTALLED_APPS = [
        # your other apps
        "sqlmiddleware"
    ]
    
    MIDDLEWARE = [
        # your other middlewares
    ]
    
    if DEBUG:
        MIDDLEWARE.append("sqlmiddleware.middlewares.LogSQLMiddleware")
    
  3. Register urls in your_project/urls.py:

    from django.urls import include, path
    
    urlpatterns = [
        # other urls,
        path("__sql/", include("sqlmiddleware.urls")),
    ]
    
  4. Run collectstatic to serve included css and js assets: ./manage.py collectstatic

  5. Start the development server: ./manage.py runserver

  6. you should be able to access localhost:8000/__sql in your browser.

Screenshots

  1. List of captured requests Alt text
  2. List of database queries in selected request Alt text
  3. Query execution plan (EXPLAIN) Alt text
  4. Traceback showing your code only Alt text
  5. Full traceback Alt text

django-sql-middleware's People

Contributors

fatanugraha avatar

Stargazers

Isaac M avatar  avatar George Pitoy avatar

Watchers

James Cloos avatar  avatar

Forkers

kyleparisi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.