On Friday, January 5, 2018 at 7:50:28 PM UTC-8, CDA wrote:
>
> 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?
>
>
I would expect that the http request wouldn't directly select a database.  
Instead, your controller would know if a select() was being done to satisfy 
the request (typical for HTTP GET, but often needed for other reasons), or 
an insert or update (often an HTTP POST or HTTP PUT), or a delete (such as 
for an HTTP DELETE).  But it's your controller that decides what type of DB 
operation is required.  AIUI.

/dps

 

> On Fri, Jan 5, 2018 at 6:35 PM, Anthony <abas...@gmail.com <javascript:>> 
> 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+un...@googlegroups.com <javascript:>.
>> 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.

Reply via email to