aries-askar
aries-askar copied to clipboard
Transaction commit
I had a question come up as I've been working with the Askar Python wrapper.
Consider these lines from the demo script:
async with store.transaction() as txn:
# ^ should be faster within a transaction
for idx in range(PERF_ROWS):
await txn.insert(
"txn",
f"name-{idx}",
b"value",
{"~plaintag": "a", "enctag": "b"},
)
await txn.commit()
My question pertains to the await txn.commit() on the final line. As I understand it, after commit has been called, the handle is closed. In other words, it is impossible to do something like:
async with store.transaction() as txn:
# ^ should be faster within a transaction
for idx in range(PERF_ROWS):
await txn.insert(
"txn",
f"name-{idx}",
b"value",
{"~plaintag": "a", "enctag": "b"},
)
await txn.commit()
await txn.insert(
"txn",
f"name-one-more",
b"value",
{"~plaintag": "a", "enctag": "b"},
)
await txn.commit()
Therefore, calling commit should essentially terminate every async with store.transaction() block and can occur only once within the block. My question: why not call commit on exit of the with block (within the context manager itself)? This seems like an ideal case for using this pattern, in fact, from my perspective at least.
Curious to hear your rationale. Thanks!