How does web2py select a database to connect to based on the http request content? Is it feasible to connect to different databases depending on whether it is a read request or a write request? Can you provide example on how to do this?
On Fri, Jan 5, 2018 at 6:35 PM, Anthony <abasta...@gmail.com> wrote: > Do you have doubts about whether it would work? Seems fairly > straightforward. > > > On Friday, January 5, 2018 at 3:59:29 PM UTC-5, CDA wrote: >> >> >> Below is an excerpt about horizontal scaling from Chapter 13 in the book. >> Has any one successfully implemented this using web2py? >> >> It is also possible to connect to different databases depending on the >> requested action or controller. In a master-slave database configuration, >> *some* *action performs only a read* and *some performs both read/write*. >> The former can safely connect to a slave db server, while the latter should >> connect to a master. So you can do: >> >> >> 1 >> 2 >> 3 >> 4 >> 5 >> 6 >> >> if request.function in read_only_actions: >> db = DAL(sample(['mysql://...1','mysql://...2','mysql://...3'], 3))elif >> request.action in read_only_actions: >> db = DAL(shuffle(['mysql://...1','mysql://...2','mysql://...3']))else: >> db = DAL(sample(['mysql://...3','mysql://...4','mysql://...5'], 3)) >> >> >> where 1,2,3 are slaves and 3,4,5 are masters. >> > -- > Resources: > - http://web2py.com > - http://web2py.com/book (Documentation) > - http://github.com/web2py/web2py (Source code) > - https://code.google.com/p/web2py/issues/list (Report Issues) > --- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.