-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
147 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use diesel::{ConnectionError, ConnectionResult}; | ||
use diesel_async::{pooled_connection::ManagerConfig, AsyncPgConnection}; | ||
use futures_util::{future::BoxFuture, FutureExt}; | ||
|
||
pub fn pool_config() -> ManagerConfig<AsyncPgConnection> { | ||
let mut config = ManagerConfig::default(); | ||
config.custom_setup = Box::new(establish_conn); | ||
config | ||
} | ||
|
||
fn establish_conn(config: &str) -> BoxFuture<'_, ConnectionResult<AsyncPgConnection>> { | ||
async { | ||
let rustls_config = rustls::ClientConfig::builder() | ||
.with_root_certificates(load_certs()) | ||
.with_no_client_auth(); | ||
let tls = tokio_postgres_rustls::MakeRustlsConnect::new(rustls_config); | ||
let (client, conn) = tokio_postgres::connect(config, tls) | ||
.await | ||
.map_err(|err| ConnectionError::BadConnection(err.to_string()))?; | ||
|
||
tokio::spawn(async move { | ||
if let Err(err) = conn.await { | ||
error!("Database connection error: {err}"); | ||
} | ||
}); | ||
|
||
AsyncPgConnection::try_from(client).await | ||
} | ||
.boxed() | ||
} | ||
|
||
fn load_certs() -> rustls::RootCertStore { | ||
let mut roots = rustls::RootCertStore::empty(); | ||
let certs = | ||
rustls_native_certs::load_native_certs().expect("Failed to load native certificates"); | ||
roots.add_parsable_certificates(certs); | ||
roots | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters