expression
rusqlite: open a disposable SQLite database
A driver translates Rust calls into database operations. rusqlite wraps SQLite, an embedded engine, so no database server is needed. A private in-memory connection is a convenient practice database. Its contents vanish when the connection closes. Run in the accompanying Cargo project. Expected stdout (not executed): answer: 5 Common mistake: Expecting in-memory data to survive closing the connection.
Formal Syntax & Structure
rust syntaxrust
Connection::open_in_memory()?Working Example
Example Snippetrust
fn main() -> Result<(), Box<dyn std::error::Error>> { let db = rusqlite::Connection::open_in_memory()?; let n: i64 = db.query_row("SELECT 2 + 3", [], |row| row.get(0))?; println!("answer: {n}"); Ok(())}