Elixir NIF wrapper for the sqlparser Rust crate.
Parses SQL into an AST (as a decoded map) and reconstructs SQL from an AST.
Dialects
Pass a dialect atom as the dialect: option. Defaults to :generic.
Limitations
to_sql/2 accepts a dialect: option for API consistency, but the underlying Rust
serializer uses a dialect-agnostic Display implementation. The dialect argument is
validated but does not affect the reconstructed SQL output.
Examples
iex> {:ok, ast} = SqlParserEx.parse("SELECT 1")
iex> is_map(ast) and map_size(ast) > 0
true
Summary
Functions
Returns all supported dialect atoms.
Parses a SQL string and returns the single statement as an AST map.
Parses a SQL string and returns all statements as a list of AST maps.
Reconstructs a SQL string from an AST map returned by parse/2 or parse_many/2.
Types
@type dialect() ::
:generic
| :ansi
| :postgres
| :mysql
| :sqlite
| :mssql
| :bigquery
| :clickhouse
| :duckdb
| :databricks
| :hive
| :redshift
| :snowflake
@type parse_error() :: String.t() | {:unknown_dialect, atom()} | {:encode_error, Jason.EncodeError.t() | String.t()}
@type sql_opt() :: {:dialect, dialect()}
@type sql_string() :: String.t()
Functions
@spec dialects() :: [dialect()]
Returns all supported dialect atoms.
@spec parse(sql_string(), [sql_opt()]) :: {:ok, map()} | {:error, parse_error()}
Parses a SQL string and returns the single statement as an AST map.
Returns {:error, reason} if zero or multiple statements are found.
Use parse_many/2 for multi-statement SQL.
@spec parse_many(sql_string(), [sql_opt()]) :: {:ok, [map()]} | {:error, parse_error()}
Parses a SQL string and returns all statements as a list of AST maps.
@spec to_sql(map(), [sql_opt()]) :: {:ok, sql_string()} | {:error, parse_error()}
Reconstructs a SQL string from an AST map returned by parse/2 or parse_many/2.
Note: the dialect: option is validated but does not affect output. The underlying
Rust serializer uses a dialect-agnostic Display implementation.