First working -d based Datasette Library

Refs #417

First proof-of-concept for Datasette Library. Run like this:

    datasette -d ~/Library

Uses a new plugin hook - available_databases()

BUT... I don't think this is quite the way I want to go.
This commit is contained in:
Simon Willison 2019-07-26 13:18:19 +03:00
commit 947645d847
15 changed files with 201 additions and 18 deletions

View file

@ -321,6 +321,8 @@ METADATA = {
PLUGIN1 = """
from datasette import hookimpl
from datasette.database import Database
from datasette.utils import sqlite3
import base64
import pint
import json
@ -397,6 +399,20 @@ def extra_template_vars(template, database, table, view_name, request, datasette
"extra_serve_options": datasette.extra_serve_options,
}, default=lambda b: b.decode("utf8"))
}
class SpecialDatabase(Database):
def connect(self):
db = sqlite3.connect(":memory:")
db.executescript("CREATE TABLE foo (id integer primary key, bar text)")
db.executescript("INSERT INTO foo (id, bar) VALUES (1, 'hello')")
return db
@hookimpl
def available_databases(datasette):
return [
("special", SpecialDatabase(datasette, name="special")),
]
"""
PLUGIN2 = """