# CLI

> Every command and flag of the reylo command, with where each is covered.

Every command and flag of `reylo`.

Run it in your project with `npx reylo`. It reads the database your project names, as the type check does.

```terminal
Usage: reylo <command> [flags]

Commands:
  analyze <paths>          Print what Reylo infers for each statement
    --sql <statement>      Read this statement, in place of files
    --url <url>            The database, in place of the project's
    --format <yaml|json>   YAML, the default, or a line of JSON per statement
  generate <generator>     Write each .sql file's module for a language
    --out <file>           Write every module into one file
  migrate <command>        Write, check and run your migrations
  db <command>             Push, reset, wipe or print a development database
  run <sql>                Run SQL as written, recording nothing
    --file <path>          Run a file's SQL too, after the text
    --url <url>            The database, in place of the project's
  play                     Serve the playground on this machine
    --port <n>             The port, 4983 by default
    --no-open              Leave the browser closed

Flags:
  -h, --help               Print this help
  --version                Print the version
```

## Install

Outside a JavaScript project, install the command on its own. It is one binary, with no Node and nothing else to install beside it:

**Homebrew**:

```bash
brew install reylosql/tap/reylo
```

**curl**:

```bash
curl -fsSL https://reylo.dev/install.sh | sh
```

**PowerShell**:

```powershell
irm https://reylo.dev/install.ps1 | iex
```

**Scoop**:

```bash
scoop bucket add reylo https://github.com/reylosql/scoop-bucket
scoop install reylo
```

**Docker**:

```bash
docker run --rm -v "$PWD:/work" ghcr.io/reylosql/reylo migrate status
```

Each installs the latest release, checked against its published checksums. To pin a version in a project, name it in mise's `mise.toml`, which every developer and CI job then installs with `mise install`:

`mise.toml`:

```toml
[tools]
"github:reylosql/reylo" = "0.8.0"
```

The scripts take a version too, as `REYLO_VERSION=0.8.0`, and the image a tag, as `ghcr.io/reylosql/reylo:0.8.0`.

## `reylo analyze`

Prints what Reylo infers for each statement. [Inference engine](https://reylo.dev/inference#how-it-works) covers it.

## `reylo generate`

Writes each `.sql` file's module for a language, as `#[reylo::query]` does for Rust. [Usage with Rust](https://reylo.dev/rust#codegen) covers it.

## `reylo migrate` and `reylo db`

Write, check and run your migrations, and work on a development database. [Migrations](https://reylo.dev/migrate/docs#cli-reylo-migrate) covers each command:

```terminal
Usage: reylo <group> <command> [flags]

Commands:
  migrate init             Start from this database
    --schema <name>        A schema to read (Postgres; public by default)
  migrate new <name>       Write the next migration, from schema.sql or this database
    --drop <names>         Accept what it drops: tables and columns
    --rename <old>=<new>   Say a table or column was renamed
    --blocking             Accept a statement that blocks writes while it reads every row
  migrate dev              Take this database to the migrations, and lock them
  migrate deploy           Run what the lock lists, with no shadow database
    --dry-run              Try it on a shadow database, running nothing here
  migrate status           Check that this database and the files are in step
  migrate lock             Write the lock from this database's history
  migrate history push     Record the migrations this database's schema has
  migrate history pull     Write the migrations this database ran into files
  db push                  Take this database to schema.sql, unrecorded
    --drop <names>         Accept what it drops: tables and columns
    --rename <old>=<new>   Say a table or column was renamed
    --force                Accept everything it drops
    --watch                Push again on each save
  db reset                 Rebuild this database from the migrations
  db wipe                  Delete every row, keeping the schema
  db introspect            Print this database's schema as SQL
    --schema <name>        A schema to read (Postgres; public by default)

Flags:
  --url <url>              The database, in place of direct_url
  --json                   Print the result as one JSON object
  -h, --help               Print this help
```

## `reylo run`

Runs SQL on the database as written, outside any migration's history.

It takes statements as text and files with `--file`, and runs the text first, then each file, each in the order given:

```terminal
$ reylo run 'alter table users add column bio text'
✓ alter table users add column bio text
```

On a SQLite file that isn't there, it refuses rather than make an empty database.

## `reylo play`

Serves the playground on this machine.

The page is a query editor whose Params, Returns and errors are Reylo's analysis of the query against your project's database, at every keystroke. Nothing is run. It opens in your browser, or stays closed with `--no-open`, for a script or an agent, which reads the same analysis as JSON:

```text
http://127.0.0.1:4983/?q=<sql>         the page, with a query in it
GET  /api/analyze?q=<sql>               a query's Params, Returns and diagnostics
POST /api/analyze  {"sql": "<sql>"}     the same
GET  /api/schema                        the tables, their columns, functions and types
```

## Examples

```sh
# the playground, for an agent: no browser
npx reylo play --no-open
```
