> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Lines

> Use database queries and live updates through head, tail and wc.

Mirage connects `head`, `tail` and `wc -l` to your backend's queries and live
updates. A database can fetch a few rows or count them without exporting the
whole table. A chat service can send new messages to `tail -f`.

## Example: inspect a table

With PostgreSQL mounted at `/db/`:

```bash theme={null}
head -n 20 /db/public/tables/tickets/rows.jsonl
wc -l /db/public/tables/tickets/rows.jsonl
```

Mirage uses `LIMIT` to fetch the first 20 rows and `COUNT(*)` to count them.
Adding a byte count with `wc -lc` requires reading the file instead.

## Connect your own backend

Override the methods your service supports:

| Method | Commands using your method | Uses normal reads instead |
| - | - | - |
| `first_lines` | `head` or `head -n N` for the first N lines; default 10. | Byte counts (`-c`), NUL separators (`-z`), or all but the last N lines (`-n -N`). |
| `last_lines` | `tail` or `tail -n N` for the last N lines; default 10. | Byte counts (`-c`) or starting at line N (`-n +N`). |
| `line_count` | `wc -l` for the newline count. | Plain `wc`, or adding word, byte, character or line-length counts (`-w`, `-c`, `-m`, `-L`). |
| `follow` | `tail -f` on one file, optionally with `-n N`. | Following by name (`-F`, `--follow=name`), byte counts (`-c`), or starting at line N (`-n +N`). |

The TypeScript names are `firstLines`, `lastLines`, `lineCount` and `follow`.
For `first_lines` and `last_lines`, N must be positive. Standard input is
always read normally.

For `follow`, first yield the last N lines, then new lines as they arrive.
Keep the stream open until the caller closes it; ending it makes `tail -f`
exit with an error.

Return the same content and order as a normal file read. Return `None` in
Python or `null` in TypeScript when a method cannot answer; Mirage reads the
file normally.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.