njord-rs/njord

Fix utility fuctions to reuse code from select.rs and update.rs

Closed this issue · 2 comments

We have a lot of duplicate code that could be used with one or more functions instead.

Example that we use in both:

let order_by_str = if let Some(order_by) = &self.order_by {
            let order_by_str: Vec<String> = order_by
                .iter()
                .map(|(columns, order)| format!("{} {}", columns.join(", "), order))
                .collect();
            if !order_by_str.is_empty() {
                format!("ORDER BY {}", order_by_str.join(", "))
            } else {
                String::new()
            }
        } else {
            String::new()
        };

Implemented.