I was considering creating a separate SQLite database for certain apps on a Django project.
However, I did not want to use direct SQLite access if possible.
Django-style ORM access to these database would be ideal.
Is this possible?
Thank you.
Yes - the low-level API for this is in place, it's just missing a convenient high-level API at the moment. These quotes are from James Bennett (Django's release manager) on programming reddit:
It's been there -- in an extremely low-level API for those who look at the codebase -- for months now (every
QuerySet
is backed by aQuery
, which in turn accepts a DB connection as an argument). There isn't any high-level documented API for it, but I know people who are already doing and have been doing stuff like multiple-DB/sharding scenarios....it's not necessarily something that needs a big write-up; the
__init__()
method ofQuerySet
accepts a keyword argumentquery
, which should be an instance ofdjango.db.models.sql.Query
. The__init__()
method ofQuery
, in turn, accepts a keyword argumentconnection
, which should be an instance of (a backend-specific subclass for your DB of)django.db.backends.BaseDatabaseWrapper
.From there, it's pretty easy; you could, for example, override
get_query_set()
on a manager to always return aQuerySet
using the connection you want, or set up things like sharding logic to figure out which DB to use based on incoming query parameters, etc., etc.
Already supported http://docs.djangoproject.com/en/dev/topics/db/multi-db/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With