INNER CODE UNIT · Rust
build_sql
fcoury/oxide · src/commands/aggregate/mod.rs:67
pub fn build_sql(sp: &SqlParam, pipeline: &Vec<Bson>) -> Result<String, CommandExecutionError> {
let mut stages: Vec<(String, SqlStatement)> = vec![];
for stage in pipeline {
let stage_doc = stage.as_document().unwrap();
let name = stage_doc.keys().next().unwrap();
match name.as_str() {
"$match" => {
// adds the result of the match
match process_match(stage_doc.get_document("$match").unwrap()) {
Ok(sql) => stages.push((name.to_string(), sql)),
Err(err) => return Err(CommandExecutionError::new(err.to_string())),
}
}
"$group" => {
// adds the group stage
match process_group(stage_doc.get_document("$group").unwrap()) {
Ok(sql) => stages.push((name.to_string(), sql)),
Err(err) => return Err(CommandExecutionError::new(err.to_string())),