Tests
This commit is contained in:
@ -1,35 +1,10 @@
|
||||
use crate::config;
|
||||
use crate::error::AppError;
|
||||
use axum::async_trait;
|
||||
use deadpool_diesel::postgres::BuildError;
|
||||
use deadpool_diesel::Status;
|
||||
use diesel_async::pooled_connection::deadpool::{Object, Pool};
|
||||
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
|
||||
use diesel_async::AsyncPgConnection;
|
||||
|
||||
pub type PgPool = Pool<AsyncPgConnection>;
|
||||
|
||||
#[async_trait]
|
||||
pub trait GetConnection: Clone + Send + Sync {
|
||||
async fn get(&self) -> Result<Object<AsyncPgConnection>, AppError>;
|
||||
fn status(&self) -> Status;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl GetConnection for PgPool {
|
||||
async fn get(&self) -> Result<Object<AsyncPgConnection>, AppError> {
|
||||
self.get().await.map_err(Into::into)
|
||||
}
|
||||
fn status(&self) -> Status {
|
||||
self.status()
|
||||
}
|
||||
}
|
||||
use lib::diesel::pool::PgPool;
|
||||
|
||||
pub(crate) fn create_pool() -> Result<PgPool, BuildError> {
|
||||
create_pool_from_url(config::DATABASE_URL)
|
||||
}
|
||||
|
||||
pub(crate) fn create_pool_from_url(url: impl Into<String>) -> Result<PgPool, BuildError> {
|
||||
let config = AsyncDieselConnectionManager::<AsyncPgConnection>::new(url);
|
||||
Pool::builder(config).max_size(config::POOL_SIZE).build()
|
||||
lib::diesel::pool::create_pool()
|
||||
.url(config::DATABASE_URL)
|
||||
.size(config::POOL_SIZE)
|
||||
.call()
|
||||
}
|
||||
|
Reference in New Issue
Block a user