mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
Update README example
This commit is contained in:
parent
4923d8f8da
commit
317abe6155
17
README.md
17
README.md
@ -10,8 +10,7 @@ Rusqlite is an ergonomic wrapper for using SQLite from Rust. It attempts to expo
|
|||||||
an interface similar to [rust-postgres](https://github.com/sfackler/rust-postgres).
|
an interface similar to [rust-postgres](https://github.com/sfackler/rust-postgres).
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use rusqlite::types::ToSql;
|
use rusqlite::{params, Connection, Result};
|
||||||
use rusqlite::{Connection, Result, NO_PARAMS};
|
|
||||||
use time::Timespec;
|
use time::Timespec;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -32,7 +31,7 @@ fn main() -> Result<()> {
|
|||||||
time_created TEXT NOT NULL,
|
time_created TEXT NOT NULL,
|
||||||
data BLOB
|
data BLOB
|
||||||
)",
|
)",
|
||||||
NO_PARAMS,
|
params![],
|
||||||
)?;
|
)?;
|
||||||
let me = Person {
|
let me = Person {
|
||||||
id: 0,
|
id: 0,
|
||||||
@ -43,18 +42,18 @@ fn main() -> Result<()> {
|
|||||||
conn.execute(
|
conn.execute(
|
||||||
"INSERT INTO person (name, time_created, data)
|
"INSERT INTO person (name, time_created, data)
|
||||||
VALUES (?1, ?2, ?3)",
|
VALUES (?1, ?2, ?3)",
|
||||||
&[&me.name as &ToSql, &me.time_created, &me.data],
|
params![me.name, me.time_created, me.data],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let mut stmt = conn
|
let mut stmt = conn.prepare("SELECT id, name, time_created, data FROM person")?;
|
||||||
.prepare("SELECT id, name, time_created, data FROM person")?;
|
let person_iter = stmt.query_map(params![], |row| {
|
||||||
let person_iter = stmt
|
Ok(Person {
|
||||||
.query_map(NO_PARAMS, |row| Ok(Person {
|
|
||||||
id: row.get(0)?,
|
id: row.get(0)?,
|
||||||
name: row.get(1)?,
|
name: row.get(1)?,
|
||||||
time_created: row.get(2)?,
|
time_created: row.get(2)?,
|
||||||
data: row.get(3)?,
|
data: row.get(3)?,
|
||||||
}))?;
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
for person in person_iter {
|
for person in person_iter {
|
||||||
println!("Found person {:?}", person.unwrap());
|
println!("Found person {:?}", person.unwrap());
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
//! expose an interface similar to [rust-postgres](https://github.com/sfackler/rust-postgres).
|
//! expose an interface similar to [rust-postgres](https://github.com/sfackler/rust-postgres).
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use rusqlite::types::ToSql;
|
|
||||||
//! use rusqlite::{params, Connection, Result};
|
//! use rusqlite::{params, Connection, Result};
|
||||||
//! use time::Timespec;
|
//! use time::Timespec;
|
||||||
//!
|
//!
|
||||||
|
Loading…
Reference in New Issue
Block a user