[−][src]Function async_postgres::connect
pub async fn connect(
config: Config
) -> Result<(Client, Connection<Socket, NoTlsStream>)>
Connect to postgres server.
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(()) }