mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
Pin the Database context manager contract
with Database(...) closes the connection on exit without committing, so uncommitted changes are rolled back. This was the existing behavior but was undocumented and untested - it is now stated in the docs and pinned by a test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UnLnhsH25Nnv7LHhekUfPd
This commit is contained in:
parent
70b48a3b16
commit
a6fcb5af62
2 changed files with 17 additions and 0 deletions
|
|
@ -144,6 +144,8 @@ The ``Database`` object also works as a context manager, which will automaticall
|
|||
db["my_table"].insert({"name": "Example"})
|
||||
# Connection is automatically closed here
|
||||
|
||||
Exiting the block closes the connection without committing, so any changes that are still inside an open transaction at that point - for example writes made with raw ``db.execute()`` calls - will be rolled back. Commit explicitly, or use methods such as ``.insert()`` and the ``db.atomic()`` context manager which commit their own transactions.
|
||||
|
||||
.. _python_api_attach:
|
||||
|
||||
Attaching additional databases
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue