[sqlalchemy] Re: Storing DB engine in session
On Oct 17, 2007, at 7:35 AM, Paul Johnston wrote: > Don't know why the Pylons session save was failing, perhaps it > doesn't allow arbitrary Python objects. in most cases, the pylons session is going to pickle whatever comes in and store it in a file, so that doesnt translate to things like connection pools. --~--~-~--~~~---~--~~ 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: Storing DB engine in session
Hi, Does this create new connection with the same name or start using the > existing one? I'm almost 100% that latter, just making sure. It should re-use existing ones, in a fairly intelligent way. Still, I'd suggest doing some load testing before going live with this. > Right now I'm binding meta to the engine, which obviosly makes all the > tables work with the last engine plugged in Ok, don't do that, not thread safe. You probably want all your tables in a MetaData that is not bound to any database. Bind your sessions to the user-specific engine. I'd suggest starting off with manual sessions. You probably can do this using scoped_session, just get it working with manual sessions first. One consideration is that this won't work if you have multiple databases. At the moment, it's pretty much impossible to support multiple dbs in this configuration. > select([func.count("*")], from_obj=[sell_table]).sess.execute() How about: engine.execute(select([func.count("*")], from_obj=[sell_table])) Paul --~--~-~--~~~---~--~~ 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: Storing DB engine in session
Thanks a lot, Paul. Great point, works just great. That pretty much solved the issue. log_dic log_typle = (session['login'], session['password']) if not log_dic.has_key((log_typle)): engine = create_engine(uri) log_dic[log_typle] = engine else: engine = log_dic[(session['login'], session['password'])] Does this create new connection with the same name or start using the existing one? I'm almost 100% that latter, just making sure. Right now I'm binding meta to the engine, which obviosly makes all the tables work with the last engine plugged in What'll be your advice for this matter. The most obvious way i see is using Contextual Session. This way I'll have to add Session = scoped_session(sessionmaker(autoflush=True, transactional=True, bind=current_user_engine)) But I'll have to rewrite all the SQL statements so that they'll start running using sessions. select([func.count("*")], from_obj=[sell_table]).sess.execute() What'll be your best practice advice on this one? On Oct 17, 3:35 pm, "Paul Johnston" <[EMAIL PROTECTED]> wrote: > Hi, > > Here's how it should work: every time the user logs in, SA creates a > > > new engine with his log/pass or uses the one that was already opened > > and then uses it. > > Unless something has changed recently, this pattern is not particularly > supported. > > Still, you could probably get it working with bound sessions. If the engine > doesn't exist in the users, session, create the engine and save in the > session. Don't know why the Pylons session save was failing, perhaps it > doesn't allow arbitrary Python objects. You could keep your own dictionary, > keyed on (username, password) tuples and avoid sessions altogether. > > Paul --~--~-~--~~~---~--~~ 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: Storing DB engine in session
Hi, Here's how it should work: every time the user logs in, SA creates a > new engine with his log/pass or uses the one that was already opened > and then uses it. Unless something has changed recently, this pattern is not particularly supported. Still, you could probably get it working with bound sessions. If the engine doesn't exist in the users, session, create the engine and save in the session. Don't know why the Pylons session save was failing, perhaps it doesn't allow arbitrary Python objects. You could keep your own dictionary, keyed on (username, password) tuples and avoid sessions altogether. Paul --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---