Function prql_compiler::compile

source ·
pub fn compile(
    prql: &str,
    options: Option<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 prql_compiler::compile;
use prql_compiler::sql;


let prql = "from employees | select [name,age] ";
let opt = sql::Options {
    format: true,
    dialect: Some(sql::Dialect::SQLite),
    signature_comment: true
};
let sql = compile(&prql, Some(opt)).unwrap();
println!("PRQL: {}\nSQLite: {}", prql, sql);

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