ensure all add account insert statements occur within a transaction

pull/43/head
Chris Veilleux 2019-02-08 15:15:28 -06:00
parent 44cf4e9e6f
commit 65d19a147d
1 changed files with 9 additions and 4 deletions

View File

@ -17,13 +17,18 @@ def _encrypt_password(password):
class AccountRepository(object):
def __init__(self, db):
self.db = db
self.cursor = Cursor(db)
def add(self, account: Account, password: str):
account.id = self._add_account(account, password)
self._add_agreement(account)
if account.subscription is not None:
self._add_subscription(account)
prev_autocommit = self.db.autocommit
self.db.autocommit = False
with self.db:
account.id = self._add_account(account, password)
self._add_agreement(account)
if account.subscription is not None:
self._add_subscription(account)
self.db.autocommit = prev_autocommit
def _add_account(self, account: Account, password: str):
"""Add a row to the account table."""