Sun 11 Nov 2007
Django Tip: External Database Backends
Posted at 20:26 +1100
I was going to write a longer Django entry today about WSGI, but I've been spending time working on Django code instead, so a here's something shorter and possibly less useful that deserves some attention from Django users.
Every now and again, somebody has a need to change the behaviour in Django's existing database backends. Or they want to develop a new backed for, say, Firebird or Microsoft's SQL-Server or something. A couple of months ago (in revision 6316), George Vilches contributed a patch that gave Django the ability to import external database backends.
This means you can set the DATABASE_ENGINE setting to any importable Python module that acts like a Django database backend. You need to have the same main files as in the Django backed (base.py, creation.py, etc), but you can also add extra files, reuse some of the existing code, or pretty much do whatever you like.
It's even documented, which means people are encouraged to use it.
The net result of all this is that anybody wanting to add an extra backend to Django can happily develop it and provide support as a third-party module. This cuts down on the inconvenience for those developers and also makes the Django maintainers' life easier, because existing support and a history of maintenance is required for anything we're likely to include in core.
Most people aren't going to need this functionality. Every now and again, though, somebody, somewhere will want to change the default character column type for Oracle to something different from what Django uses. Or will want to add support for their favourite underused database server. This is now possible and doesn't require making changes to the core code. Hooks like this, that are unobtrusive and don't have any real performance impact (we check it once at import time) are really the way to go for extensible frameworks (where extensions are justified; not everything has to be customisable).
Topics: software/django/tips