| sidebar_position | 2 |
|---|---|
| title | CLI Reference |
| description | Complete sqlgg command-line reference |
import CliOptions from './_cli-options.md';
sqlgg <options> <file.sql> [<file2.sql> ...]
Files are read as one stream: DDL builds up the schema, queries become generated functions. Each option applies to the files after it, which is how the schema goes in without generating code:
sqlgg -gen none ddl.sql -gen caml dml.sqlWithout -params the mode follows -dialect: MySQL, TiDB and SQLite use unnamed (?), PostgreSQL uses postgresql ($1, $2, ...). oracle produces :param, named keeps @param as is, none fails on queries with autogenerated parameters.
Prints one JSON document with what the built-in generators receive, for a generator written in another language: every query with its function name, result columns, parameters and statement kind; an SQL template that keeps parameters as Bind nodes and choices, IN lists and dynamic selects as nested nodes; the table catalog; the dialect and the -params mode. -json-schema prints its JSON Schema.
sqlgg ir [-schema <file>] [-plain-sql] [<file.sql> ...]
sqlgg ir -json-schema
Prints one JSON document with the parsed AST of every statement, for tooling that wants the SQL itself rather than generated bindings. Input comes from the files, or stdin when there are none. Unlike -gen json it does not stop at the first bad statement: a statement that fails to parse or type-check becomes an Invalid node with its diagnostics, the rest of the document is still produced, and the exit code is 1. Unreadable input or a schema that does not compile exits with 2.
With -schema <file> statements are also checked against that schema and carry the typed result; -plain-sql rejects sqlgg extensions; -json-schema prints the JSON Schema of the document. ir is a separate command with its own options, so the code generation options above do not apply to it.
sqlgg migrations generate --dialect <dialect> --lang ocaml --schema <file> --migrations <file> --module <name> [--manual <file>] [--now <YYYYMMDDHHMMSS>]
sqlgg migrations dune <the same options> --generated <file.ml>
generate records the changes of the schema file as new migrations in the migrations file and prints a module for the migration runtime shipped with sqlgg; dune prints Dune rules that do this on every build. See Migrations. Like ir, it is a separate command with its own options; --help lists them. Usage errors exit with 2.
Drops the version and timestamp from the header, so the generated file only changes when the SQL does. Use it with dune promote rules (see Getting Started).