Dear Carl,
On Tuesday, February 2, 2016 at 7:51:20 PM UTC, Carl Meyer wrote:
>
>
> There's nothing wrong with connections[options.get('database')] if you
> want to get a specific database connection object; that's public API and
> you can use it. In the case of the built-in commands, that's useful
>
OK, perhaps I misunderstood what you said in an earlier comment - I see you
were talking against using the *internals* of the connection rather the
connection itself.
because they need to do low-level things with the connection; I don't
> think it helps you for regular ORM use. It doesn't allow changing the
> default connection for ORM usage. Where the built-in management commands
> do use the higher-level ORM, they use the public `using` APIs.
>
That's fine for simple use, but it's not good have lots of using() calls
for models when it's not a "real" multi-DB scenario,
> If you want to write a management command that has a --database option
> like the built-in ones and makes heavy use of the ORM, you can a)
> explicitly provide `using` where needed , b) use
> django-dynamic-db-router, or c) hold your nose and monkeypatch
> DEFAULT_DB_ALIAS, since it's just a one-shot management command and you
> don't need to be as concerned about cleaning up after yourself.
>
> Personally I would go for (a) or (b), depending on just how much I was
> using the ORM in the management command. I'm not convinced that a fourth
> (or third supported public) option is necessary here. If it's just a few
> queries, you use `using`, if it's more than that and you want a broader
> policy applied, you use a database router.
>
OK, thanks for the suggestion - you've been very helpful, as always. I'll
mull things over and see what's the best for the specifics of the specific
project.
Regards,
Vinay Sajip
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/832b093d-1d5a-4d24-9125-9eeb9297bbd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.