mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-26 19:41:37 +08:00
Fix rustdoc examples
This commit is contained in:
parent
d93dec52c0
commit
8abaf6eefe
16
src/cache.rs
16
src/cache.rs
@ -152,7 +152,7 @@ impl StatementCache {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::StatementCache;
|
use super::StatementCache;
|
||||||
use crate::{Connection, NO_PARAMS};
|
use crate::{Connection, FallibleStreamingIterator, NO_PARAMS};
|
||||||
|
|
||||||
impl StatementCache {
|
impl StatementCache {
|
||||||
fn clear(&self) {
|
fn clear(&self) {
|
||||||
@ -277,12 +277,9 @@ mod test {
|
|||||||
{
|
{
|
||||||
let mut stmt = db.prepare_cached(sql).unwrap();
|
let mut stmt = db.prepare_cached(sql).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
1i32,
|
Ok(Some(&1i32)),
|
||||||
stmt.query_map::<i32, _, _>(NO_PARAMS, |r| r.get(0))
|
stmt.query(NO_PARAMS).unwrap().map(|r| r.get(0))
|
||||||
.unwrap()
|
|
||||||
.next()
|
.next()
|
||||||
.unwrap()
|
|
||||||
.unwrap()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,12 +294,9 @@ mod test {
|
|||||||
{
|
{
|
||||||
let mut stmt = db.prepare_cached(sql).unwrap();
|
let mut stmt = db.prepare_cached(sql).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(1i32, 2i32),
|
Ok(Some(&(1i32, 2i32))),
|
||||||
stmt.query_map(NO_PARAMS, |r| (r.get(0), r.get(1)))
|
stmt.query(NO_PARAMS).unwrap().map(|r| (r.get(0), r.get(1)))
|
||||||
.unwrap()
|
|
||||||
.next()
|
.next()
|
||||||
.unwrap()
|
|
||||||
.unwrap()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,14 +169,13 @@ impl Statement<'_> {
|
|||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use rusqlite::{Connection, Result, NO_PARAMS};
|
/// # use rusqlite::{Connection, FallibleStreamingIterator, Result, NO_PARAMS};
|
||||||
/// fn get_names(conn: &Connection) -> Result<Vec<String>> {
|
/// fn get_names(conn: &Connection) -> Result<Vec<String>> {
|
||||||
/// let mut stmt = conn.prepare("SELECT name FROM people")?;
|
/// let mut stmt = conn.prepare("SELECT name FROM people")?;
|
||||||
/// let mut rows = stmt.query(NO_PARAMS)?;
|
/// let mut rows = stmt.query(NO_PARAMS)?;
|
||||||
///
|
///
|
||||||
/// let mut names = Vec::new();
|
/// let mut names = Vec::new();
|
||||||
/// while let Some(result_row) = rows.next() {
|
/// while let Some(row) = rows.next()? {
|
||||||
/// let row = result_row?;
|
|
||||||
/// names.push(row.get(0));
|
/// names.push(row.get(0));
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
@ -206,11 +205,11 @@ impl Statement<'_> {
|
|||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use rusqlite::{Connection, Result};
|
/// # use rusqlite::{Connection, FallibleStreamingIterator, Result};
|
||||||
/// fn query(conn: &Connection) -> Result<()> {
|
/// fn query(conn: &Connection) -> Result<()> {
|
||||||
/// let mut stmt = conn.prepare("SELECT * FROM test where name = :name")?;
|
/// let mut stmt = conn.prepare("SELECT * FROM test where name = :name")?;
|
||||||
/// let mut rows = stmt.query_named(&[(":name", &"one")])?;
|
/// let mut rows = stmt.query_named(&[(":name", &"one")])?;
|
||||||
/// while let Some(row) = rows.next() {
|
/// while let Some(row) = rows.next()? {
|
||||||
/// // ...
|
/// // ...
|
||||||
/// }
|
/// }
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
@ -221,11 +220,11 @@ impl Statement<'_> {
|
|||||||
/// and so the above example could also be written as:
|
/// and so the above example could also be written as:
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use rusqlite::{Connection, Result, named_params};
|
/// # use rusqlite::{Connection, FallibleStreamingIterator, Result, named_params};
|
||||||
/// fn query(conn: &Connection) -> Result<()> {
|
/// fn query(conn: &Connection) -> Result<()> {
|
||||||
/// let mut stmt = conn.prepare("SELECT * FROM test where name = :name")?;
|
/// let mut stmt = conn.prepare("SELECT * FROM test where name = :name")?;
|
||||||
/// let mut rows = stmt.query_named(named_params!{ ":name": "one" })?;
|
/// let mut rows = stmt.query_named(named_params!{ ":name": "one" })?;
|
||||||
/// while let Some(row) = rows.next() {
|
/// while let Some(row) = rows.next()? {
|
||||||
/// // ...
|
/// // ...
|
||||||
/// }
|
/// }
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
@ -816,14 +815,12 @@ mod test {
|
|||||||
.prepare("SELECT id FROM test where name = :name")
|
.prepare("SELECT id FROM test where name = :name")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut rows = stmt
|
let mut rows = stmt
|
||||||
.query_map_named(&[(":name", &"one")], |row| {
|
.query_named(&[(":name", &"one")]).unwrap().map(|row| {
|
||||||
let id: i32 = row.get(0);
|
let id: i32 = row.get(0);
|
||||||
2 * id
|
2 * id
|
||||||
})
|
});
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let doubled_id: i32 = rows.next().unwrap().unwrap();
|
assert_eq!(Ok(Some(&2)), rows.next());
|
||||||
assert_eq!(2, doubled_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user