-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
funds-manager: Use
diesel-async
and add warp
endpoints
- Loading branch information
Showing
11 changed files
with
215 additions
and
55 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,5 +1,34 @@ | ||
//! Database code | ||
|
||
use diesel_async::{AsyncConnection, AsyncPgConnection}; | ||
Check failure on line 3 in funds-manager/src/db/mod.rs GitHub Actions / clippyunused import: `AsyncConnection`
|
||
use native_tls::TlsConnector; | ||
use postgres_native_tls::MakeTlsConnector; | ||
use renegade_util::err_str; | ||
use tokio_postgres::tls::{MakeTlsConnect, TlsConnect}; | ||
Check failure on line 7 in funds-manager/src/db/mod.rs GitHub Actions / clippyunused imports: `MakeTlsConnect`, `TlsConnect`
|
||
|
||
use crate::error::FundsManagerError; | ||
|
||
pub mod models; | ||
#[allow(missing_docs)] | ||
pub mod schema; | ||
|
||
/// Establish a connection to the database | ||
pub async fn establish_connection(db_url: &str) -> Result<AsyncPgConnection, FundsManagerError> { | ||
let connector = TlsConnector::builder() | ||
.danger_accept_invalid_certs(true) | ||
.build() | ||
.map_err(err_str!(FundsManagerError::Db))?; | ||
let connector = MakeTlsConnector::new(connector); | ||
let (client, conn) = tokio_postgres::connect(db_url, connector) | ||
.await | ||
.map_err(err_str!(FundsManagerError::Db))?; | ||
|
||
// Spawn the connection handle in a separate task | ||
tokio::spawn(async move { | ||
if let Err(e) = conn.await { | ||
eprintln!("Connection error: {}", e); | ||
} | ||
}); | ||
|
||
AsyncPgConnection::try_from(client).await.map_err(err_str!(FundsManagerError::Db)) | ||
} |
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
Oops, something went wrong.