-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlibrary.rs
More file actions
29 lines (21 loc) · 772 Bytes
/
library.rs
File metadata and controls
29 lines (21 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use include_sqlite_sql::{include_sql, impl_sql};
use rusqlite::{Result, Connection};
include_sql!("/examples/library.sql");
fn main() -> Result<()> {
let db = Connection::open_in_memory()?;
db.init_library()?;
db.loan_books(&["War and Peace", "Gone With the Wind"], "Sheldon Cooper")?;
db.loan_books(&["The Lord of the Rings", "Master and Commander"], "Leonard Hofstadter")?;
db.get_loaned_books("Sheldon Cooper", |row| {
let book_title : &str = row.get_ref(0)?.as_str()?;
println!("{book_title}");
Ok(())
})?;
println!("---");
db.get_loaned_books("Leonard Hofstadter", |row| {
let book_title : &str = row.get_ref(0)?.as_str()?;
println!("{book_title}");
Ok(())
})?;
Ok(())
}