Last active
April 1, 2024 12:57
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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