Add more STRICT table support (#604)

* Add more STRICT table support per https://github.com/simonw/sqlite-utils/issues/344#issuecomment-982014776.
* Make `table.transform()` preserve STRICT mode.
* Fix mypy failures in PR #604
* Link to SQLITE strict page in a few places
This commit is contained in:
Taj Khattra 2023-12-07 21:05:27 -08:00 committed by GitHub
commit 1500c19bd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 182 additions and 5 deletions

View file

@ -117,6 +117,12 @@ By default, any :ref:`sqlite-utils plugins <plugins>` that implement the :ref:`p
db = Database(memory=True, execute_plugins=False)
You can pass ``strict=True`` to enable `SQLite STRICT mode <https://www.sqlite.org/stricttables.html>`__ for all tables created using this database object:
.. code-block:: python
db = Database("my_database.db", strict=True)
.. _python_api_attach:
Attaching additional databases
@ -581,6 +587,15 @@ The ``transform=True`` option will update the table schema if any of the followi
Changes to ``foreign_keys=`` are not currently detected and applied by ``transform=True``.
You can pass ``strict=True`` to create a table in ``STRICT`` mode:
.. code-block:: python
db["cats"].create({
"id": int,
"name": str,
}, strict=True)
.. _python_api_compound_primary_keys:
Compound primary keys
@ -661,7 +676,7 @@ You can set default values for these methods by accessing the table through the
# Now you can call .insert() like so:
table.insert({"id": 1, "name": "Tracy", "score": 5})
The configuration options that can be specified in this way are ``pk``, ``foreign_keys``, ``column_order``, ``not_null``, ``defaults``, ``batch_size``, ``hash_id``, ``hash_id_columns``, ``alter``, ``ignore``, ``replace``, ``extracts``, ``conversions``, ``columns``. These are all documented below.
The configuration options that can be specified in this way are ``pk``, ``foreign_keys``, ``column_order``, ``not_null``, ``defaults``, ``batch_size``, ``hash_id``, ``hash_id_columns``, ``alter``, ``ignore``, ``replace``, ``extracts``, ``conversions``, ``columns``, ``strict``. These are all documented below.
.. _python_api_defaults_not_null:
@ -1011,6 +1026,7 @@ The first time this is called the record will be created for ``name="Palm"``. An
- ``extracts``
- ``conversions``
- ``columns``
- ``strict``
.. _python_api_extracts: