Skip to main content

params

Macro params 

Source
macro_rules! params {
    ($($val:expr),* $(,)?) => { ... };
}
Expand description

Create a Params with values of mixed types.

If all of the parameters to a query are of the same type, a simple array can be used to bind them. If you want to pass multiple values, you need to use this macro.

§Syntax

This macro works like an array expression, except the values do not have to be the same type (and is more performant than an array of dyn ToParam).

use sqlite3_ext::{Connection, Result, params};

fn do_thing(conn: &Connection) -> Result<i64> {
    conn.execute(
        "INSERT INTO tbl VALUES (?, ?)",
        params![1024, "one thousand twenty four"],
    )
}

Named parameters are always provided as a tuple, and work with this macro or the normal array syntax.

use sqlite3_ext::{Connection, Result, params};

fn do_thing(conn: &Connection) -> Result<i64> {
    conn.execute(
        "INSERT INTO tbl VALUES (:number, :name)",
        params![(":name", "one thousand twenty four"), (":number", 1024)],
    )
}