CLI
Every command and flag of reylo.
In a JavaScript project, run it with npx reylo. Elsewhere, install the binary on its own:
brew install reylosql/tap/reylocurl -fsSL https://reylo.dev/install.sh | shirm https://reylo.dev/install.ps1 | iexscoop bucket add reylo https://github.com/reylosql/scoop-bucket
scoop install reylodocker run --rm -v "$PWD:/work" ghcr.io/reylosql/reylo migrate statusTo pin a version, name it in mise's mise.toml. Every developer and CI job then installs it with mise install:
[tools]
reylo = "0.8.3"The scripts take REYLO_VERSION=0.8.3. The image takes a tag, as ghcr.io/reylosql/reylo:0.8.3.
Each command reads the database your project names, as the type check does:
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 <format> json, the default, yaml or typescript
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 versionreylo analyze
Prints what Reylo infers for each statement. Given this query:
-- One user, by id.
select id, email, bio from users where id = :idAnalyze it:
$ reylo analyze queries/get_user.sql
{
"$schema": "https://reylo.dev/typedefs/preview.json",
"dialect": { "name": "postgres", "version": "18.6" },
"sql": "-- One user, by id.\nselect id, email, bio from users where id = $1\n",
"kind": "select",
"comment": "One user, by id.",
"params": [
{ "name": "id", "type": { "kind": "integer", "bits": 64, "label": "int8" } }
],
"result": {
"kind": "table",
"cardinality": "at_most_one",
"columns": [
{
"name": "id",
"type": { "kind": "integer", "bits": 64, "label": "int8" }
},
{
"name": "email",
"type": {
"kind": "text",
"code_points": [[1, 1114111]],
"size": { "max": 255 },
"label": "varchar"
}
},
{
"name": "bio",
"type": {
"kind": "text",
"code_points": [[1, 1114111]],
"label": "text"
},
"nullable": true,
"comment": "Shown on the profile page"
}
]
},
"capabilities": { "tables": { "public.users": "read" } },
"diagnostics": []
}Each field of the result:
| Field | What it holds |
|---|---|
file | The file the statement came from, when the command reads several |
$schema | The format's version, as the URL of its JSON Schema |
dialect | The database, and its server's version |
sql | The statement as the database runs it, with the database's own placeholders |
kind | What the statement does: select, insert, update, delete, merge or other |
comment | The comment before the statement |
params | Each parameter's name and type |
result | Each column's name and type, and the cardinality: how many rows the statement returns |
capabilities | The tables the statement reads or writes |
diagnostics | What the database reports where it refuses the statement |
All type information is presented using the Reylo Type Defs specification.
It takes files, directories and globs, or one statement with --sql:
reylo analyze queries/get_user.sql
reylo analyze queries
reylo analyze 'queries/**/*.sql'
reylo analyze --sql 'select count(*) as n from users'Piped, each statement prints as one line of JSON:
$ reylo analyze --sql 'select count(*) as n from users' | cat
{"$schema":"https://reylo.dev/typedefs/preview.json","dialect":{"name":"postgres","version":"18.6"},"sql":"select count(*) as n from users","kind":"select","params":[],"result":{"kind":"table","cardinality":"one","columns":[{"name":"n","type":{"kind":"integer","bits":64,"label":"int8"}}]},"capabilities":{"tables":{"public.users":"read"}},"diagnostics":[]}With --format typescript, it prints the parameters and what .run() resolves to:
$ reylo analyze queries/get_user.sql --format typescript
type Params = { id: number | bigint | string };
type Returns = {
id: bigint;
email: string;
/** Shown on the profile page */
bio: string | null;
} | null;The --format yaml flag prints a YAML document per statement.
A statement the database refuses prints its error on stderr, and the command exits with 1:
$ reylo analyze queries/broken.sql > /dev/null
queries/broken.sql:4:7: column u.emial does not exist (42703)
where u.emial = :email
^^^^^^^reylo migrate
Write, check and run your migrations:
Usage: reylo migrate <command> [flags]
Commands:
init Start from this database
--schema <name> A schema to read; repeat for more (Postgres; all by default)
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
dev Apply all unapplied migrations and regenerate the lockfile
deploy Run what the lock lists, with no shadow database
--dry-run Try it on a shadow database, running nothing here
status Check that this database and the files are in step
lock Write the lock from this database's history
history push Record the migrations this database's schema has
history pull Write the migrations this database ran into files
Flags:
--url <url> The database, in place of direct_url
--json Print the result as one JSON object
-h, --help Print this helpinit
Starts your migrations from an existing database:
reylo migrate init
reylo migrate init --schema public --schema billingnew
Writes the next migration, from your change to schema.sql:
reylo migrate new add_bio
reylo migrate new add_bio --drop users.bio
reylo migrate new add_bio --rename users.name=full_name
reylo migrate new add_bio --blockingdev
Applies all unapplied migrations to your development database and regenerates the lockfile:
reylo migrate devdeploy
Runs the lock's pending migrations, with no shadow database:
reylo migrate deploy
reylo migrate deploy --dry-runstatus
Checks that a database and your files are in step, changing nothing:
reylo migrate status
reylo migrate status --url $PROD_URLlock
Writes the lock from your database's history:
reylo migrate lockhistory push
Records your migrations as run on a database that already has their schema:
reylo migrate history push --url $PROD_URLhistory pull
Writes your migration files from a database's history:
reylo migrate history pull --url $PROD_URLreylo db
Push schema.sql to a development database, reset it, wipe it or read its schema:
Usage: reylo db <command> [flags]
Commands:
push Synchronize this database with schema.sql (may be destructive)
--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
reset Rebuild this database from the migrations
wipe Delete every row, keeping the schema
introspect Print this database's schema as SQL
--schema <name> A schema to read; repeat for more (Postgres; all by default)
Flags:
--url <url> The database, in place of direct_url
--json Print the result as one JSON object
-h, --help Print this helppush
Synchronizes your development database with schema.sql, writing no migration:
reylo db push
reylo db push --watch
reylo db push --drop users.bio
reylo db push --forcereset
Rebuilds your development database from your migrations:
reylo db resetwipe
Deletes every row, keeping the schema and the history:
reylo db wipeintrospect
Prints your database's schema as SQL:
reylo db introspect
reylo db introspect --schema appreylo run
Runs SQL on the database as written, outside any migration's history.
It runs the statements you pass as text, then each --file, in order:
$ reylo run 'alter table users add column bio text'
✓ alter table users add column bio textA statement that returns rows prints them, up to 50:
$ reylo run 'select id, email, bio from users'
✓ select id, email, bio from users
id email bio
── ───────────────── ───────────────────────
1 ada@example.com Wrote the first program
2 grace@example.com null
Returned 2 rowsOn 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. It shows Reylo's analysis of the query against your database at every keystroke, without running it. The --no-open flag leaves the browser closed, for a script or an agent. Either reads the same analysis as JSON:
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