Expand description
Compiler for PRQL language. Targets SQL and exposes PL and RQ abstract syntax trees.
You probably want to start with compile wrapper function.
For more granular access, refer to this diagram:
PRQL
(parse) │ ▲
prql_to_pl │ │ pl_to_prql
│ │
▼ │ json::from_pl
────────►
PL AST PL JSON
◄────────
│ json::to_pl
│
(resolve) │
pl_to_rq │
│
│
▼ json::from_rq
────────►
RQ AST RQ JSON
◄────────
│ json::to_rq
│
rq_to_sql │
▼
SQL
§Common use-cases
-
Compile PRQL queries to SQL at run time.
let sql = prqlc::compile( "from albums | select {title, artist_id}", &prqlc::Options::default().no_format() )?; assert_eq!(&sql[..35], "SELECT title, artist_id FROM albums");
-
Compile PRQL queries to SQL at build time.
For inline strings, use the
prql-compiler-macros
crate; for example:ⓘlet sql: &str = prql_to_sql!("from albums | select {title, artist_id}");
For compiling whole files (
.prql
to.sql
), callprqlc
frombuild.rs
. See this example project. -
Compile, format & debug PRQL from command line.
$ cargo install --locked prqlc $ prqlc compile query.prql
§Feature flags
The following feature flags are available:
serde_yaml
: adapts theSerialize
implementation forprqlc_ast::expr::ExprKind::Literal
toserde_yaml
, which doesn’t support the serialization of nested enums
§Large binary sizes
For Linux users, the binary size contributed by this crate will probably be
quite large (>20MB) by default. That is because it includes a lot of
debuginfo symbols from our parser. They can be removed by adding the
following to Cargo.toml
, reducing the contribution to around 7MB:
[profile.release.package.prqlc]
strip = "debuginfo"
Re-exports§
pub use prqlc_ast as ast;
Modules§
- Intermediate Representations of Abstract Syntax Tree
- JSON serialization and deserialization functions
- Semantic resolver (name resolution, type checking and lowering to RQ)
- Backend for translating RQ into SQL
Structs§
- Compilation options for SQL backend of the compiler.
- Location within the source file. Tuples contain:
- All paths are relative to the project root.
Enums§
- Compile message kind. Currently only Error is implemented.
Statics§
Traits§
Functions§
- Compile a PRQL string into a SQL string.
- Generate PRQL code from PL AST
- Perform semantic analysis and convert PL to RQ.
- Perform semantic analysis and convert PL to RQ.
- Parse PRQL into a PL AST
- Parse PRQL into a PL AST
- Generate SQL from RQ.