Function prql_compiler::compile

source ·
pub fn compile(prql: &str, options: &Options) -> Result<String, ErrorMessages>
Expand description

Compile a PRQL string into a SQL string.

This is a wrapper for:

  • prql_to_pl — Build PL AST from a PRQL string
  • pl_to_rq — Finds variable references, validates functions calls, determines frames and converts PL to RQ.
  • rq_to_sql — Convert RQ AST into an SQL string.

§Example

Use the prql compiler to convert a PRQL string to SQLite dialect

use prqlc::{compile, Options, Target, sql::Dialect};

let prql = "from employees | select {name,age}";
let opts = Options {
    format: false,
    target: Target::Sql(Some(Dialect::SQLite)),
    signature_comment: false,
    color: false,
};
let sql = compile(&prql, &opts).unwrap();
println!("PRQL: {}\nSQLite: {}", prql, &sql);
assert_eq!("SELECT name, age FROM employees", sql)

See sql::Options and sql::Dialect for options and supported SQL dialects.