This question should be directed at the SQLAlchemy mailing list. I'll just post this here in case it helps:
http://techspot.zzzeek.org/2012/01/11/django-style-database-routers-in-sqlalchemy/ On Thu, Jan 26, 2012 at 4:47 PM, Jonathan Vanasco <jonat...@findmeon.com>wrote: > I've set up my application with multiple database connections to > postgresql, which then reflects the table structure into my classes > under /models. i am using sqlahelper. > > myapp_reader can read to all tables > myapp_writer can read and write to all tables > > what I 'expected' is as follows: > - calls to sqlahelper.get_session() would return the session ( ok, it > does ) > - items that i try to 'add' to the session would go through the > 'primary mapper' , unless I call something like > binds= {models.core.TestTable : sqlahelper.get_engine('reader') } > dbSession.configure(binds=binds) " > > what I experienced is this: > - items are randomly saved to the database through either the > myapp_reader or myapp_writer engines. sometimes the engines change > every other request, sometimes they stick for a while. there's simply > no way to predict. > > > can anyone offer suggestions. i clearly didn't do something > correctly. > > > the relevant code for my setup is below.... > > > .ini > sqlalchemy_reader.url = postgres://myapp_reader:myapp@localhost/myapp > sqlalchemy_writer.url = postgres://myapp_writer:myapp@localhost/myapp > > __init__.py > engine_reader = sqlalchemy.engine_from_config(settings, > prefix="sqlalchemy_reader.") > sqlahelper.add_engine(engine_reader,name='reader') > models.initialize_sql(engine_reader,primary=True) > engine_writer = sqlalchemy.engine_from_config(settings, > prefix="sqlalchemy_writer.") > sqlahelper.add_engine(engine_writer,name='writer') > models.initialize_sql(engine_writer,primary=False) > > models/__init__.py > def initialize_sql(engine,primary=True): > DBSession.configure(bind=engine) > DBMetadata.bind = engine > map_tables( myapp.models , primary=primary ) > > def map_tables( app_model , primary=False ): > to_reflect= code to find items to reflect > for item in to_reflect: > table= Table( table_name, DBMetadata, autoload=True ) > if primary: > mapper( _class , table ) > else: > mapper( _class , table , non_primary=True ) > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To post to this group, send email to pylons-discuss@googlegroups.com. > To unsubscribe from this group, send email to > pylons-discuss+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/pylons-discuss?hl=en. > > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.