Fix docs for simple_query

Also fixes the return type to be consistent with regular "Rows" API.
This commit is contained in:
Joe Wilm 2018-04-27 17:26:49 -07:00
parent 3b1b9aeace
commit 20d4d8a71a
2 changed files with 12 additions and 8 deletions

View File

@ -1365,9 +1365,11 @@ impl Connection {
/// ```rust,no_run
/// # use postgres::{Connection, TlsMode};
/// # let conn = Connection::connect("", TlsMode::None).unwrap();
/// for row in &conn.simple_query("SELECT foo FROM bar WHERE baz = 'quux'").unwrap() {
/// let foo: String = row.get("foo");
/// println!("foo: {}", foo);
/// for response in &conn.simple_query("SELECT foo FROM bar WHERE baz = 'quux'").unwrap() {
/// for row in response {
/// let foo: &str = row.get("foo");
/// println!("foo: {}", foo);
/// }
/// }
/// ```
pub fn simple_query(&self, query: &str) -> Result<Vec<TextRows>> {

View File

@ -9,6 +9,7 @@ use std::str;
pub use postgres_shared::rows::RowIndex;
use stmt::{Column};
use {Result, error};
/// The resulting rows of a query.
pub struct TextRows {
@ -145,25 +146,26 @@ impl<'a> TextRow<'a> {
}
/// stub
pub fn get<I>(&self, idx: I) -> Option<&str>
pub fn get<I>(&self, idx: I) -> &str
where
I: RowIndex + fmt::Debug,
{
match self.get_inner(&idx) {
Some(value) => value,
Some(Ok(value)) => value,
Some(Err(err)) => panic!("error retrieving column {:?}: {:?}", idx, err),
None => panic!("no such column {:?}", idx),
}
}
/// stub
pub fn get_opt<I>(&self, idx: I) -> Option<Option<&str>>
pub fn get_opt<I>(&self, idx: I) -> Option<Result<&str>>
where
I: RowIndex,
{
self.get_inner(&idx)
}
fn get_inner<I>(&self, idx: &I) -> Option<Option<&str>>
fn get_inner<I>(&self, idx: &I) -> Option<Result<&str>>
where
I: RowIndex,
{
@ -173,6 +175,6 @@ impl<'a> TextRow<'a> {
};
self.data.get(idx)
.map(|s| str::from_utf8(s).ok())
.map(|s| str::from_utf8(s).map_err(|e| error::conversion(Box::new(e))))
}
}