mirror of
https://github.com/simonw/dclient.git
synced 2026-08-01 15:04:11 +02:00
Docs for streaming and --interval, closes #21
This commit is contained in:
parent
5a0a81b8da
commit
44d7e2bf9e
2 changed files with 25 additions and 2 deletions
|
|
@ -111,7 +111,7 @@ def query(url_or_alias, sql, token):
|
|||
"--batch-size", type=int, default=100, help="Send rows in batches of this size"
|
||||
)
|
||||
@click.option(
|
||||
"--interval", type=float, default=None, help="Send batch at least every X seconds"
|
||||
"--interval", type=float, default=10, help="Send batch at least every X seconds"
|
||||
)
|
||||
@click.option("--token", "-t", help="API token")
|
||||
@click.option("--silent", is_flag=True, help="Don't output progress")
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ First you'll need to {ref}`authenticate <authentication>` with the instance.
|
|||
To insert data from a `data.csv` file into a table called `my_table`, creating that table if it does not exist:
|
||||
|
||||
```bash
|
||||
dclient insert https://my-private-space.datasette.cloud/data my_table data.csv --create
|
||||
dclient insert \
|
||||
https://my-private-space.datasette.cloud/data \
|
||||
my_table data.csv --create
|
||||
```
|
||||
You can also pipe data into standard input:
|
||||
```bash
|
||||
|
|
@ -17,6 +19,26 @@ curl -s 'https://api.github.com/repos/simonw/dclient/issues' | \
|
|||
issues - --create
|
||||
```
|
||||
|
||||
## Streaming data
|
||||
|
||||
`dclient insert` works for streaming data as well.
|
||||
|
||||
If you have a log file containing newline-delimited JSON you can tail it and send it to a Datasette instance like this:
|
||||
```bash
|
||||
tail -f log.jsonl | \
|
||||
dclient insert https://my-private-space.datasette.cloud/data logs - --nl
|
||||
```
|
||||
When reading from standard input (filename `-`) you are required to specify the format. In this example that's `--nl` for newline-delimited JSON. `--csv` and `--tsv` are supported for streaming as well, but `--json` is not.
|
||||
|
||||
In streaming mode records default to being sent to the server every 100 records or every 10 seconds, whichever comes first. You can adjust these values using the `--batch-size` and `--interval` settings. For example, here's how to send every 10 records or if 5 seconds has passed since the last time data was sent to the server:
|
||||
|
||||
```bash
|
||||
tail -f log.jsonl | dclient insert \
|
||||
https://my-private-space.datasette.cloud/data logs - --nl --create \
|
||||
--batch-size 10 \
|
||||
--interval 5
|
||||
```
|
||||
|
||||
## Supported formats
|
||||
|
||||
Data can be inserted from CSV, TSV, JSON or newline-delimited JSON files.
|
||||
|
|
@ -106,6 +128,7 @@ Options:
|
|||
--pk TEXT Columns to use as the primary key when creating the
|
||||
table
|
||||
--batch-size INTEGER Send rows in batches of this size
|
||||
--interval FLOAT Send batch at least every X seconds
|
||||
-t, --token TEXT API token
|
||||
--silent Don't output progress
|
||||
--help Show this message and exit.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue