2024-09-08 17:27:20 +02:00
|
|
|
use deadpool_diesel::Status;
|
|
|
|
use derive_more::From;
|
|
|
|
use diesel_async::AsyncPgConnection;
|
2025-03-07 18:21:23 +01:00
|
|
|
use diesel_async::pooled_connection::deadpool::{Object, PoolError};
|
2024-09-08 17:27:20 +02:00
|
|
|
use lib::diesel::pool::PgPool;
|
|
|
|
|
|
|
|
pub trait GetConnection: Clone + Send + Sync {
|
2025-03-07 22:40:10 +01:00
|
|
|
fn get(
|
|
|
|
&self,
|
|
|
|
) -> impl Future<Output = Result<Object<AsyncPgConnection>, GetConnectionError>> + Send;
|
2024-09-08 17:27:20 +02:00
|
|
|
fn status(&self) -> Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
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),
|
|
|
|
}
|