The loco-generate-via-sql binary is a filter: it reads SQL
from stdin and writes cargo loco generate scaffold commands to stdout.
loco-generate-via-sql [OPTIONS]
SQL dialect for parsing the input. Default: postgres.
| Value | Picks parser |
|---|---|
postgres |
sqlparser::dialect::PostgreSqlDialect |
mysql |
sqlparser::dialect::MySqlDialect |
sqlite |
sqlparser::dialect::SQLiteDialect |
generic |
sqlparser::dialect::GenericDialect |
The dialect affects which keywords sqlparser recognizes — for example,
UNSIGNED and TINYINT(1) need the MySQL dialect; BYTEA, JSONB, and
SERIAL need Postgres. generic is a permissive fallback.
Scaffold template flag appended to each command. Default: htmx.
| Value | Appended flag |
|---|---|
htmx |
--htmx |
html |
--html |
api |
--api |
none |
(nothing — useful when piping into another tool) |
Print help. Lists every option with its default.
Print version (matches Cargo.toml version = "...").
- stdin: raw SQL text. Multiple statements OK; only
CREATE TABLEis processed; other statements (CREATE INDEX,ALTER TABLE, comments,BEGIN/COMMIT) are silently skipped. - stdout: generated commands. One per
CREATE TABLE, in source order, separated by a blank line. The output ends with\n. Empty input → empty output. - stderr: warnings prefixed
warn:(unknown types, generated columns) and errors prefixederror:(parse failure, I/O failure).
| Code | Meaning |
|---|---|
| 0 | Success — commands written to stdout. (Warnings on stderr don't change this.) |
| 1 | SQL parse error — sqlparser couldn't read the input. |
| 2 | I/O error — failed to read stdin or write stdout. |
Print commands to terminal:
loco-generate-via-sql < schema.sqlSave to a runnable script:
loco-generate-via-sql < schema.sql > setup.sh
sh setup.shRun scaffolds inline:
loco-generate-via-sql < schema.sql | sh -e-e makes the shell exit if any individual scaffold fails, so you don't
silently skip past errors.
Compare output to an expected snapshot:
loco-generate-via-sql < schema.sql | diff - expected.txtRun with a non-default dialect and kind:
loco-generate-via-sql -d mysql -k api < schema.sqlFilter the output before running — e.g., only run scaffolds for tables matching a pattern:
loco-generate-via-sql < schema.sql \
| grep '^cargo loco generate scaffold post' \
| sh -eSuppress warnings:
loco-generate-via-sql < schema.sql 2>/dev/nullCapture warnings only:
loco-generate-via-sql < schema.sql 2>warnings.log >/dev/null- Run
--helpfor the canonical option list with defaults — never out of date. - Use
--kind nonewhen piping into a tool that adds its own flags. - Source order matters — see the README. If your schema dump puts FK targets after referencing tables, reorder before piping.
- Pre-flight with
--quiet-style stdout: redirect stdout to/dev/nulland watch stderr to see whether the input has any warnings before generating real output.