[][src]Function roa_pg::connect

pub async fn connect<'_>(
    config: &'_ Config
) -> Result<(Client, Connection<AsyncStream<TcpStream>, TlsStream<AsyncStream<TcpStream>>>)>

Connect to postgres server.

use roa_pg::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(())
}