Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Example Of Using A Struct With rusqlite

This is a stright copy of the example from the rusqlite docs page ru . It's more complicated than I need right now. Keeping it here for a quick reference regardless.

The main way I'm using the create is without a struct which I've documented here

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

struct Person {
    id: i32,
    name: String,
    data: Option<Vec<u8>>,

fn main() -> Result<()> {
    let conn = Connection::open_in_memory()?;

        "CREATE TABLE person (
            id   INTEGER PRIMARY KEY,
            name TEXT NOT NULL,
            data BLOB
        (), // empty list of parameters.
    let me = Person {
        id: 0,
        name: "Steven".to_string(),
        data: None,
        "INSERT INTO person (name, data) VALUES (?1, ?2)",
        (&me.name, &me.data),

    let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
    let person_iter = stmt.query_map([], |row| {
        Ok(Person {
            id: row.get(0)?,
            name: row.get(1)?,
            data: row.get(2)?,

    for person in person_iter {
        println!("Found person {:?}", person.unwrap());

Footnotes And References