Moved more code from hotel_service to lib
Some checks failed
Build & test / build (push) Failing after 6s

This commit is contained in:
Martin Berg Alstad
2024-09-08 17:27:20 +02:00
parent 7e2df67fee
commit 80f4af9087
18 changed files with 254 additions and 15 deletions

View File

@ -0,0 +1,29 @@
use axum::async_trait;
use deadpool_diesel::Status;
use derive_more::From;
use diesel_async::pooled_connection::deadpool::{Object, PoolError};
use diesel_async::AsyncPgConnection;
use lib::diesel::pool::PgPool;
#[async_trait]
pub trait GetConnection: Clone + Send + Sync {
async fn get(&self) -> Result<Object<AsyncPgConnection>, GetConnectionError>;
fn status(&self) -> Status;
}
#[async_trait]
impl GetConnection for PgPool {
async fn get(&self) -> Result<Object<AsyncPgConnection>, GetConnectionError> {
self.get().await.map_err(Into::into)
}
#[inline]
fn status(&self) -> Status {
self.status()
}
}
#[derive(Debug, From)]
pub enum GetConnectionError {
PoolError(PoolError),
DieselError(diesel::result::Error),
}