mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-28 04:44:26 +02:00
Unwrap hard-wrapped prose in the documentation
The documentation style for this project is one line per paragraph, not text-wrapped RST. Unwraps three recently added paragraphs in python-api.rst and two older ones in plugins.rst. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UnLnhsH25Nnv7LHhekUfPd
This commit is contained in:
parent
89af511f79
commit
7a015cff52
2 changed files with 7 additions and 20 deletions
|
|
@ -140,9 +140,7 @@ As a special niche feature, if your plugin needs to import some files and then a
|
||||||
prepare_connection(conn)
|
prepare_connection(conn)
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
This hook is called when a new SQLite database connection is created. You can
|
This hook is called when a new SQLite database connection is created. You can use it to `register custom SQL functions <https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.create_function>`_, aggregates and collations. For example:
|
||||||
use it to `register custom SQL functions <https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.create_function>`_,
|
|
||||||
aggregates and collations. For example:
|
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
|
@ -154,8 +152,7 @@ aggregates and collations. For example:
|
||||||
"hello", 1, lambda name: f"Hello, {name}!"
|
"hello", 1, lambda name: f"Hello, {name}!"
|
||||||
)
|
)
|
||||||
|
|
||||||
This registers a SQL function called ``hello`` which takes a single
|
This registers a SQL function called ``hello`` which takes a single argument and can be called like this:
|
||||||
argument and can be called like this:
|
|
||||||
|
|
||||||
.. code-block:: sql
|
.. code-block:: sql
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -148,21 +148,11 @@ The ``Database`` object also works as a context manager, which will automaticall
|
||||||
db["my_table"].insert({"name": "Example"})
|
db["my_table"].insert({"name": "Example"})
|
||||||
# Connection is automatically closed here
|
# Connection is automatically closed here
|
||||||
|
|
||||||
Exiting the block is equivalent to calling ``db.close()``: the connection is
|
Exiting the block is equivalent to calling ``db.close()``: the connection is closed and any transaction still open at that point is rolled back. This matches SQLite's own behavior when a connection closes.
|
||||||
closed and any transaction still open at that point is rolled back. This
|
|
||||||
matches SQLite's own behavior when a connection closes.
|
|
||||||
|
|
||||||
This rarely matters in practice. Everything that writes to the database -
|
This rarely matters in practice. Everything that writes to the database - including raw ``db.execute()`` statements - commits automatically, so a transaction can only be open here if you explicitly started one with ``db.begin()`` and have not yet committed it. In that case the decision to commit stays with you: committing automatically on exit could silently persist half-finished work, for example if your code returned early from the block. Call ``db.commit()`` when the work is complete.
|
||||||
including raw ``db.execute()`` statements - commits automatically, so a
|
|
||||||
transaction can only be open here if you explicitly started one with
|
|
||||||
``db.begin()`` and have not yet committed it. In that case the decision to
|
|
||||||
commit stays with you: committing automatically on exit could silently
|
|
||||||
persist half-finished work, for example if your code returned early from the
|
|
||||||
block. Call ``db.commit()`` when the work is complete.
|
|
||||||
|
|
||||||
Note this differs from the ``sqlite3.Connection`` context manager in the
|
Note this differs from the ``sqlite3.Connection`` context manager in the standard library, which commits on success but does not close the connection. See :ref:`python_api_transactions` for the full transaction model.
|
||||||
standard library, which commits on success but does not close the connection.
|
|
||||||
See :ref:`python_api_transactions` for the full transaction model.
|
|
||||||
|
|
||||||
.. _python_api_attach:
|
.. _python_api_attach:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue