On 10/06/2009, at 1:44 AM, [email protected] wrote:

>
> Hello everyone,
>
> I'm just starting to use pylons so maybe what i have done will be
> quite stupid but i'm still asking ^^
>
> So i want to be able to use about 3/4 databases for my website all on
> the same mysql server, i have modified some file for my project and i
> would like to know if it's the right way to do it ... or not
>
> --- development.ini ---
> replaced : sqlalchemy.url = sqlite:///%(here)s/development.db
> by : ({'name' : 'characters', 'sqlalchemy.url' : 'mysql://
> login:passw...@localhost/characters'}, {'name' : 'realm',
> 'sqlalchemy.url' : 'mysql://login:passw...@localhost/realmd'})
>
> --- environment.py ---
> replaced :
>    engine = engine_from_config(config, 'sqlalchemy.')
>    init_model(engine)
> by:
>    dbs = eval(config['sqlalchemy.databases'])
>    for db in dbs:
>        engine = engine_from_config(db, 'sqlalchemy.')
>        init_model(engine, db['name'])
>
> --- meta.py ---
> replaced:
>    everything
> by:
> class metaObj(object):
>    def __init__(self):
>        self.engine = None
>        self.Session = scoped_session(sessionmaker())
>        self.metadata = MetaData()
>
> metas = {'realm' : metaObj(), 'characters' : metaObj()}
>
> --- model/__init__.py ---
> replaced :
> def init_model(engine):
>    meta.Session.configure(bind=engine)
>    meta.engine = engine
> by:
> def init_model(engine, name):
>    metas[name].Session.configure(bind=engine)
>    metas[name].engine = engine
>
> And the worst for the end ... (this is just a bad hack to try if what
> i've done before was working)
>
> --- base.py ---
> replaced by :
>        #try:
>        return WSGIController.__call__(self, environ, start_response)
>        #finally:
>            #meta.Session.remove()

You should still make sure you remove the sessions.  In your case,  
just loop over all sessions in your "metas" dict and call .remove() on  
each.

I can't say if what you've written will work syntactically, but the  
strategy makes some sense.  Personally, when I do multi database  
support, I just add a second definition for the second database  
everywhere it needs to be.  You're trying to encapsulate the objects  
needed for multiple databases in dicts and custom objects, which - if  
it works - isn't a problem is it?

Cheers
Chris Miles


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

Reply via email to