expression
SQLite: distinguish two private in-memory connections
Each ordinary private in-memory connection owns a separate database. A table created on one is not automatically visible on another. This is important when switching from one connection to a pool. Some adapters deliberately use shared named in-memory databases, which are a different configuration. Run in the accompanying Cargo project. Expected stdout (not executed): tables in b: 0 Common mistake: Creating a schema on one private connection and assuming it exists on every connection.
Formal Syntax & Structure
rust syntaxrust
Connection::open_in_memory()?Working Example
Example Snippetrust
fn main() -> Result<(), Box<dyn std::error::Error>> { let a = rusqlite::Connection::open_in_memory()?; let b = rusqlite::Connection::open_in_memory()?; a.execute("CREATE TABLE item (id INTEGER)", [])?; let count: i64 = b.query_row("SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name = 'item'", [], |r| r.get(0))?; println!("tables in b: {count}"); Ok(())}