29 lines
756 B
Rust
29 lines
756 B
Rust
use deadpool_diesel::Status;
|
|
use derive_more::From;
|
|
use diesel_async::AsyncPgConnection;
|
|
use diesel_async::pooled_connection::deadpool::{Object, PoolError};
|
|
use lib::diesel::pool::PgPool;
|
|
|
|
pub trait GetConnection: Clone + Send + Sync {
|
|
fn get(
|
|
&self,
|
|
) -> impl Future<Output = Result<Object<AsyncPgConnection>, GetConnectionError>> + Send;
|
|
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),
|
|
}
|