sql_support

Function each_chunk

source
pub fn each_chunk<'a, T, E, F>(items: &'a [T], do_chunk: F) -> Result<(), E>
where T: 'a, F: FnMut(&'a [T], usize) -> Result<(), E>,
Expand description

Helper for the case where you have a &[impl ToSql] of arbitrary length, but need one of no more than the connection’s MAX_VARIABLE_NUMBER (rather, default_max_variable_number()). This is useful when performing batched updates.

The do_chunk callback is called with a slice of no more than default_max_variable_number() items as it’s first argument, and the offset from the start as it’s second.

See each_chunk_mapped for the case where T doesn’t implement ToSql, but can be converted to something that does.