Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/python-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,27 @@ You can pass ``strict=True`` to enable `SQLite STRICT mode <https://www.sqlite.o

db = Database("my_database.db", strict=True)

.. _python_api_close:

Closing a database
------------------

Database objects maintain a connection to the underlying SQLite database. You can explicitly close this connection using the ``.close()`` method:

.. code-block:: python

db = Database("my_database.db")
# ... use the database ...
db.close()

The ``Database`` object also works as a context manager, which will automatically close the connection when the ``with`` block exits:

.. code-block:: python

with Database("my_database.db") as db:
db["my_table"].insert({"name": "Example"})
# Connection is automatically closed here

.. _python_api_attach:

Attaching additional databases
Expand Down
Loading
Loading