diff --git a/datasette/cli.py b/datasette/cli.py index 4363a28e..7887e642 100644 --- a/datasette/cli.py +++ b/datasette/cli.py @@ -497,6 +497,7 @@ def uninstall(packages, yes): "--internal", type=click.Path(), help="Path to a persistent Datasette internal SQLite database", + envvar="DATASETTE_INTERNAL", ) def serve( files, diff --git a/docs/cli-reference.rst b/docs/cli-reference.rst index 2302f742..db903e8e 100644 --- a/docs/cli-reference.rst +++ b/docs/cli-reference.rst @@ -76,6 +76,8 @@ Or since this is the default command you can run this instead:: Once started you can access it at ``http://localhost:8001`` +Use ``--internal PATH`` or the ``DATASETTE_INTERNAL`` environment variable to persist :ref:`Datasette's internal database ` to a SQLite file. + .. [[[cog help(["serve", "--help"]) .. ]]] diff --git a/docs/internals.rst b/docs/internals.rst index c05c7e27..8607e6b8 100644 --- a/docs/internals.rst +++ b/docs/internals.rst @@ -2473,7 +2473,20 @@ No token, cookie, or hidden form field is needed. Any ``
`` i Datasette's internal database ============================= -Datasette maintains an "internal" SQLite database used for configuration, caching, and storage. Plugins can store configuration, settings, and other data inside this database. By default, Datasette will use a temporary in-memory SQLite database as the internal database, which is created at startup and destroyed at shutdown. Users of Datasette can optionally pass in a ``--internal`` flag to specify the path to a SQLite database to use as the internal database, which will persist internal data across Datasette instances. +Datasette maintains an "internal" SQLite database used for configuration, caching, and storage. Plugins can store configuration, settings, and other data inside this database. By default, Datasette will use a temporary in-memory SQLite database as the internal database, which is created at startup and destroyed at shutdown. + +To persist internal data across Datasette instances, use the ``--internal`` option to specify the path to a SQLite database: + +.. code-block:: bash + + datasette mydatabase.db --internal internal.db + +You can also set the ``DATASETTE_INTERNAL`` environment variable to specify this path without passing ``--internal`` each time: + +.. code-block:: bash + + export DATASETTE_INTERNAL=/path/to/internal.db + datasette mydatabase.db Datasette maintains tables called ``catalog_databases``, ``catalog_tables``, ``catalog_views``, ``catalog_columns``, ``catalog_indexes``, ``catalog_foreign_keys`` with details of the attached databases and their schemas. These tables should not be considered a stable API - they may change between Datasette releases.