# History and rows

## Commands

| Command | Input and result |
| --- | --- |
| `legato history` | Prints every history's status and size, and every page's sparkline readings. |
| `legato rows add <dataset> [file] [--request-id id]` | Adds rows from a JSON array of items, or from `{"rows": [...]}`, in a file or on stdin when there is no file. It takes up to 2,000 items and 8 MB of them at a time, in input of up to 32 MB. With `--request-id`, you can run the same command again after a timeout without adding the rows twice. An id is 1–64 letters, digits and `-`. |
| `legato rows list <dataset> [--limit n]` | Prints the newest rows, up to 500. |
| `legato rows delete <dataset> --key k ...` | Deletes the rows with those keys from the current history. Repeat `--key` for each one. |
| `legato rows delete <dataset> --epoch n` | Deletes one history by its number: an earlier history, whole, or the current one's rows. The number is the `epoch` in the answers of `rows add` and `rows list`. |
| `legato rows delete <dataset> --all` | Deletes every row. |

Deleting can't be undone. Give one of `--key`, `--epoch` or `--all`. If you give more than one, `--all` wins, then `--epoch`. Answers and refusals are JSON on stdout. Success exits with status 0, and a refusal with status 1. See [Rows from outside](https://legatobar.com/docs/history-rows.md) for which histories accept rows, how request ids work, and the refusals.

## Examples and success output

These commands assume you have a history named `example-daily` that accepts rows, is keyed by `date`, and keeps the fields `date` and `steps`.

```bash
legato history
printf '%s\n' '[{"date":"2026-11-10","steps":4200}]' | legato rows add example-daily --request-id example-import-1
legato rows list example-daily --limit 10
legato rows delete example-daily --key 2026-11-10
```

The last command deletes the example row. A row that is already past the history's retention is counted in `expired` and isn't added.

| Command | Success output |
| --- | --- |
| `history` | `histories`, `readings` and `totals`, which has `row_bytes` and `disk_bytes`. When History can't be opened, `unavailable` says why. |
| `rows add` | `dataset`, `accepted`, `rejected`, `expired`, `pruned`, `epoch` and `request_id`. |
| `rows list` | `dataset`, `epoch`, `total_count`, `undated_count`, `rows` and `truncated`. Each row has `key`, `row`, `first_seen` and `last_seen`, and `date` and `date_kind` when the row has a date, with `time` when it has one. In a history of samples, each row has `key`, `at` and `row`. |
| `rows delete` | `dataset` and `deleted`, the number of rows removed. |

`rows add` exits with status 0 even when rows were rejected or expired, so check the counts. The `rows delete` in the example prints:

```json
{
  "dataset" : "example-daily",
  "deleted" : 1
}
```
