Load example SQL scripts into Datasette on startup
Install this plugin in the same environment as Datasette.
pip install datasette-examples
This plugin is configured using metadata.yaml
(or metadata.json
or datasette.yml
in Datasette 1.0).
Add a block like this that specifies the example SQL scripts you would like to load:
plugins:
datasette-examples:
startup:
examples:
- url: https://example.com/path/to/example1.sql
if_not_table: table_name_1
- url: https://example.com/path/to/example2.sql
if_not_table: table_name_2
When Datasette starts running, it will:
- Check if the specified table (
if_not_table
) exists in theexamples.db
database - If the table doesn't exist, it will download the SQL file from the provided URL
- Execute the SQL against
examples.db
The if_not_table
should be set to a table that is created by the script, to prevent the script from executing more than once.
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
cd datasette-examples
python3 -m venv venv
source venv/bin/activate
Now install the dependencies and test dependencies:
pip install -e '.[test]'
To run the tests:
pytest