MCPcopy Create free account
hub / github.com/PRQL/prql / compile_path

Function compile_path

prqlc/prqlc/src/cli/watch.rs:96–136  ·  view source on GitHub ↗
(path: &Path, opt: &prqlc::Options)

Source from the content-addressed store, hash-verified

94}
95
96fn compile_path(path: &Path, opt: &prqlc::Options) -> Result<()> {
97 // filter to only .prql files
98 if path.extension() != Some(OsStr::new("prql")) {
99 return Ok(());
100 }
101
102 let sql_path = path.with_extension("sql");
103 let prql_path = path;
104
105 // read
106 let Some(prql_string) = fs::read_to_string(prql_path).ok() else {
107 // file may not exist, because this may have been a delete event
108 return Ok(());
109 };
110 if prql_string.is_empty() {
111 return Ok(());
112 }
113
114 // pre-process Jinja
115 let (prql_string, jinja_context) = jinja::pre_process(&prql_string)?;
116
117 // compile
118 println!("Compiling {}", prql_path.display());
119 let sql_string = match prqlc::compile(&prql_string, opt) {
120 Ok(sql_string) => sql_string,
121 Err(errs) => {
122 for err in errs.inner {
123 println!("{err}");
124 }
125 return Err(anyhow!("failed to compile"));
126 }
127 };
128
129 // post-process Jinja
130 let sql_string = jinja::post_process(&sql_string, jinja_context);
131
132 // write
133 fs::write(sql_path, sql_string)?;
134
135 Ok(())
136}

Callers 2

find_and_compileFunction · 0.85
watch_and_compileFunction · 0.85

Calls 4

pre_processFunction · 0.85
post_processFunction · 0.85
is_emptyMethod · 0.80
compileFunction · 0.70

Tested by

no test coverage detected