Add tables command to list tables in a database

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Simon Willison 2026-02-24 14:57:18 -08:00
commit f47738495d

View file

@ -84,6 +84,34 @@ def databases(url_or_alias, token):
click.echo(json.dumps(response.json(), indent=2))
@cli.command()
@click.argument("url_or_alias", default=None, required=False)
@click.option("--token", help="API token")
def tables(url_or_alias, token):
"""
List tables in a Datasette database
Example usage:
\b
dclient tables https://latest.datasette.io/fixtures
"""
url = _resolve_url(url_or_alias)
token = _resolve_token(token, url)
headers = {}
if token:
headers["Authorization"] = f"Bearer {token}"
response = httpx.get(
url.rstrip("/") + "/-/tables.json",
headers=headers,
follow_redirects=True,
timeout=30.0,
)
if response.status_code != 200:
raise click.ClickException(f"{response.status_code} error")
click.echo(json.dumps(response.json(), indent=2))
@cli.command()
@click.argument("url_or_alias")
@click.argument("sql")