Skip to main content

substitute_context_bind_params

Function substitute_context_bind_params 

Source
pub fn substitute_context_bind_params(
    template: &str,
    context: &HashMap<String, Value>,
    start_index: usize,
    marker_fn: impl Fn(usize) -> String,
) -> (String, Vec<Value>)
Expand description

Replace {key} placeholders with SQL bind-parameter markers, returning the rewritten query and an ordered list of values to bind.

Scans the template left-to-right; each recognised placeholder is replaced with the marker produced by marker_fn(index), and the corresponding value is appended to the returned vector. The same key appearing multiple times produces one bind value per occurrence.

start_index is the 1-based index for the first parameter.

ยงMarker functions

  • PostgreSQL: |i| format!("${i}")
  • MySQL / SQLite: |_| "?".to_string()

Placeholders whose key is not present in context are left unchanged.