On Fri, Jun 27, 2014 at 7:04 AM, Anssi Kääriäinen <anssi.kaariai...@thl.fi>
wrote:

> This is possible to do by supplying a custom SQLCompiler class for the
> backend, and overriding its .compile() method.
>
> Personally I don't see usage of as_vendor() as that problematic. Supplying
> as_vendor in first DatabaseWrapper.__init__() should work. Yes, we are
> dynamically altering the node's class. But we are just using the __dict__
> of the node to store backend specific implementation instead of using a
> dictionary somewhere in the backend for the implementation. Using the
> __dict__ has the advantage that inheritance works automatically.
>
> As multiple core developers have said they don't like as_vendor() for 3rd
> party backend support it might be better to offer official hook for
> altering the generated SQL. That is, change the SQLCompiler.compile()
> method from
>
>     def compile(self, node):
>         vendor_impl = getattr(
>             node, 'as_' + self.connection.vendor, None)
>         if vendor_impl:
>             return vendor_impl(self, self.connection)
>         else:
>             return node.as_sql(self, self.connection)
>
> to
>
>     def compile(self, node):
>         ret = self.connection.compile(node)
>

If this is going to be moved off SQLCompiler, I think DatabaseOperations is
a better place for it because we already have
DatabaseOperatoins.combine_expression. The compile method will need access
to the compiler to match the signature of as_sql (and it is necessary in
some cases to inspect the query).


> The main reason for offering a hook is that overriding SQLCompiler is a
> bit problematic. There exists various subclasses of SQLCompiler, and the
> backend needs to support those, too.
>

All of the subclasses are going to inherit SQLCompiler.compile and do the
same exact logic. I don't understand what problem is caused by overriding
compile that is solved by a function call to compile on some other class.

Regards,
Michael Manfre

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAGdCwBv6%2Bo02ECs9NN10TgHwHAYWv%3D_8U06zmK7QQJXEQdKfGg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to