-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved (and better documented) support for transactions #121
Comments
Better transaction handling would be really great. Some of my thoughts on implementing better transaction discipline are in #118 (comment). My preferences:
db = sqlite_utils.Database(path)
with db: # ← BEGIN issued here by Database.__enter__
db.insert(…)
db.create_view(…)
# ← COMMIT/ROLLBACK issue here by sqlite3.connection.__exit__ |
I'm with you on most of this. Completely agreed that the CLI should do everything in a transaction. The one thing I'm not keen on is forcing calling code to explicitly start a transaction, for a couple of reasons:
So... how about this: IF you wrap your code in a That way existing code works as it does today, lazy people like me can call |
Yep, I agree that makes more sense for backwards compat and more casual use cases. I think it should be possible for the Database/Queryable methods to DTRT based on seeing if it's within a context-manager-managed transaction. |
Just a heads-up that there is a new autocommit attribute and transaction logic in Python 3.12: https://docs.python.org/3.12/library/sqlite3.html#sqlite3.Connection.autocommit |
I've played a bit with that functionality. It does not work yet with the Table accessor, added unit tests to demonstrate here: #637 |
Originally posted by @simonw in #118 (comment)
We should put some thought into how this library supports and encourages smart use of transactions.
The text was updated successfully, but these errors were encountered: