# basemodo db

Run SQL against an App's SQLite database (/data/app.db) and print the rows.

```sh
basemodo db [OPTIONS] [SQL]
```

Every App has a SQLite file at /data/app.db on its volume ($BASEMODO_DB in its processes), made by whatever opens it first. Several statements run in order and stop at the first error; what ran before it stays done. The rows are those of the last statement that returned any. A sleeping App is woken to run it. In a terminal the SQL may come on stdin. A control character in a value (an escape, a carriage return) prints as \x1b or \x0d, so a row cannot drive your terminal; --json keeps every value exact.

## Arguments

- `SQL`: The SQL to run; `-` or nothing reads it from stdin.
- `--app <APP>`: The App whose database to use. Default: the one named after the current folder.

Like every command, it also takes the [global options](https://basemodo.com/docs/cli#global-options) `--json` and `--api-url`.

## Examples

Look at the latest rows of a table:

```sh
basemodo db "select * from tasks order by id desc limit 10"
```

List the tables:

```sh
basemodo db "select name from sqlite_master where type = 'table'"
```

Run a file of SQL against another App:

```sh
basemodo db --app lunch-rota < fix.sql
```

## Output

With `--json`, it prints {"columns": [...], "rows": [[...], ...]}, empty for statements that return no rows. SQL that fails is an error with code sql_error and SQLite's message.

## From an agent

Basemodo's [MCP](https://basemodo.com/docs/mcp) serves it as the tool [`db`](https://basemodo.com/docs/mcp/tools/db). It changes things, so an agent's client may ask you before it runs. Its arguments are the command's, named as JSON keys: `sql` (text), `app` (text). It answers what the command prints with `--json`.

## Explained in

- [Data: the disk, SQLite, db, run and Backups](https://basemodo.com/docs/data)
- [Connect your App to Google, Slack or Notion](https://basemodo.com/docs/connections)