1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
mod ast;
#[cfg(feature = "cli")]
mod cli;
mod error;
mod parser;
mod semantic;
mod sql;
mod utils;
pub use anyhow::Result;
pub use ast::display;
#[cfg(feature = "cli")]
pub use cli::Cli;
pub use error::{format_error, SourceLocation};
pub use parser::parse;
pub use semantic::*;
pub use sql::{resolve_and_translate, translate};
pub fn compile(prql: &str) -> Result<String> {
parse(prql).and_then(resolve_and_translate)
}
pub fn format(prql: &str) -> Result<String> {
parse(prql).map(display)
}
pub fn to_json(prql: &str) -> Result<String> {
Ok(serde_json::to_string(&parse(prql)?)?)
}
pub mod internals {
pub use crate::ast::ast_fold::AstFold;
pub use crate::ast::Node;
pub use crate::utils::{IntoOnly, Only};
}
#[cfg(test)]
mod test {
use super::*;
use crate::to_json;
#[test]
fn test_to_json() -> Result<()> {
let json = to_json("from employees | take 10")?;
assert_eq!(json.chars().next().unwrap(), '{');
assert_eq!(json.chars().nth(json.len() - 1).unwrap(), '}');
Ok(())
}
}