prqlc
The reference Rust compiler and CLI for PRQL, a modern pipelined language that compiles to SQL.
Repository Health
Technical Analysis
prqlc is the reference implementation of the PRQL compiler, written in Rust. PRQL (Pipelined Relational Query Language) is a modern language for transforming data — a simple, powerful, pipelined replacement for SQL — and prqlc compiles PRQL queries into standard SQL that runs on any SQL database or tool.
prqlc is both a Rust crate you can embed and a single dependency-free CLI binary. As a library it exposes the full compilation pipeline — parsing PRQL into a PL abstract syntax tree, resolving it to an RQ intermediate representation, and generating SQL for a chosen dialect — plus JSON serialization of the intermediate trees. As a CLI it works as a filter (prqlc compile) that reads PRQL and prints SQL, pairing naturally with tools like the DuckDB CLI.
What You Get
- A
compilefunction and granular pipeline APIs (prql_to_pl,pl_to_rq,rq_to_sql) for embedding PRQL compilation - A single dependency-free
prqlcCLI binary withcompile,watch, and formatting subcommands - SQL generation targeting multiple database dialects
- JSON serialization of the PL and RQ intermediate representations for tooling and language bindings
Common Use Cases
- Compiling PRQL queries into SQL as part of a data pipeline or build step
- Embedding PRQL support inside a Rust application or another language via bindings over the crate
- Interactively converting PRQL to SQL on the command line and piping into engines like DuckDB
Under The Hood
Architecture — prqlc lives at prqlc/prqlc within the PRQL Cargo workspace, alongside prqlc-parser and prqlc-macros. The compiler is a staged pipeline documented in lib.rs: PRQL text is parsed into a PL (Pipelined Language) AST via prql_to_pl, resolved and lowered into an RQ (Relational Query) AST via pl_to_rq, then rendered to SQL. Each stage is individually callable, and PL/RQ trees can be serialized to and from JSON, which is how the many language bindings reuse the compiler. The top-level compile wrapper chains these stages for the common case.
Tech Stack — Pure Rust (MSRV 1.81), organized as a Cargo workspace. The CLI is gated behind a cli feature pulling in clap, anyhow, and completion helpers, keeping the default library build dependency-light. A build.rs script supports build-time generation.
Code Quality — The crate carries extensive test coverage — roughly two dozen source files contain unit tests, complemented by integration tests with sample data (e.g. the Chinook dataset) that assert generated SQL. The project is very actively maintained with consistent release cadence and strong community contribution.
API Design — The library API is layered for both simplicity and control: newcomers call a single compile function, while advanced users reach into prql_to_pl, pl_to_rq, and JSON round-tripping. The CLI follows a clean filter model (prqlc compile) that composes with standard Unix tooling.