Connect SQLite in a Rust app
For run SQL queries on SQLite database from Rust, we can use the sqlite3 crate:
let connection = sqlite::open(":memory:").unwrap(); connection .execute( " CREATE TABLE users (name TEXT, age INTEGER); INSERT INTO users (name, age) VALUES ('Alice', 42); INSERT INTO users (name, age) VALUES ('Bob', 69); ", ) .unwrap();
connection .iterate("SELECT * FROM users WHERE age > 50", |pairs| { for &(column, value) in pairs.iter() { println!("{} = {}", column, value.unwrap()); } true }) .unwrap();
And more...
ref: https://docs.rs/sqlite3/latest/sqlite3/