mirror of
https://github.com/simonw/dclient.git
synced 2026-07-26 02:44:34 +02:00
Replace aliases.json with config.json storing instances with default_database. Instance resolution: -i flag → config default → DATASETTE_URL. Database resolution: -d flag → instance default_database → DATASETTE_DATABASE. Token resolution: --token → auth.json by alias → auth.json by URL → DATASETTE_TOKEN. Add click-default-group dependency for bare SQL shortcut support. Add DCLIENT_CONFIG_DIR env var to override config directory. Rewrite query, insert, get, and actor commands for v2 API where instance is always -i flag. Add upsert command sharing insert implementation. Add databases, tables, schema, plugins commands. Add default_query hidden command for bare SQL shortcut. Add alias default, alias default-db subcommands. Add auth status subcommand. refs #29 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
70 lines
1.7 KiB
Markdown
70 lines
1.7 KiB
Markdown
# Running queries
|
|
|
|
You can run SQL queries against a Datasette instance like this:
|
|
|
|
```bash
|
|
dclient query fixtures "select * from facetable limit 1" -i https://latest.datasette.io
|
|
```
|
|
Output:
|
|
```json
|
|
[
|
|
{
|
|
"pk": 1,
|
|
"created": "2019-01-14 08:00:00",
|
|
"planet_int": 1,
|
|
"on_earth": 1,
|
|
"state": "CA",
|
|
"_city_id": 1,
|
|
"_neighborhood": "Mission",
|
|
"tags": "[\"tag1\", \"tag2\"]",
|
|
"complex_array": "[{\"foo\": \"bar\"}]",
|
|
"distinct_some_null": "one",
|
|
"n": "n1"
|
|
}
|
|
]
|
|
```
|
|
|
|
The `query` command takes a database name and SQL string as positional arguments. Use `-i` to specify the instance (alias or URL). If you have a default instance and default database configured, you can use the bare SQL shortcut instead:
|
|
|
|
```bash
|
|
dclient "select * from facetable limit 1"
|
|
```
|
|
|
|
You can override just the database with `-d`:
|
|
|
|
```bash
|
|
dclient "select * from counters" -d counters
|
|
```
|
|
|
|
## dclient query --help
|
|
<!-- [[[cog
|
|
import cog
|
|
from dclient import cli
|
|
from click.testing import CliRunner
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli.cli, ["query", "--help"])
|
|
help = result.output.replace("Usage: cli", "Usage: dclient")
|
|
cog.out(
|
|
"```\n{}\n```".format(help)
|
|
)
|
|
]]] -->
|
|
```
|
|
Usage: dclient query [OPTIONS] DATABASE SQL
|
|
|
|
Run a SQL query against a Datasette database
|
|
|
|
Requires both a database name and a SQL string.
|
|
|
|
Example usage:
|
|
|
|
dclient query fixtures "select * from facetable limit 5"
|
|
dclient query analytics "select count(*) from events" -i staging
|
|
|
|
Options:
|
|
-i, --instance TEXT Datasette instance URL or alias
|
|
--token TEXT API token
|
|
-v, --verbose Verbose output: show HTTP request
|
|
--help Show this message and exit.
|
|
|
|
```
|
|
<!-- [[[end]]] -->
|