On Jul 8, 2008, at 11:02 AM, Manlio Perillo wrote:

>
> Hi.
>
> Is it ok to do something like:
>
> def helper(conn):
>     sess = orm.create_session(bind=conn)
>
>     t = Test()
>     t.x = 121
>
>     sess.save(t)
>     sess.flush()
>     sess.close()
>
>
> db = create_engine(URL)
> db.transaction(db, helper)


its fine although the Session itself can create transaction boundaries:

Session = sessionmaker(autocommit=False)
def transactional(fn):
     def wrap():
         sess = Session()
         try:
             ret = fn(sess)
             sess.commit()
             return ret
         except:
             sess.rollback()
             raise
         finally:
             sess.close()
     return wrap

@transactional
def do(session):
     <work with session>


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

Reply via email to