use super::super::super::quote::{quote_ident, quote_literal};
pub(super) fn key_list(primary_key: &[String]) -> String {
primary_key
.iter()
.map(|key| quote_ident(key))
.collect::<Vec<_>>()
.join(", ")
}
pub(super) fn cursor(primary_key: &[String], last_value: &[String]) -> String {
let values = last_value
.iter()
.map(|value| quote_literal(value))
.collect::<Vec<_>>()
.join(", ");
format!(" AND ({}) > ({values})", key_list(primary_key))
}
pub(super) fn join(table: &str, primary_key: &[String]) -> String {
let table = quote_ident(table);
primary_key
.iter()
.map(|key| {
let key = quote_ident(key);
format!("{table}.{key} = batch.{key}")
})
.collect::<Vec<_>>()
.join(" AND ")
}
pub(super) fn returning(table: &str, primary_key: &[String]) -> String {
let table = quote_ident(table);
primary_key
.iter()
.map(|key| format!("{table}.{}", quote_ident(key)))
.collect::<Vec<_>>()
.join(", ")
}
pub(super) fn cursor_projection(primary_key: &[String]) -> String {
primary_key
.iter()
.map(|key| format!("{}::text", quote_ident(key)))
.collect::<Vec<_>>()
.join(", ")
}