Advertisement
Guest User

Untitled

a guest
Nov 18th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. @contextmanager
  2. def transacting(db):
  3.     try:
  4.         yield db
  5.     except:
  6.         db.rollback()
  7.         raise
  8.     else:
  9.         db.commit()
  10.     db.close()
  11.  
  12. with transacting(connect_db()) as db:
  13.     with app.open_resource('schema.sql', mode='r') as f:
  14.         db.cursor().executescript(f.read())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement