# `Lotus.SQL.Validator`
[🔗](https://github.com/typhoonworks/lotus/blob/v0.16.6/lib/lotus/sql/validator.ex#L1)

Validates SQL syntax by preparing it against the database without executing.

Uses EXPLAIN to parse the query server-side. Before validation, `{{var}}`
placeholders are replaced with NULL and `[[...]]` optional brackets are
stripped so the raw template can be checked.

# `validate`

```elixir
@spec validate(String.t(), String.t()) :: :ok | {:error, String.t()}
```

Validates SQL syntax against the given data source.

Neutralizes Lotus template syntax (`{{var}}` → `NULL`, `[[...]]` → inner
content) and runs EXPLAIN to check whether the database can parse the
statement.

Returns `:ok` if the SQL is valid, or `{:error, reason}` with the
database error message if it is not.

## Examples

    iex> Lotus.SQL.Validator.validate("SELECT 1", "postgres")
    :ok

    iex> Lotus.SQL.Validator.validate("NOT VALID SQL", "postgres")
    {:error, "SQL syntax error: ..."}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
