kopia lustrzana https://github.com/simonw/datasette
Database(is_mutable=) now defaults to True, closes #1808
Refs https://github.com/simonw/datasette-upload-dbs/issues/6pull/1812/head
rodzic
bf8d84af54
commit
fb7e70d5e7
|
@ -28,7 +28,7 @@ AttachedDatabase = namedtuple("AttachedDatabase", ("seq", "name", "file"))
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(
|
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.name = None
|
||||||
self.route = None
|
self.route = None
|
||||||
|
@ -39,7 +39,6 @@ class Database:
|
||||||
self.memory_name = memory_name
|
self.memory_name = memory_name
|
||||||
if memory_name is not None:
|
if memory_name is not None:
|
||||||
self.is_memory = True
|
self.is_memory = True
|
||||||
self.is_mutable = True
|
|
||||||
self.hash = None
|
self.hash = None
|
||||||
self.cached_size = None
|
self.cached_size = None
|
||||||
self._cached_table_counts = None
|
self._cached_table_counts = None
|
||||||
|
|
|
@ -426,12 +426,13 @@ The ``db`` parameter should be an instance of the ``datasette.database.Database`
|
||||||
Database(
|
Database(
|
||||||
datasette,
|
datasette,
|
||||||
path="path/to/my-new-database.db",
|
path="path/to/my-new-database.db",
|
||||||
is_mutable=True,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
This will add a mutable database and serve it at ``/my-new-database``.
|
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:
|
``.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
|
.. code-block:: python
|
||||||
|
@ -671,8 +672,8 @@ Instances of the ``Database`` class can be used to execute queries against attac
|
||||||
|
|
||||||
.. _database_constructor:
|
.. _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.
|
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.
|
Path to a SQLite database file on disk.
|
||||||
|
|
||||||
``is_mutable`` - boolean
|
``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
|
``is_memory`` - boolean
|
||||||
Use this to create non-shared memory connections.
|
Use this to create non-shared memory connections.
|
||||||
|
|
|
@ -499,6 +499,7 @@ def test_mtime_ns_is_none_for_memory(app_client):
|
||||||
|
|
||||||
|
|
||||||
def test_is_mutable(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=True).is_mutable is True
|
||||||
assert Database(app_client.ds, is_memory=True, is_mutable=False).is_mutable is False
|
assert Database(app_client.ds, is_memory=True, is_mutable=False).is_mutable is False
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ async def test_datasette_constructor():
|
||||||
"route": "_memory",
|
"route": "_memory",
|
||||||
"path": None,
|
"path": None,
|
||||||
"size": 0,
|
"size": 0,
|
||||||
"is_mutable": False,
|
"is_mutable": True,
|
||||||
"is_memory": True,
|
"is_memory": True,
|
||||||
"hash": None,
|
"hash": None,
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue