Skip to content

Commit 3b1b9ae

Browse files
committed
Add docs for simple_query method on Connections
1 parent 815175f commit 3b1b9ae

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

postgres/src/lib.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,28 @@ impl Connection {
13481348

13491349
/// Send a simple, non-prepared query
13501350
///
1351-
/// TODO docs. Should this replace the batch_execute API?
1351+
/// Executes a query without making a prepared statement. All result columns
1352+
/// are returned in a UTF-8 text format rather than compact binary
1353+
/// representations. This can be useful when communicating with services
1354+
/// like _pgbouncer_ which speak "basic" postgres but don't support prepared
1355+
/// statements.
1356+
///
1357+
/// Because rust-postgres' query parameter substitution relies on prepared
1358+
/// statements, it's not possible to pass a separate parameters list with
1359+
/// this API.
1360+
///
1361+
/// In general, the `query` API should be prefered whenever possible.
1362+
///
1363+
/// # Example
1364+
///
1365+
/// ```rust,no_run
1366+
/// # use postgres::{Connection, TlsMode};
1367+
/// # 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);
1371+
/// }
1372+
/// ```
13521373
pub fn simple_query(&self, query: &str) -> Result<Vec<TextRows>> {
13531374
self.0.borrow_mut().simple_query_(query)
13541375
}

0 commit comments

Comments
 (0)