refactor: split ImageRefPort into ImageRefCommand and ImageRefQuery
This commit is contained in:
@@ -2,8 +2,9 @@ use std::sync::Arc;
|
||||
|
||||
use anyhow::Context;
|
||||
use domain::ports::{
|
||||
DiaryRepository, ImageRefPort, ImportProfileRepository, ImportSessionRepository,
|
||||
MovieProfileRepository, MovieRepository, ReviewRepository, StatsRepository, UserRepository,
|
||||
DiaryRepository, ImageRefCommand, ImageRefQuery, ImportProfileRepository,
|
||||
ImportSessionRepository, MovieProfileRepository, MovieRepository, ReviewRepository,
|
||||
StatsRepository, UserRepository,
|
||||
};
|
||||
|
||||
pub enum DbPool {
|
||||
@@ -22,7 +23,8 @@ pub struct Repos {
|
||||
pub import_session: Arc<dyn ImportSessionRepository>,
|
||||
pub import_profile: Arc<dyn ImportProfileRepository>,
|
||||
pub movie_profile: Arc<dyn MovieProfileRepository>,
|
||||
pub image_ref: Arc<dyn ImageRefPort>,
|
||||
pub image_ref_command: Arc<dyn ImageRefCommand>,
|
||||
pub image_ref_query: Arc<dyn ImageRefQuery>,
|
||||
}
|
||||
|
||||
pub async fn connect(database_url: &str, backend: &str) -> anyhow::Result<(Repos, DbPool)> {
|
||||
@@ -31,15 +33,19 @@ pub async fn connect(database_url: &str, backend: &str) -> anyhow::Result<(Repos
|
||||
"postgres" => {
|
||||
let (pool, m, r, d, s, u, is, ip, mp) =
|
||||
postgres::wire(database_url).await.context("PostgreSQL connection failed")?;
|
||||
let image_ref = postgres::create_image_ref(pool.clone());
|
||||
Ok((Repos { movie: m, review: r, diary: d, stats: s, user: u, import_session: is, import_profile: ip, movie_profile: mp, image_ref }, DbPool::Postgres(pool)))
|
||||
let (image_ref_command, image_ref_query) = postgres::create_image_ref(pool.clone());
|
||||
Ok((Repos { movie: m, review: r, diary: d, stats: s, user: u,
|
||||
import_session: is, import_profile: ip, movie_profile: mp,
|
||||
image_ref_command, image_ref_query }, DbPool::Postgres(pool)))
|
||||
}
|
||||
#[cfg(feature = "sqlite")]
|
||||
_ => {
|
||||
let (pool, m, r, d, s, u, is, ip, mp) =
|
||||
sqlite::wire(database_url).await.context("SQLite connection failed")?;
|
||||
let image_ref = sqlite::create_image_ref(pool.clone());
|
||||
Ok((Repos { movie: m, review: r, diary: d, stats: s, user: u, import_session: is, import_profile: ip, movie_profile: mp, image_ref }, DbPool::Sqlite(pool)))
|
||||
let (image_ref_command, image_ref_query) = sqlite::create_image_ref(pool.clone());
|
||||
Ok((Repos { movie: m, review: r, diary: d, stats: s, user: u,
|
||||
import_session: is, import_profile: ip, movie_profile: mp,
|
||||
image_ref_command, image_ref_query }, DbPool::Sqlite(pool)))
|
||||
}
|
||||
#[cfg(not(feature = "sqlite"))]
|
||||
_ => anyhow::bail!("DATABASE_BACKEND={backend} is not supported by this build"),
|
||||
|
||||
Reference in New Issue
Block a user