# sqlite.query.run

Run SQL on the project's built-in SQLite database (connection default; no credential)

# sqlite.query.run

```
sqlite.query.run [--query TEXT] [--param KEY=EXPR…] [--write] [--limit N] → query
```

Run SQL on the project's built-in SQLite database (connection `default`; no credential). SQL in the body after `--` (or `--query`); values bind from `--param`: `1=…` binds `?1`, `name=…` binds `:name` — a literal is text, a whole `{{ expr }}` keeps its type. The database is opened read-only unless `--write` is set, so an INSERT/UPDATE/DELETE/CREATE without it is refused. Adds `query: { rows, columns, row_count, truncated }` (`input.query.rows[0].name`), plus `rows_affected` with `--write`; `INSERT … RETURNING id` answers the rows it wrote. `--limit` caps the rows (default 200, at most 5000). Standard SQLite DDL and constraints work (unlike Sekejap).

## Flags

- `--query`: The SQLite statement (or the body after `--`). A literal or {{ expr }}.
- `--param`: One bind value, repeated: `1=…` binds ?1, `name=…` binds :name (or @name, $name). A literal is text; a whole {{ expr }} keeps its JSON type, so a number stays a number.
- `--write`: Let the statement change data. Without it the query runs read-only and a write is refused. Literal; never {{ }}.
- `--limit`: Rows answered (default 200, at most 5000); `truncated` says more matched.

## Examples

### Read with a bound value

```
| sqlite.query.run --param "1={{ $trigger.body.email }}" -- "SELECT id, name FROM users WHERE email = ?1"
```

It answers:

```json
{
  "query": {
    "rows": [
      {
        "id": 1,
        "name": "Ana"
      }
    ],
    "columns": [
      "id",
      "name"
    ],
    "row_count": 1,
    "truncated": false
  }
}
```

### Insert from a form

```
| sqlite.query.run --write --param "email={{ $trigger.body.email }}" --param "name={{ $trigger.body.name }}" -- "INSERT INTO users (email, name) VALUES (:email, :name) RETURNING id"
```

It answers:

```json
{
  "query": {
    "rows": [
      {
        "id": 2
      }
    ],
    "columns": [
      "id"
    ],
    "row_count": 1,
    "truncated": false,
    "rows_affected": 1
  }
}
```

### Create a table

```
| sqlite.query.run --write -- "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, email TEXT UNIQUE NOT NULL, name TEXT, created_at TEXT DEFAULT CURRENT_TIMESTAMP)"
```

It answers:

```json
{
  "query": {
    "rows": [],
    "columns": [],
    "row_count": 0,
    "truncated": false,
    "rows_affected": 0
  }
}
```

## Used in

- [Sign in with Google (OAuth login)](/examples/oauth-login-google.md)
