mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
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:
parent
9c46f2f21f
commit
947645d847
15 changed files with 201 additions and 18 deletions
|
|
@ -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 = """
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue