Advertisement
Guest User

Untitled

a guest
Jul 15th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. from contextlib import contextmanager
  2.  
  3. class A:
  4.     @contextmanager
  5.     def transaction(self, isolation_level="DEFERRED"):
  6.         prev_iso_lvl = self.conn.isolation_level
  7.         self.conn.isolation_level = "DEFERRED"
  8.         self.conn.execute("BEGIN")
  9.         yield
  10.         self.conn.commit()
  11.         self.conn.isolation_level = prev_iso_lvl
  12.  
  13.     def insert_many(self, users, users_data):
  14.         with self.transaction():
  15.             for user in users:
  16.                 data = users_data[user['username']]
  17.                 self.insert(user, data)              # !!!
  18.  
  19.     def insert_many(self, users, users_data):
  20.         with self.transaction():
  21.             for user in users:
  22.                 data = users_data[user['username']]
  23.                 self.update(user, data)              # !!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement