Skip to content

Instantly share code, notes, and snippets.

@dvas0004
Last active April 1, 2024 12:57
Show Gist options
  • Save dvas0004/cad2e3974901f4a2e76651abcc120816 to your computer and use it in GitHub Desktop.
Save dvas0004/cad2e3974901f4a2e76651abcc120816 to your computer and use it in GitHub Desktop.
using the rusqlite vtab in a rust app (https://blog.davidvassallo.me/?p=4083)
fn main() -> Result<(), rusqlite::Error> {
let db = Connection::open_in_memory()?;
let module = rusqlite::vtab::eponymous_only_module::<Test>();
db.create_module::<Test>("test", module, None)?;
// normal rusqlite code from here on out...
println!("Hello, world!");
let mut s = db.prepare("SELECT * FROM test WHERE id=1")?;
let mut rows = s.query([])?;
while let Some(row) = rows.next()? {
let id: i64 = row.get(0)?;
let name: String = row.get(1)?;
println!("id: {}, name: {}", id, name);
}
let mut s = db.prepare("SELECT name FROM test WHERE id > 2")?;
let mut rows = s.query([])?;
while let Some(row) = rows.next()? {
let name: String = row.get(0)?;
println!("name: {}", name);
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment