-
-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.add_database() and .remove_database() methods, refs #671
Also made a start on the Datasette class documentation, refs #576
- Loading branch information
Showing
4 changed files
with
60 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.. _datasette: | ||
|
||
Datasette class | ||
=============== | ||
|
||
Many of Datasette's :ref:`plugin_hooks` pass a ``datasette`` object to the plugin as an argument. | ||
|
||
This object is an instance of the ``Datasette`` class. That class currently has a large number of methods on it, but it should not be considered stable (at least until Datasette 1.0) with the exception of the methods that are documented on this page. | ||
|
||
.add_database(name, db) | ||
----------------------- | ||
|
||
The ``datasette.add_database(name, db)`` method lets you add a new database to the current Datasette instance. This database will then be served at URL path that matches the ``name`` parameter, e.g. ``/mynewdb/``. | ||
|
||
The ``db`` parameter should be an instance of the ``datasette.database.Database`` class. For example: | ||
|
||
.. code-block:: python | ||
from datasette.database import Database | ||
datasette.add_database("my-new-database", Database( | ||
datasette, | ||
path="path/to/my-new-database.db", | ||
is_mutable=True | ||
)) | ||
This will add a mutable database from the provided file path. | ||
|
||
The ``Database()`` constructor takes four arguments: the first is the ``datasette`` instance you are attaching to, the second is a ``path=``, then ``is_mutable`` and ``is_memory`` are both optional arguments. | ||
|
||
Use ``is_mutable`` 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. | ||
|
||
Use ``is_memory`` if the connection is to an in-memory SQLite database. | ||
|
||
.remove_database(name) | ||
---------------------- | ||
|
||
This removes a database that has been previously added. ``name=`` is the unique name of that database, also used in the URL for it. | ||
|
||
.plugin_config(plugin_name, database=None, table=None) | ||
------------------------------------------------------ | ||
|
||
This method lets you read plugin configuration values that were set in ``metadata.json``. See :ref:`plugins_plugin_config` for full details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ Contents | |
introspection | ||
custom_templates | ||
plugins | ||
datasette | ||
contributing | ||
changelog | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters