Moved more code from hotel_service to lib
Some checks failed
Build & test / build (push) Failing after 6s
Some checks failed
Build & test / build (push) Failing after 6s
This commit is contained in:
29
src/diesel/get_connection.rs
Normal file
29
src/diesel/get_connection.rs
Normal 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
9
src/diesel/migration.rs
Normal 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
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
pub mod get_connection;
|
||||
pub mod migration;
|
||||
pub mod pool;
|
||||
|
||||
/// Re-export diesel::result::Error as DieselError
|
||||
|
Reference in New Issue
Block a user