On Nov 8, 2008, at 3:07 PM, Mike Bernson wrote:

>
> I am looking at how to have 2 engines a session.
>
> I want to be able to switch between engine used based on
> if any writes will be happening to the data being read. I
> can tell if any data will be modify by if the transaction
> started by issues a begin.
>
> I want to setup a number of server doing Replication. I need
> to have a master and a number of slaves.
>
> In the code I always start transaction that will be doing write with  
> begin. I would like to
> have the session have 2 engines. The first engine is used outside of  
> any transaction that
> have not started with a begin. This would allow all reads to use a  
> slave mysql server and
> keep the records in the session identify map. The second engine  
> would be used for writes.
> This engine is selected in the transaction started with a begin. The  
> rows are read with
> select for update. These rows also would be session identify map.  
> When flushing modified
> data it need to be flushed to master.


set session.bind = <any engine> as needed.    I recommend a decorator  
for the general use case, such as

@decorator
def with_master(fn, *arg, **kw):
     sess = Session()
     sess.bind = the_master
     try:
         r = fn(*arg, **kw)
     finally:
         sess.bind = not_the_master
     return r



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to