Hi,

I am working on a web site using Python Django and SQLAlchemy ORM. I want 
to do all read operations in separate database and write operations in 
separate database. 

So I tried *Mike Bayer*'s solution (
http://techspot.zzzeek.org/2012/01/11/django-style-database-routers-in-sqlalchemy/)
 
but query.update() and query.delete() didn't work properly. I debugged some 
code and modified SessionRouter class as following:

class SQLAlchemySessionRouter(Session):
def get_bind(self, mapper=None, clause=None):
if self._flushing:
return ENGINES['write-only']
elif isinstance(clause, sqlalchemy.sql.expression.Update):
return ENGINES['write-only']
elif isinstance(clause, sqlalchemy.sql.expression.Delete):
return ENGINES['write-only']
else:
return ENGINES['read-only']

Now it is working fine in my case (I tested this manually).

I need *Mike Bayer* or experts guidance. Do these modifications looks good? 
Should I go with this solution? Or is there some thing better that can help 
me?

Thanks in advance,

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to