cozodb / pycozo

The Python client and Jupyter helper for CozoDB
Mozilla Public License 2.0
47 stars 9 forks source link

feat: add context-manager dunder methods to `MultiTransact` #10

Closed extradosages closed 9 months ago

extradosages commented 12 months ago

This adds the __enter__ and __exit__ methods to the MultiTransact class in client.py, so that MultiTransact instances can be used with the with construct. The __exit__ method, which is used to clean-up resources, is presently implemented by trying to abort the transaction. I am presuming that if the transaction has already been committed, then attempting to abort with raise a runtime error and will not change any state in the db. I'd consider a solution in which I was able to check the state of the transaction from python to be more elegant, but I didn't see such an API available. For another PR, perhaps.

This also updates the README to document the usage of multi-transactions as a context-manager.

extradosages commented 12 months ago

Damn, it seems as though I formatted both README.md and client.py.

extradosages commented 12 months ago

Fixed.