How to do raw SQL queries

Execute raw SQL in Rust using the `sql_query` function from the Diesel crate to run custom database commands safely.

Rust does not have a built-in "raw SQL" feature; you must use a database crate like Diesel to execute SQL strings directly. Use the sql_query function to run arbitrary SQL with parameters, then map the results to a struct or tuple.

use diesel::prelude::*;
use diesel::sql_query;

let results = sql_query("SELECT * FROM users WHERE id = ?")
    .bind::<diesel::sql_types::Integer, _>(user_id)
    .load::<(i32, String)>(connection)?;

The sql_query function takes a raw SQL string, bind adds parameters safely, and load retrieves the data into a Rust type.