PRQL compiler

prql-compiler contains the implementation of PRQL’s compiler, written in Rust.

For more on PRQL, check out the PRQL website or the PRQL repo.

For more usage examples and the library documentation, check out the prql-compiler documentation.

Installation

cargo add prql-compiler

Examples

Compile a PRQL string to a SQLite dialect string.

src/main.rs

  1. #![allow(unused)]
  2. fn main() {
  3. use prql_compiler::{compile, Options, Target, sql::Dialect};
  4. let prql = "from employees | select [name, age]";
  5. let opts = &Options {
  6. format: false,
  7. target: Target::Sql(Some(Dialect::SQLite)),
  8. signature_comment: false,
  9. color: false,
  10. };
  11. let sql = compile(&prql, opts).unwrap();
  12. assert_eq!("SELECT name, age FROM employees", sql);
  13. }

Terminology

Relation): Standard definition of a relation in context of databases:

  • An ordered set of tuples of form (d_0, d_1, d_2, ...).
  • Set of all d_x is called an attribute or a column. It has a name and a type domain D_x.

Frame: descriptor of a relation. Contains list of columns (with names and types). Does not contain data.

Table#Tables_versus_relations): persistently stored relation. Some uses of this term actually mean to say “relation”.