On Tue, 2014-07-01 at 17:49 +0300, Shai Berger wrote:

> I think we can reach very similar results, with a much nicer API, by letting 
> the backends just override the function classes.

The backend specific class must be instantiated at query compile time.
How is the data contained in the original class copied to the overriding
class? One possibility is to copy the original instance's __dict__ to
the overriding class.

Also, "if the attribute has an attribute named like the function class"
isn't good, clashes between plain class names is expected. The overrides
could be a dictionary of original class -> overriding class. So,
something like this:

class BackendLower(models.Lower):
    def __init__(self, from_node):
        # The hacky way
        self.__dict__ = from_node.__dict__

    def as_sql(self, qn, connection):
        ....
overrides = {models.Lower: BackendLower}

And compiler.compile() would look something like this:

if node.__class__ in connection.overrides:
    return connection.overrides[node.__class__](node).as_sql(...)
else:
    return node.as_sql(...)

Using the above way there is no need to alter classes dynamically. On
the other hand, copying data from the original class to the implementing
class can be risky (circular dependencies for example), and it is a bit
more expensive. Still, inheritance will not work like with as_vendor(),
but I am not sure how common subclasses without custom as_sql() are.

 - Anssi

-- 
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/1404228748.9408.189.camel%40TTY32.
For more options, visit https://groups.google.com/d/optout.

Reply via email to