-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlib.rs
41 lines (37 loc) · 1.07 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#![cfg_attr(feature = "docs", feature(external_doc))]
#![cfg_attr(feature = "docs", doc(include = "../README.md"))]
#![cfg_attr(feature = "docs", warn(missing_docs))]
#[doc(inline)]
pub use connect::connect_tls;
#[doc(inline)]
pub use socket::Socket;
#[doc(no_inline)]
pub use tokio_postgres::*;
use std::io;
use tokio_postgres::tls::{NoTls, NoTlsStream};
use tokio_postgres::{Client, Connection};
/// Connect to postgres server.
///
/// ```rust
/// use async_postgres::connect;
/// use std::error::Error;
/// use async_std::task::spawn;
///
/// async fn play() -> Result<(), Box<dyn Error>> {
/// let url = "host=localhost user=postgres";
/// let (client, conn) = connect(url.parse()?).await?;
/// spawn(conn);
/// let row = client.query_one("SELECT * FROM user WHERE id=$1", &[&0]).await?;
/// let value: &str = row.get(0);
/// println!("value: {}", value);
/// Ok(())
/// }
/// ```
#[inline]
pub async fn connect(
config: Config,
) -> io::Result<(Client, Connection<Socket, NoTlsStream>)> {
connect_tls(config, NoTls).await
}
mod connect;
mod socket;