Database(is_mutable=) now defaults to True, closes #1808

Refs https://github.com/simonw/datasette-upload-dbs/issues/6
pull/1812/head
Simon Willison 2022-09-09 09:19:20 -07:00
rodzic bf8d84af54
commit fb7e70d5e7
4 zmienionych plików z 8 dodań i 7 usunięć

Wyświetl plik

@ -28,7 +28,7 @@ AttachedDatabase = namedtuple("AttachedDatabase", ("seq", "name", "file"))
class Database:
def __init__(
self, ds, path=None, is_mutable=False, is_memory=False, memory_name=None
self, ds, path=None, is_mutable=True, is_memory=False, memory_name=None
):
self.name = None
self.route = None
@ -39,7 +39,6 @@ class Database:
self.memory_name = memory_name
if memory_name is not None:
self.is_memory = True
self.is_mutable = True
self.hash = None
self.cached_size = None
self._cached_table_counts = None

Wyświetl plik

@ -426,12 +426,13 @@ The ``db`` parameter should be an instance of the ``datasette.database.Database`
Database(
datasette,
path="path/to/my-new-database.db",
is_mutable=True,
)
)
This will add a mutable database and serve it at ``/my-new-database``.
Use ``is_mutable=False`` to add an immutable database.
``.add_database()`` returns the Database instance, with its name set as the ``database.name`` attribute. Any time you are working with a newly added database you should use the return value of ``.add_database()``, for example:
.. code-block:: python
@ -671,8 +672,8 @@ Instances of the ``Database`` class can be used to execute queries against attac
.. _database_constructor:
Database(ds, path=None, is_mutable=False, is_memory=False, memory_name=None)
----------------------------------------------------------------------------
Database(ds, path=None, is_mutable=True, is_memory=False, memory_name=None)
---------------------------------------------------------------------------
The ``Database()`` constructor can be used by plugins, in conjunction with :ref:`datasette_add_database`, to create and register new databases.
@ -685,7 +686,7 @@ The arguments are as follows:
Path to a SQLite database file on disk.
``is_mutable`` - boolean
Set this to ``True`` if it is possible that updates will be made to that database - otherwise Datasette will open it in immutable mode and any changes could cause undesired behavior.
Set this to ``False`` to cause Datasette to open the file in immutable mode.
``is_memory`` - boolean
Use this to create non-shared memory connections.

Wyświetl plik

@ -499,6 +499,7 @@ def test_mtime_ns_is_none_for_memory(app_client):
def test_is_mutable(app_client):
assert Database(app_client.ds, is_memory=True).is_mutable is True
assert Database(app_client.ds, is_memory=True, is_mutable=True).is_mutable is True
assert Database(app_client.ds, is_memory=True, is_mutable=False).is_mutable is False

Wyświetl plik

@ -58,7 +58,7 @@ async def test_datasette_constructor():
"route": "_memory",
"path": None,
"size": 0,
"is_mutable": False,
"is_mutable": True,
"is_memory": True,
"hash": None,
}