--- title: CLI reference description: Commands for generation, validation, formatting, migrations, and editor integration. --- See [Installation](../installation.md) to install the CLI or run it from a checkout. ## Command overview | Command | Requires dev database | Description | | --- | --- | --- | | `generate ...` | Yes | Generate Go code in `_gen.go` files beside the source files | | `generate --check ...` | Yes | Check that generated code is current; fail if files are stale or missing | | `lint ...` | No | Check syntax, declarations, types, and supported SQL structure | | `lint --online ...` | Yes | Run lint checks and validate queries against the development database | | `fmt ...` | No | Format `.stitchql` source files | | `fmt --check ...` | No | Check formatting without changing files; fail if formatting differs | | `schema generate ` | No | Print the package's expanded schema SQL | | `schema diff --name ` | Yes | Generate an Up-only Goose migration by comparing migration history with the declared schema | | `lsp` | Optional for diagnostics | Start the language server for editor integration over stdio | For database modes and shared flags, see [Configuration](configuration.md). ## Package targets Generation, lint, and formatting accept package directories, Go import paths, and recursive targets ending in `/...`: ```bash stitchql generate ./store ./reports stitchql lint ./... stitchql fmt --check example.com/app/store ``` Every `.stitchql` file directly in each selected package participates. Sources can exist before the package has generated Go files. Existing directory paths take precedence over Go import lookup, and overlapping targets are deduplicated. Recursive discovery skips nested modules, vendor, testdata, hidden and underscore-prefixed directories, and directory symlinks. Select skipped package roots explicitly if needed. A target matching no sources is an error. Individual source files and arbitrary filesystem globs are not accepted. ## Generate and check output ```bash stitchql generate ./store stitchql generate --check ./store ``` Generation validates selected packages before replacing output files. A source `books.stitchql` produces `books_gen.go`. Unchanged files retain their timestamps. The generator refuses to overwrite a symlink or an unmarked handwritten file. Generation describes statements against PostgreSQL and reads catalog metadata; it does not execute authored SELECTs or mutations. Configure an existing schema or isolated analysis through [Configuration](configuration.md). `--check` renders in memory and exits nonzero for stale or missing files. It never updates them. Build the Go package afterward to verify integration with your application: ```bash go build ./... ``` ## Lint ```bash stitchql lint ./store stitchql lint --json ./store stitchql lint --online ./store ``` Offline lint checks syntax, package declarations, fragment composition, Go types, and supported SQL structure. Online lint adds PostgreSQL description and catalog checks. Neither executes authored queries. JSON diagnostics include source ranges and related declaration locations. ## Format ```bash stitchql fmt ./store stitchql fmt --check ./store ``` Formatting preserves SQL meaning, literals, and comments while applying the current canonical layout. The current formatter can compact annotations and spacing differently from the expanded examples in these docs. Formatting is a separate command; generation does not reformat your source. ## Generate schema SQL and migrations ```bash stitchql schema generate ./store > schema.sql stitchql schema diff ./store --name add_book_status --dir ./migrations ``` Schema commands select one package. `schema diff` requires a name containing letters, digits, underscores, or hyphens. Its default output directory is `migrations`, relative to the working directory. It prints the generated path or `No schema changes.`. See [Migrations](migrations.md) for review and replay behavior. ## Language server ```bash stitchql lsp ``` This starts a stdio language server for editor clients, not an interactive shell. See [Editor setup](../integrations/editors.md) for the supported features and local installation.