Changes between Version 4 and Version 5 of Recipes/MultipleDatabases

Show
Ignore:
Timestamp:
12/10/07 19:40:59 (5 years ago)
Author:
guest (IP: 195.27.52.9)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Recipes/MultipleDatabases

    v4 v5  
    113113=== Pylons Integration === 
    114114 
    115 Use the "multiple files" method above as a starting point. Remove the "create_engine" lines in the models.  
     115Use the "multiple files" method above as a starting point. Remove the "create_engine" lines in the model files a.py and b.py.  
    116116 
    117117==== {{{project/model/__init__.py}}} ==== 
     
    123123}}} 
    124124 
     125==== {{{development.ini}}} ==== 
     126 
     127Just add as many sqlalchemy urls as neccessary. 
     128 
     129{{{ 
     130sqlalchemy.a.url = sqlite:///%(here)s/databases/a.db 
     131sqlalchemy.b.url = sqlite:///%(here)s/databases/b.db  
     132}}} 
     133 
     134==== {{{project/config/environment.py}}} ==== 
     135 
     136Edit the global environment settings and set the following to setup your session's and metadata's when the application is started. 
     137 
     138{{{ 
     139from sqlalchemy import engine_from_config 
     140config['pylons.g'].engine_a = engine_from_config(config,'sqlalchemy.a.') 
     141config['pylons.g'].engine_b = engine_from_config(config,'sqlalchemy.b.') 
     142 
     143import project.model as model 
     144model.a_session.bind = config['pylons.g'].engine_a 
     145model.a_metadata.bind = config['pylons.g'].engine_a 
     146model.b_session.bind = config['pylons.g'].engine_b 
     147model.b_metadata.bind = config['pylons.g'].engine_b 
     148}}} 
     149 
     150==== {{{project/lib/base.py}}} ==== 
     151 
     152Edit the end of call method to cleanup with 
     153 
     154{{{ 
     155   finally: 
     156       model.a_session.remove() 
     157       model.b_session.remove() 
     158}}}