Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What about django db routing? #9

Closed
unaxfromsibiria opened this issue Dec 18, 2014 · 4 comments
Closed

What about django db routing? #9

unaxfromsibiria opened this issue Dec 18, 2014 · 4 comments
Assignees

Comments

@unaxfromsibiria
Copy link

if has more one db connection, have to do like this:

from architect.orms.django.mixins import PartitionableMixin
from django.db import connections
from django.db.utils import ConnectionDoesNotExist


class RoutingPartitionableMixin(PartitionableMixin):

    def get_cursor(self):
        try:
            cursor = connections[self.PartitionableMeta.db_name].cursor()
        except AttributeError:
            cursor = super(RoutingPartitionableMixin, self).get_cursor()
        except ConnectionDoesNotExist as err:
            # need self.PartitionableMeta.db_name
            raise err

        return cursor

I would like something native implementation for this. Please, think about.

@maxtepkeev maxtepkeev self-assigned this Dec 31, 2014
@maxtepkeev
Copy link
Owner

Great idea. I'll put it in my TODO list. Thanks.

@unaxfromsibiria
Copy link
Author

after version 0.4.0 forced to replace cursor as:

try:
    SomeModelClass.architect.operation.cursor = connections['some_not_default_connection'].cursor()
except ConnectionDoesNotExist:
    # use default
    pass

I think good idea a give native opportunity for replacing feature classes, like this:

from architect.orms.django.features import PartitionFeature

class CustomPartitionFeature(PartitionFeature):
    def __init__(self, *args, **kwargs):
        super(PartitionFeature, self).__init__(*args, **kwargs)
        self.cursor = connections['some_not_default_connection'].cursor()

SomeModelClass.architect.set_feature_class('partition', CustomPartitionFeature)

This will be usefull for resolving other users needs, not only replacing cursor :)

maxtepkeev added a commit that referenced this issue May 7, 2015
@maxtepkeev
Copy link
Owner

Support for multiple database connections in Django and custom features are available in v0.5.0

@unaxfromsibiria
Copy link
Author

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants