In my Django project I have a dependency for a third party application that produces SQLite cache files in various directories with a known schema.
I'd like to use Django models to access those databases, but obviously I cannot use a static DATABASES
setup.
How can I dynamically open a SQLite database on an arbitrary path?
EDIT
As Byron Ruth pointed out, the solution is to use the django.db.connections
in conjunction with the using
function in the QuerySet.
The
django.db.connections
is a simple wrapper aroundDATABASES
defined in your settings. The wrapper class is here: django.db.utils#L137-L227Assuming the only engine used is SQLite and the location of the (only) database file is what varies, provide a callable to the
NAME
:You can register database in DATABASES settings.
You can but you shouldn't.