Prql (prql_rs v0.1.0)

View Source

PRQL compiler for Elixir, powered by Rust's prqlc.

Summary

Functions

Compiles a PRQL query to SQL.

Same as compile/2 but raises an exception if compilation fails.

Types

dialect()

@type dialect() :: Prql.Options.dialect()

display_option()

@type display_option() :: Prql.Options.display_option()

option()

@type option() :: Prql.Options.option()

options()

@type options() :: Prql.Options.options()

Functions

compile(prql_query, options \\ [])

@spec compile(String.t(), options()) :: {:ok, String.t()} | {:error, String.t()}

Compiles a PRQL query to SQL.

Options

  • :format - Whether to format the SQL output (default: false)
  • :target - The SQL dialect to target (optional, no default)
  • :signature_comment - Whether to include the PRQL signature comment (default: false)
  • :color - Whether to enable color in the output (default: false)
  • :display - Display options for the output (:plain or :ansi_color, default: :plain)

Examples

iex> Prql.compile("from employees | select {name, age}")
{:ok, "SELECT name, age FROM employees"}

iex> Prql.compile("from employees | select {name, age}", target: :postgres)
{:ok, "SELECT name, age FROM employees"}

Returns {:ok, sql_string} on success, or {:error, reason} on failure.

compile!(prql_query, options \\ [])

@spec compile!(String.t(), options()) :: String.t() | no_return()

Same as compile/2 but raises an exception if compilation fails.

Options

See compile/2 for available options.

Examples

iex> Prql.compile!("from employees | select {name, age}")
"SELECT name, age FROM employees"

iex> Prql.compile!("from employees | select {name, age}", target: :postgres)
"SELECT name, age FROM employees"

iex> Prql.compile!("invalid prql")
** (RuntimeError) PRQL compilation failed: ...