fn convert_item_to_csv_line()

in src/data.rs [1281:1321]


fn convert_item_to_csv_line(
    item: &HashMap<String, AttributeValue>,
    ts: &app::TableSchema,
    attributes_to_append: &Option<Vec<String>>,
    keys_only: bool,
) -> String {
    let mut line = String::new();

    // push pk value to the line
    let pk_attrval: &AttributeValue = item
        .iter()
        .find(|x| x.0 == &ts.pk.name)
        .expect("pk should exist")
        .1;
    // NOTE: Another possible implementation to generate string from attrval would be: `&attrval_to_cell_print(Some(pk_attrval.to_owned())))`.
    //       However, `attrval_to_cell_print` doesn't surround String value with double-quotes (""), so I prefer using attrval_to_jsonval here.
    line.push_str(&attrval_to_jsonval(pk_attrval).to_string());

    // push sk value to the line, if needed.
    if let Some(sk) = &ts.sk {
        let sk_attrval: &AttributeValue = item
            .iter()
            .find(|x| x.0 == &sk.name)
            .expect("sk should exist in an item")
            .1;
        line.push(',');
        line.push_str(&attrval_to_jsonval(sk_attrval).to_string());
    }

    if keys_only {
    } else if let Some(attrs) = attributes_to_append {
        for attr /* String */ in attrs {
            let attrval: &AttributeValue = item.iter().find(|x| x.0 == attr).expect("Specified attribute not found in the item.").1;
            line.push(',');
            // NOTE: If special handling for complex data type is needed: `if let Some(_) = attrval.m {...`
            line.push_str(&attrval_to_jsonval(attrval).to_string());
        }
    }

    line
}