Skip to main content

generate_where_operator_sql

Function generate_where_operator_sql 

Source
pub fn generate_where_operator_sql(
    operator: &WhereOperator,
    param_index: &mut usize,
    params: &mut HashMap<usize, Value>,
) -> Result<String>
Expand description

Generates SQL from a WHERE operator with parameter binding support

§Parameters

  • operator: The WHERE operator to generate SQL for
  • param_index: Mutable reference to parameter counter (for $1, $2, etc.)
  • params: Mutable map to accumulate parameter values (for later binding)

§Returns

SQL string with parameter placeholders ($1, $2, etc.)

§Examples

// Requires: fraiseql_wire::operators re-exports; Value has no PartialEq so assert_eq on params omitted.
use std::collections::HashMap;
use fraiseql_wire::operators::{Field, Value, WhereOperator, generate_where_operator_sql};
let mut param_index = 0;
let mut params = HashMap::new();
let op = WhereOperator::Eq(Field::JsonbField("name".to_string()), Value::String("John".to_string()));
let sql = generate_where_operator_sql(&op, &mut param_index, &mut params).unwrap();
assert_eq!(sql, "(data->'name')::text = $1");

§Errors

Returns Error::InvalidSchema if operator field validation fails.