Skip to content

Commit 20d4d8a

Browse files
committed
Fix docs for simple_query
Also fixes the return type to be consistent with regular "Rows" API.
1 parent 3b1b9ae commit 20d4d8a

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

postgres/src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1365,9 +1365,11 @@ impl Connection {
13651365
/// ```rust,no_run
13661366
/// # use postgres::{Connection, TlsMode};
13671367
/// # let conn = Connection::connect("", TlsMode::None).unwrap();
1368-
/// for row in &conn.simple_query("SELECT foo FROM bar WHERE baz = 'quux'").unwrap() {
1369-
/// let foo: String = row.get("foo");
1370-
/// println!("foo: {}", foo);
1368+
/// for response in &conn.simple_query("SELECT foo FROM bar WHERE baz = 'quux'").unwrap() {
1369+
/// for row in response {
1370+
/// let foo: &str = row.get("foo");
1371+
/// println!("foo: {}", foo);
1372+
/// }
13711373
/// }
13721374
/// ```
13731375
pub fn simple_query(&self, query: &str) -> Result<Vec<TextRows>> {

postgres/src/text_rows.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::str;
99
pub use postgres_shared::rows::RowIndex;
1010

1111
use stmt::{Column};
12+
use {Result, error};
1213

1314
/// The resulting rows of a query.
1415
pub struct TextRows {
@@ -145,25 +146,26 @@ impl<'a> TextRow<'a> {
145146
}
146147

147148
/// stub
148-
pub fn get<I>(&self, idx: I) -> Option<&str>
149+
pub fn get<I>(&self, idx: I) -> &str
149150
where
150151
I: RowIndex + fmt::Debug,
151152
{
152153
match self.get_inner(&idx) {
153-
Some(value) => value,
154+
Some(Ok(value)) => value,
155+
Some(Err(err)) => panic!("error retrieving column {:?}: {:?}", idx, err),
154156
None => panic!("no such column {:?}", idx),
155157
}
156158
}
157159

158160
/// stub
159-
pub fn get_opt<I>(&self, idx: I) -> Option<Option<&str>>
161+
pub fn get_opt<I>(&self, idx: I) -> Option<Result<&str>>
160162
where
161163
I: RowIndex,
162164
{
163165
self.get_inner(&idx)
164166
}
165167

166-
fn get_inner<I>(&self, idx: &I) -> Option<Option<&str>>
168+
fn get_inner<I>(&self, idx: &I) -> Option<Result<&str>>
167169
where
168170
I: RowIndex,
169171
{
@@ -173,6 +175,6 @@ impl<'a> TextRow<'a> {
173175
};
174176

175177
self.data.get(idx)
176-
.map(|s| str::from_utf8(s).ok())
178+
.map(|s| str::from_utf8(s).map_err(|e| error::conversion(Box::new(e))))
177179
}
178180
}

0 commit comments

Comments
 (0)