From 355c02cf7e392b9dc858b49b953814b009b869e3 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 12 Nov 2022 12:38:50 -0800 Subject: [PATCH] Add argument transaction_mode to begin. --- voussoirkit/worms.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/voussoirkit/worms.py b/voussoirkit/worms.py index 41dbfc7..e9cbaba 100644 --- a/voussoirkit/worms.py +++ b/voussoirkit/worms.py @@ -99,7 +99,7 @@ class TransactionContextManager: def __enter__(self): log.loud('Entering transaction.') - self.database.begin() + self.database.begin(transaction_mode='IMMEDIATE') return self def __exit__(self, exc_type, exc_value, exc_traceback): @@ -235,9 +235,12 @@ class Database(metaclass=abc.ABCMeta): if table not in self.COLUMN_INDEX: raise BadTable(f'Table {table} does not exist.') - def begin(self): + def begin(self, transaction_mode='DEFERRED'): + if transaction_mode not in {'DEFERRED', 'IMMEDIATE', 'EXCLUSIVE'}: + raise ValueError(transaction_mode) + self.acquire_transaction_lock() - self.execute('BEGIN') + self.execute(f'BEGIN {transaction_mode}') def close(self): # Wrapped in hasattr because if the object fails __init__, Python will