Configuration file
sqlsift check and sqlsift schema look for sqlsift.toml in the current directory and its parents, or use the file given with --config <FILE>. The language server reads it from the workspace root. Command-line options override values from the file. sqlsift init writes a commented starting point for your project.
# Schema
schema = ["db/schema/*.sql"] # schema files (glob patterns supported)
schema_dir = "db/migrations" # all .sql files under this directory, in version order
# Query files
files = ["queries/**/*.sql"] # query files to check when none are given on the command line
ignore = ["queries/archive/**", "**/*.generated.sql"] # query files to skip
dialect = "postgresql" # postgresql, mysql, sqlite; alpha: snowflake, bigquery, redshift, databricks
templating = "jinja" # jinja (dbt models) or none
dbt_catalog = "target/catalog.json" # dbt catalog with the columns of ref() / source() (alpha)
format = "human" # human, json, sarif, github or gitlab
max_warnings = 0 # fail when more than this many warnings are reported
baseline = "sqlsift-baseline.json" # known diagnostics that are not reported
embedded_sql_tags = ["sql", "$queryRaw"] # template literal tags checked in .ts/.js files
embedded_sql_macros = ["query", "query_as", "my_query"] # sqlx macros checked in .rs files
embedded_sql_functions = ["execute", "fetch", "text", "run_sql"] # calls checked in .py files
embedded_sql_go_functions = ["QueryContext", "ExecContext", "RunSQL"] # calls checked in .go files
# Rules
disable = ["E0006"] # rules to turn off (same as `E0006 = "off"` below)
[rules] # per-rule level: "off", "warn" or "error"
E0008 = "warn" # by code...
ambiguous-column = "off" # ...or by name
[categories] # level of every rule in a category
correctness = "error"
Keys
| Key | Type | Default | Description |
|---|---|---|---|
schema | list of paths / globs | [] | Schema files, loaded in order |
schema_dir | path | none | Directory of schema files, loaded recursively in version order (see Schema), skipping rollback migrations |
files | list of paths / globs | [] | Query files to check when none are given on the command line |
ignore | list of globs | [] | Query files to skip. ** matches any number of directories; a pattern matching a directory skips everything below it. --ignore adds to this list |
dialect | string | "postgresql" | postgresql, mysql or sqlite |
templating | string | auto | jinja masks dbt / Jinja templates in query files, none turns that off. When unset, jinja is used if a dbt_project.yml is in the current directory, next to sqlsift.toml or in a directory above the query file. See dbt and Jinja templates |
dbt_catalog | path | auto | dbt catalog.json (from dbt docs generate) with the columns of the models and sources that {{ ref() }} / {{ source() }} name (alpha); schema files are optional with one. When unset, target/catalog.json of the dbt project is used if it exists (unless templating = "none"). --dbt-catalog overrides it. See Columns of models and sources |
format | string | "human" | human, json, sarif, github or gitlab |
max_warnings | integer | none | Fail when more than this many warnings are reported |
baseline | path | none | Baseline file of known diagnostics, hidden by sqlsift check and the language server; --baseline overrides it. See Baseline |
embedded_sql_tags | list of strings | ["sql"] | Tags of the template literals checked as SQL in TypeScript, JavaScript, Vue and Svelte files, matched against the tag expression's last or first identifier (sql matches db.sql, sql.unsafe and sql.type(schema)) (see SQL in TypeScript and JavaScript) |
embedded_sql_macros | list of strings | ["query", "query_as", "query_scalar", "query_unchecked", "query_as_unchecked", "query_scalar_unchecked"] | Names of the macros (query!("..."), query_as!(T, "...")) and sqlx:: functions (sqlx::query("...")) whose SQL is checked in Rust files (see SQL in Rust (sqlx)) |
embedded_sql_functions | list of strings | ["execute", "executemany", "executescript", "exec_driver_sql", "fetch", "fetchrow", "fetchval", "raw", "text"] | Names of the calls (cur.execute("..."), text("...")) whose first argument, a string literal, is checked as SQL in Python files (see SQL in Python) |
embedded_sql_go_functions | list of strings | Query, QueryRow, Exec, Prepare and their Context variants; sqlx's Get, Select, Queryx, QueryRowx, MustExec, NamedExec, NamedQuery, Preparex (and Context variants) and In | Names of the database/sql, sqlx and pgx calls (db.QueryContext(ctx, "...")) whose SQL argument, a string literal, is checked in Go files (see SQL in Go) |
unused_exclude | list of strings | [] | Tables and columns sqlsift unused never reports, as glob patterns of table, schema.table, table.column or schema.table.column |
disable | list of rules | [] | Rules (codes or names) to turn off |
[rules] | table | Level per rule: "off", "warn" or "error" | |
[categories] | table | Level per category: correctness, suspicious, pedantic, style, restriction |
Paths
Relative paths and patterns in the file are resolved against the directory containing sqlsift.toml, so the same file works from any subdirectory.
Validation
Unknown keys produce a warning. Invalid dialect, templating or format values, unknown rules or categories and invalid levels are errors (exit code 2), with a suggestion when the name is close to a valid one.