Closed ferndot closed 5 years ago
Why would this be useful may I ask?
It is useful for when one needs to connect to the database outside the Django ORM. For instance, my team sometimes writes custom utilities and management commands to perform operations with large quantities of data. One can extract parameters from the database dictionary in Django settings, but it would be much more elegant to easily retrieve a standard connection URL.
This is a bit of an edge case, though.
Can you retrieve the original database url from os.environ
? Or am I missing something?
@jacobian yes, but that means that one is configuring the database separately from Django and changes would need to be reflected in both places, which can be easy to miss. The benefit of the url function would be that one could simply do parse_db_url(settings.DATABASES["default"])
and then simply consume the configuration already used by the rest of the project.
that means that one is configuring the database separately from Django
Maybe I'm being dense here -- but isn't that exactly the point of this library? The whole idea here is: you've got some external system that's setting up a database, and passing the info to you in env[DATABASE_URL].
What am I missing?
What you are saying makes sense. This library makes the assumption that the database connection url is located at DATABASE_URL
. In which case it would be trivial to simply use that same env variable elsewhere and this feature is pretty redundant. We can close this.
It would be nice if this package could also parse a Django database dictionary into a valid connection URI.