Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: -o could open to a more convenient location #976

Closed
simonw opened this issue Sep 24, 2020 · 2 comments
Closed

Idea: -o could open to a more convenient location #976

simonw opened this issue Sep 24, 2020 · 2 comments
Labels

Comments

@simonw
Copy link
Owner

simonw commented Sep 24, 2020

Idea: if a database only has a single table, this could open straight to /db/table. If it has multiple tables but a single database it could open straight to /db.
Originally posted by @simonw in #970 (comment)

@simonw simonw added the idea label Sep 24, 2020
@simonw
Copy link
Owner Author

simonw commented Sep 24, 2020

This is complex enough new logic that it will need test coverage - specifically covering tables or databases with strange names.

@simonw simonw closed this as completed in f5dbe61 Oct 26, 2020
@simonw
Copy link
Owner Author

simonw commented Oct 26, 2020

I used the new datasette.urls methods to handle escaping table names.

async def initial_path_for_datasette(datasette):
"Return suggested path for opening this Datasette, based on number of DBs and tables"
if len(datasette.databases) == 1:
db_name = next(iter(datasette.databases.keys()))
path = datasette.urls.database(db_name)
# Does this DB only have one table?
db = next(iter(datasette.databases.values()))
tables = await db.table_names()
if len(tables) == 1:
path = datasette.urls.table(db_name, tables[0])
else:
path = datasette.urls.instance()
return path

simonw added a commit that referenced this issue Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant