CLI reference
See Installation to install the CLI or run it from a checkout.
Command overview
| Command | Requires dev database | Description |
|---|---|---|
generate <package>... | Yes | Generate Go code in _gen.go files beside the source files |
generate --check <package>... | Yes | Check that generated code is current; fail if files are stale or missing |
lint <package>... | No | Check syntax, declarations, types, and supported SQL structure |
lint --online <package>... | Yes | Run lint checks and validate queries against the development database |
fmt <package>... | No | Format .stitchql source files |
fmt --check <package>... | No | Check formatting without changing files; fail if formatting differs |
schema generate <package> | No | Print the package's expanded schema SQL |
schema diff <package> --name <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.
Package targets
Generation, lint, and formatting accept package directories, Go import paths, and
recursive targets ending in /...:
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
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.
--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:
go build ./...
Lint
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
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
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 for review and replay behavior.
Language server
stitchql lsp
This starts a stdio language server for editor clients, not an interactive shell. See Editor setup for the supported features and local installation.