[sqlalchemy] Re: two scoped sessions in one app?

2008-01-16 Thread Max Ischenko
I had a Session.configure() statement which was called for both sessions and
this was making setup unusable. Duh.

On Jan 16, 2008 2:12 PM, Max Ischenko [EMAIL PROTECTED] wrote:



 On Jan 15, 2008 6:14 PM, Michael Bayer [EMAIL PROTECTED] wrote:

  if you are using multiple scoped sessions you won't be able to use
  Session.mapper - the idea of Session.mapper is that all instances get
  tied to a single contextual session.
 

 OK, so how do I set it up. I'm reading
 http://www.sqlalchemy.org/docs/04/session.html but answer isn't clear.
 Should I use set up one scope session and another with create_session?




-- 
Max
http://maxischenko.in.ua // http://www.linkedin.com/in/maksim

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: two scoped sessions in one app?

2008-01-16 Thread Max Ischenko
On Jan 15, 2008 6:14 PM, Michael Bayer [EMAIL PROTECTED] wrote:

 if you are using multiple scoped sessions you won't be able to use
 Session.mapper - the idea of Session.mapper is that all instances get
 tied to a single contextual session.


OK, so how do I set it up. I'm reading
http://www.sqlalchemy.org/docs/04/session.html but answer isn't clear.
Should I use set up one scope session and another with create_session?

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: two scoped sessions in one app?

2008-01-16 Thread Max Ischenko
Hello,

Sorry for reply to myself; just want to tell that the problem is solved.

Here is how my setup looks like:

Session = scoped_session(sessionmaker(autoflush=True, transactional=False))
SessionCDB = scoped_session(sessionmaker(autoflush=True,
transactional=False))
...
# application startup
sqlalchemy_configure(blog, Session, init_blog_meta)
sqlalchemy_configure(cdb, SessionCDB, init_companydb_meta)
...
def sqlalchemy_configure(dbname, session, callback):
global metadata_cache
from sqlalchemy import engine_from_config
from pylons import config
engine = engine_from_config(config, 'sqlalchemy.%s.' % dbname)
session.configure(bind=engine)
meta = sqlalchemy.MetaData(engine)
metadata_cache[dbname] = meta
callback(session.mapper, meta)

Max.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: two scoped sessions in one app?

2008-01-15 Thread Michael Bayer


On Jan 15, 2008, at 7:37 AM, Max Ischenko wrote:

 Hello,

 I need to access two databases from my app. I'm trying to use  
 scoped_session helper:

 SessionA = scoped_session(sessionmaker(autoflush=True,  
 transactional=False))
 SessionB = scoped_session(sessionmaker(autoflush=True,  
 transactional=False))
 ...
 mapper(SessionA.mapper, ClassFromA ...)
 mapper(SessionB.mapper, ClassFromB ...)

 But when I try to query against SessionA it looks for a table_a in  
 database B. How do I separate two sessions properly?



if you are using multiple scoped sessions you won't be able to use  
Session.mapper - the idea of Session.mapper is that all instances get  
tied to a single contextual session. 
   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---