Skip to content

Commit aaaf824

Browse files
committed
Crate level docs
1 parent 16021d2 commit aaaf824

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

postgres/src/lib.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,57 @@
1+
//! A synchronous client for the PostgreSQL database.
12
//!
3+
//! # Example
4+
//!
5+
//! ```no_run
6+
//! use postgres::{Client, NoTls};
7+
//!
8+
//! # fn main() -> Result<(), postgres::Error> {
9+
//! let mut client = Client::connect("host=localhost user=postgres", NoTls)?;
10+
//!
11+
//! client.simple_query("
12+
//! CREATE TABLE person (
13+
//! id SERIAL PRIMARY KEY,
14+
//! name TEXT NOT NULL,
15+
//! data BYTEA
16+
//! )
17+
//! ")?;
18+
//!
19+
//! let name = "Ferris";
20+
//! let data = None::<&[u8]>;
21+
//! client.execute(
22+
//! "INSERT INTO person (name, data) VALUES ($1, $2)",
23+
//! &[&name, &data],
24+
//! )?;
25+
//!
26+
//! for row in client.query("SELECT id, name, data FROM person", &[])? {
27+
//! let id: i32 = row.get(0);
28+
//! let name: &str = row.get(1);
29+
//! let data: Option<&[u8]> = row.get(2);
30+
//!
31+
//! println!("found person: {} {} {:?}", id, name, data);
32+
//! }
33+
//! # Ok(())
34+
//! # }
35+
//! ```
36+
//!
37+
//! # Implementation
38+
//!
39+
//! This crate is a lightweight wrapper over tokio-postgres. The `tokio_postgres::Connection` is spawned onto an
40+
//! executor, and the `tokio_postgres::Client` is wrapped in the `postgres::Client`, which simply waits on the futures
41+
//! the nonblocking client creates.
42+
//!
43+
//! # Runtime
44+
//!
45+
//! A client can be constructed directly from a `tokio-postgres` client via a `From` implementation, but the `runtime`
46+
//! Cargo feature (enabled by default) provides a more convenient interface. By default, connections will be spawned
47+
//! onto a static tokio `Runtime`, but a custom `Executor` can also be used instead.
48+
//!
49+
//! # SSL/TLS support
50+
//!
51+
//! TLS support is implemented via external libraries. `Client::connect` and `Config::connect` take a TLS implementation
52+
//! as an argument. The `NoTls` type in this crate can be used when TLS is not required. Otherwise, the
53+
//! `tokio-postgres-openssl` and `tokio-postgres-native-tls` crates provide implementations backed by the `postgres` and
54+
//! `native-tls` crates, respectively.
255
#![warn(clippy::all, rust_2018_idioms, missing_docs)]
356

457
#[cfg(feature = "runtime")]

0 commit comments

Comments
 (0)