mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-09 01:54:21 +02:00
Use sqlean if available in environment (#560)
Closes #559 Closes #235 Refs https://github.com/simonw/llm/issues/60 - Uses `sqlean` in place of `sqlite3` if `sqlean.py` is installed - Uses `sqlite-dump` if available and `conn.iterdump()` does not exist - New `with db.ensure_autocommit_off()` method for ensuring autocommit is off, used by `enable_wal()` and `disable_wal()`.
This commit is contained in:
parent
2747257a33
commit
f5c63088e1
12 changed files with 136 additions and 19 deletions
|
|
@ -39,6 +39,32 @@ Using pipx
|
|||
|
||||
pipx install sqlite-utils
|
||||
|
||||
.. _installation_sqlite3_alternatives:
|
||||
|
||||
Alternatives to sqlite3
|
||||
=======================
|
||||
|
||||
By default, ``sqlite-utils`` uses the ``sqlite3`` package bundled with the Python standard library.
|
||||
|
||||
Depending on your operating system, this may come with some limitations.
|
||||
|
||||
On some platforms the ability to load additional extensions (via ``conn.load_extension(...)`` or ``--load-extension=/path/to/extension``) may be disabled.
|
||||
|
||||
You may also see the error ``sqlite3.OperationalError: table sqlite_master may not be modified`` when trying to alter an existing table.
|
||||
|
||||
You can work around these limitations by installing either the `pysqlite3 <https://pypi.org/project/pysqlite3/>`__ package or the `sqlean.py <https://pypi.org/project/sqlean.py/>`__ package, both of which provide drop-in replacements for the standard library ``sqlite3`` module but with a recent version of SQLite and full support for loading extensions.
|
||||
|
||||
To install ``sqlean.py`` (which has compiled binary wheels available for all major platforms) run the following:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
sqlite-utils install sqlean.py
|
||||
|
||||
``pysqlite3`` and ``sqlean.py`` do not provide implementations of the ``.iterdump()`` method. To use that method (see :ref:`python_api_itedump`) or the ``sqlite-utils dump`` command you should also install the ``sqlite-dump`` package:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
sqlite-utils install sqlite-dump
|
||||
|
||||
.. _installation_completion:
|
||||
|
||||
|
|
|
|||
|
|
@ -1779,6 +1779,25 @@ The ``db.sqlite_version`` property returns a tuple of integers representing the
|
|||
>>> db.sqlite_version
|
||||
(3, 36, 0)
|
||||
|
||||
.. _python_api_itedump:
|
||||
|
||||
Dumping the database to SQL
|
||||
===========================
|
||||
|
||||
The ``db.iterdump()`` method returns a sequence of SQL strings representing a complete dump of the database. Use it like this:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
full_sql = "".join(db.iterdump())
|
||||
|
||||
This uses the `sqlite3.Connection.iterdump() <https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.iterdump>`__ method.
|
||||
|
||||
If you are using ``pysqlite3`` or ``sqlean.py`` the underlying method may be missing. If you install the `sqlite-dump <https://pypi.org/project/sqlite-dump/>`__ package then the ``db.iterdump()`` method will use that implementation instead:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install sqlite-dump
|
||||
|
||||
.. _python_api_introspection:
|
||||
|
||||
Introspecting tables and views
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue