Skip to content

Django Debug Query (ddquery) beautiful colored SQL statements for logging

License

Notifications You must be signed in to change notification settings

elinaldosoft/ddquery

Repository files navigation

Django Debug Query (ddquery)

Ddquery is a library built in python that add color in your SQL statements and show in your command shell (pretty), for relational databases that uses ORM of the Django

Requirements

  • Python ≥ 3.3
  • Django ≥ 1.8

How to use

pip install ddquery

Add it to your Django Logging settings

You can add it to your Django LOGGING settings:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'sqlhandler': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'sqlformatter'
        }
    },
    'formatters': {
        'sqlformatter': {
            '()': 'ddquery.SqlFormatter',
            'format': '%(levelname)s %(message)s',
        },
    },
    'loggers': {
        'django.db.backends': {
            'handlers': ['sqlhandler'],
            'level': 'DEBUG',
        },
    }
}

Configuration options

'formatters': {
    'sqlformatter': {
        '()': 'sqlformatter.SqlFormatter',
        'format': '%(levelname)s %(message)s',
        'reindent': False,
        'highlight': False,
        'keyword_case': 'lower'
    },
},

How it looks like?

python manage.py runserver

Shell

python manage.py shell

Shell 02

python manage.py migration

Migration

References

About

Django Debug Query (ddquery) beautiful colored SQL statements for logging

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages