tpcpr/src/database/postgresql.rs

17 lines
553 B
Rust

use std::error::Error;
use tokio_postgres::{NoTls, Client};
pub async fn connect_to_postgres(config: &std::string::String ) -> Result<Client, Box<dyn Error>> {
// let config = "postgres://postgres:password@172.17.0.2:5432/postgres";
let (client, _connection) = tokio_postgres::connect(&config, NoTls).await?;
tokio::spawn(async move {
if let Err(e) = _connection.await {
eprintln!("connection error: {}", e);
}
});
// Do any other necessary processing with the client or connection...
Ok(client)
}