translate_placeholders

Function translate_placeholders 

Source
pub fn translate_placeholders(
    sql: &str,
    target: PlaceholderStyle,
    enabled: bool,
) -> Cow<'_, str>
Expand description

Translate placeholders between Postgres-style $N and SQLite-style ?N.

Warning: translation skips quoted strings, comments, and dollar-quoted blocks via a lightweight state machine; it may still miss edge cases in complex SQL. For dialect-specific SQL (e.g., PL/pgSQL bodies), prefer backend-specific SQL instead of relying on translation:

let query = match conn {
    MiddlewarePoolConnection::Postgres { .. } => r#"$function$
BEGIN
    RETURN ($1 ~ $q$[\t\r\n\v\\]$q$);
END;
$function$"#,
    MiddlewarePoolConnection::Sqlite { .. } | MiddlewarePoolConnection::Turso { .. } => {
        include_str!("../sql/functions/sqlite/03_sp_get_scores.sql")
    }
};

Returns a borrowed Cow when no changes are needed.