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),
}

9
src/diesel/migration.rs Normal file
View File

@ -0,0 +1,9 @@
use diesel_async::AsyncPgConnection;
use diesel_async_migrations::EmbeddedMigrations;
pub async fn run_migrations(
migrations: &EmbeddedMigrations,
conn: &mut AsyncPgConnection,
) -> Result<(), diesel::result::Error> {
migrations.run_pending_migrations(conn).await
}

View File

@ -1,3 +1,5 @@
pub mod get_connection;
pub mod migration;
pub mod pool;
/// Re-export diesel::result::Error as DieselError