mirror of
https://github.com/isar/rusqlite.git
synced 2025-11-20 23:09:16 +08:00
Remove unwrap from examples
This commit is contained in:
16
README.md
16
README.md
@@ -11,7 +11,7 @@ an interface similar to [rust-postgres](https://github.com/sfackler/rust-postgre
|
||||
|
||||
```rust
|
||||
use rusqlite::types::ToSql;
|
||||
use rusqlite::{Connection, NO_PARAMS};
|
||||
use rusqlite::{Connection, Result, NO_PARAMS};
|
||||
use time::Timespec;
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -22,8 +22,8 @@ struct Person {
|
||||
data: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let conn = Connection::open_in_memory().unwrap();
|
||||
fn main() -> Result<()> {
|
||||
let conn = Connection::open_in_memory()?;
|
||||
|
||||
conn.execute(
|
||||
"CREATE TABLE person (
|
||||
@@ -33,7 +33,7 @@ fn main() {
|
||||
data BLOB
|
||||
)",
|
||||
NO_PARAMS,
|
||||
).unwrap();
|
||||
)?;
|
||||
let me = Person {
|
||||
id: 0,
|
||||
name: "Steven".to_string(),
|
||||
@@ -44,22 +44,22 @@ fn main() {
|
||||
"INSERT INTO person (name, time_created, data)
|
||||
VALUES (?1, ?2, ?3)",
|
||||
&[&me.name as &ToSql, &me.time_created, &me.data],
|
||||
).unwrap();
|
||||
)?;
|
||||
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT id, name, time_created, data FROM person")
|
||||
.unwrap();
|
||||
.prepare("SELECT id, name, time_created, data FROM person")?;
|
||||
let person_iter = stmt
|
||||
.query_map(NO_PARAMS, |row| Person {
|
||||
id: row.get(0),
|
||||
name: row.get(1),
|
||||
time_created: row.get(2),
|
||||
data: row.get(3),
|
||||
}).unwrap();
|
||||
})?;
|
||||
|
||||
for person in person_iter {
|
||||
println!("Found person {:?}", person.unwrap());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user