Hi all,
Can anyone explain to me how to correctly create sessions in web
applications?
The documentation gives an example with a scoped_session:
from sqlalchemy.orm import scoped_session, sessionmaker
Session = scoped_session(sessionmaker())
Okay, I should wrap the "thing" returned by sessionmaker() in
scoped_session(). But do I later still have to construct Session() by
doing this:
session = Session()
I did some experiments and I don't get it.
Here is the code I tried:
>>> from app.models import Page
>>>
>>> Session = sessionmaker(bind=engine, autoflush=True,
autocommit=False)
>>> session = scoped_session(Session)
>>>
>>> session
<sqlalchemy.orm.scoping.ScopedSession object at 0x848eb8c>
>>> session()
<sqlalchemy.orm.session.Session object at 0x83fe08c>
>>> session.query(Page).count()
211L
>>> session().query(Page).count()
211L
Both work identically, but I don't understand the difference. Can
anyone explain it please?
Also when do I have to call remove() method that is mentioned in
documentation?
Thanks,
Peteris Krumins
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en.