Friday, June 21, 2019

Re: Can we create a Rest Api in Django which can able to communicate with multiple databases(Relational, Non relational) dynamically. If yes please recommend me a way to do that

If it is one time selection like storing in a user level settings, you can store the database to use in user model 
i.e. you have to customize default Usermodel in django and add one extra field to store the db type of the current user. 

Then access the right db 
Author.objects.using(request.user.database).all() 
OR
Author.objects.using('mysql').all()
Author.objects.using('postgresql').all()
You might have to use the database routers also. It depends on your detailed requirements.


Official docs - 

On Fri, Jun 21, 2019 at 4:55 PM anilkumar sangu <sangu.anilkumar@gmail.com> wrote:
Hello,

I am working on Django

I have a scenario like 
I want to connect multiple databases. based on user selection.  if user selects MySql from front end my Api could able to connect MySql. if user select postgreSql my api could able to connect to postgreSql based on user selection dynamically. how to achieve this in Django Rest Api

Thanks in advance 

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/50a8fe84-0966-4b2c-bcf4-725f75a78609%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/CAMKMUjuH_j_OGDpLQfQQZ8EqChRTXXvutNb%3DK%2BJEv76QJeQmFw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment