Is there a way to open a database file under a custom name, independent of its filename? #2808
Replies: 1 comment
-
|
No CLI flag or metadata/config option does this rn, the internal name is always derived from the filename. On the serve path each file is opened with Cleanest fix is a tiny startup plugin that registers the file under a fixed name, so canned queries/templates keyed to from datasette import hookimpl
from datasette.database import Database
@hookimpl
def startup(datasette):
async def inner():
datasette.add_database(
Database(datasette, path="/abs/path/client_a.db", is_mutable=False),
name="mydb",
)
return innerDrop it in a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have multiple SQLite files with different names (
client_a.db,client_b.db, etc.) that all share the same structure. I want to open any one of them with Datasette and always have it appear under a single canonical name (e.g.mydb), so that canned queries and custom templates defined formydbkeep working regardless of which file I actually open.Right now Datasette derives the name from the filename, so each file gets a different name and I'd need to duplicate my queries and templates for every possible filename.
What I've tried:
ln -sf client_a.db mydb.db && datasette mydb.dbworks but feels fragileI also noticed
db.route(#1668) already separates the URL path from the internal name for plugins, so I'm wondering if there's a config-level equivalent I've missed.Is there an existing way to do this?
Beta Was this translation helpful? Give feedback.
All reactions