Source: https://github.com/weiznich/diesel_async/blob/main/examples/postgres/pooled-with-rustls/src/main.rs
(config: &str)
| 67 | // Source: |
| 68 | // https://github.com/weiznich/diesel_async/blob/main/examples/postgres/pooled-with-rustls/src/main.rs |
| 69 | fn pg_establish_connection(config: &str) -> BoxFuture<'_, ConnectionResult<AsyncPgConnection>> { |
| 70 | let fut = async { |
| 71 | let conf = config::get(); |
| 72 | |
| 73 | let root_certs = get_root_certs(if conf.postgresql.ca_cert.is_empty() { |
| 74 | None |
| 75 | } else { |
| 76 | Some(conf.postgresql.ca_cert.clone()) |
| 77 | }) |
| 78 | .map_err(|e| ConnectionError::BadConnection(e.to_string()))?; |
| 79 | let rustls_config = rustls::ClientConfig::builder() |
| 80 | .with_root_certificates(root_certs) |
| 81 | .with_no_client_auth(); |
| 82 | let tls = tokio_postgres_rustls::MakeRustlsConnect::new(rustls_config); |
| 83 | let (client, conn) = tokio_postgres::connect(config, tls) |
| 84 | .await |
| 85 | .map_err(|e| ConnectionError::BadConnection(e.to_string()))?; |
| 86 | tokio::spawn(async move { |
| 87 | if let Err(e) = conn.await { |
| 88 | error!(error = %e, "PostgreSQL connection error"); |
| 89 | } |
| 90 | }); |
| 91 | AsyncPgConnection::try_from(client).await |
| 92 | }; |
| 93 | fut.boxed() |
| 94 | } |
| 95 | |
| 96 | fn get_async_db_pool() -> Result<AsyncPgPool> { |
| 97 | let pool_r = ASYNC_PG_POOL.read().unwrap(); |
nothing calls this directly
no test coverage detected