This commit is contained in:
@@ -16,7 +16,7 @@ pub enum DbPool {
|
||||
Postgres(sqlx::PgPool),
|
||||
}
|
||||
|
||||
pub struct Repos {
|
||||
pub struct WorkerDbOutput {
|
||||
pub movie: Arc<dyn MovieRepository>,
|
||||
pub review: Arc<dyn ReviewRepository>,
|
||||
pub diary: Arc<dyn DiaryRepository>,
|
||||
@@ -26,96 +26,95 @@ pub struct Repos {
|
||||
pub import_profile: Arc<dyn ImportProfileRepository>,
|
||||
pub movie_profile: Arc<dyn MovieProfileRepository>,
|
||||
pub watchlist: Arc<dyn WatchlistRepository>,
|
||||
pub ap_content: Arc<dyn LocalApContentQuery>,
|
||||
pub image_ref_command: Arc<dyn ImageRefCommand>,
|
||||
pub image_ref_query: Arc<dyn ImageRefQuery>,
|
||||
pub watch_event: Arc<dyn WatchEventRepository>,
|
||||
pub webhook_token: Arc<dyn WebhookTokenRepository>,
|
||||
pub person_command: Arc<dyn PersonCommand>,
|
||||
pub person_query: Arc<dyn PersonQuery>,
|
||||
pub search_command: Arc<dyn SearchCommand>,
|
||||
pub search_port: Arc<dyn SearchPort>,
|
||||
pub profile_fields: Arc<dyn UserProfileFieldsRepository>,
|
||||
pub watch_event: Arc<dyn WatchEventRepository>,
|
||||
pub webhook_token: Arc<dyn WebhookTokenRepository>,
|
||||
pub ap_content: Arc<dyn LocalApContentQuery>,
|
||||
pub image_ref_command: Arc<dyn ImageRefCommand>,
|
||||
pub image_ref_query: Arc<dyn ImageRefQuery>,
|
||||
pub db_pool: DbPool,
|
||||
}
|
||||
|
||||
pub async fn connect(database_url: &str, backend: &str) -> anyhow::Result<(Repos, DbPool)> {
|
||||
pub async fn connect(database_url: &str, backend: &str) -> anyhow::Result<WorkerDbOutput> {
|
||||
match backend {
|
||||
#[cfg(feature = "postgres")]
|
||||
"postgres" => {
|
||||
let (pool, m, r, d, s, u, is, ip, mp, wl, ac) = postgres::wire(database_url)
|
||||
let w = postgres::wire(database_url)
|
||||
.await
|
||||
.context("PostgreSQL connection failed")?;
|
||||
let (image_ref_command, image_ref_query) = postgres::create_image_ref(pool.clone());
|
||||
let (person_command, person_query) = postgres::create_person_adapter(pool.clone());
|
||||
let (image_ref_command, image_ref_query) = postgres::create_image_ref(w.pool.clone());
|
||||
let (person_command, person_query) = postgres::create_person_adapter(w.pool.clone());
|
||||
let (search_command, search_port) =
|
||||
postgres_search::create_search_adapter(pool.clone());
|
||||
let pf = postgres::create_profile_fields_repo(pool.clone());
|
||||
postgres_search::create_search_adapter(w.pool.clone());
|
||||
let pf = postgres::create_profile_fields_repo(w.pool.clone());
|
||||
let we: Arc<dyn WatchEventRepository> =
|
||||
Arc::new(postgres::PostgresWatchEventRepository::new(pool.clone()));
|
||||
let wt: Arc<dyn WebhookTokenRepository> =
|
||||
Arc::new(postgres::PostgresWebhookTokenRepository::new(pool.clone()));
|
||||
Ok((
|
||||
Repos {
|
||||
movie: m,
|
||||
review: r,
|
||||
diary: d,
|
||||
stats: s,
|
||||
user: u,
|
||||
import_session: is,
|
||||
import_profile: ip,
|
||||
movie_profile: mp,
|
||||
watchlist: wl,
|
||||
ap_content: ac,
|
||||
image_ref_command,
|
||||
image_ref_query,
|
||||
person_command,
|
||||
person_query,
|
||||
search_command,
|
||||
search_port,
|
||||
profile_fields: pf,
|
||||
watch_event: we,
|
||||
webhook_token: wt,
|
||||
},
|
||||
DbPool::Postgres(pool),
|
||||
))
|
||||
Arc::new(postgres::PostgresWatchEventRepository::new(w.pool.clone()));
|
||||
let wt: Arc<dyn WebhookTokenRepository> = Arc::new(
|
||||
postgres::PostgresWebhookTokenRepository::new(w.pool.clone()),
|
||||
);
|
||||
Ok(WorkerDbOutput {
|
||||
movie: w.movie,
|
||||
review: w.review,
|
||||
diary: w.diary,
|
||||
stats: w.stats,
|
||||
user: w.user,
|
||||
import_session: w.import_session,
|
||||
import_profile: w.import_profile,
|
||||
movie_profile: w.movie_profile,
|
||||
watchlist: w.watchlist,
|
||||
watch_event: we,
|
||||
webhook_token: wt,
|
||||
person_command,
|
||||
person_query,
|
||||
search_command,
|
||||
search_port,
|
||||
profile_fields: pf,
|
||||
ap_content: w.ap_content,
|
||||
image_ref_command,
|
||||
image_ref_query,
|
||||
db_pool: DbPool::Postgres(w.pool),
|
||||
})
|
||||
}
|
||||
#[cfg(feature = "sqlite")]
|
||||
_ => {
|
||||
let (pool, m, r, d, s, u, is, ip, mp, wl, ac) = sqlite::wire(database_url)
|
||||
let w = sqlite::wire(database_url)
|
||||
.await
|
||||
.context("SQLite connection failed")?;
|
||||
let (image_ref_command, image_ref_query) = sqlite::create_image_ref(pool.clone());
|
||||
let (person_command, person_query) = sqlite::create_person_adapter(pool.clone());
|
||||
let (search_command, search_port) = sqlite_search::create_search_adapter(pool.clone());
|
||||
let pf = sqlite::create_profile_fields_repo(pool.clone());
|
||||
let (image_ref_command, image_ref_query) = sqlite::create_image_ref(w.pool.clone());
|
||||
let (person_command, person_query) = sqlite::create_person_adapter(w.pool.clone());
|
||||
let (search_command, search_port) =
|
||||
sqlite_search::create_search_adapter(w.pool.clone());
|
||||
let pf = sqlite::create_profile_fields_repo(w.pool.clone());
|
||||
let we: Arc<dyn WatchEventRepository> =
|
||||
Arc::new(sqlite::SqliteWatchEventRepository::new(pool.clone()));
|
||||
Arc::new(sqlite::SqliteWatchEventRepository::new(w.pool.clone()));
|
||||
let wt: Arc<dyn WebhookTokenRepository> =
|
||||
Arc::new(sqlite::SqliteWebhookTokenRepository::new(pool.clone()));
|
||||
Ok((
|
||||
Repos {
|
||||
movie: m,
|
||||
review: r,
|
||||
diary: d,
|
||||
stats: s,
|
||||
user: u,
|
||||
import_session: is,
|
||||
import_profile: ip,
|
||||
movie_profile: mp,
|
||||
watchlist: wl,
|
||||
ap_content: ac,
|
||||
image_ref_command,
|
||||
image_ref_query,
|
||||
person_command,
|
||||
person_query,
|
||||
search_command,
|
||||
search_port,
|
||||
profile_fields: pf,
|
||||
watch_event: we,
|
||||
webhook_token: wt,
|
||||
},
|
||||
DbPool::Sqlite(pool),
|
||||
))
|
||||
Arc::new(sqlite::SqliteWebhookTokenRepository::new(w.pool.clone()));
|
||||
Ok(WorkerDbOutput {
|
||||
movie: w.movie,
|
||||
review: w.review,
|
||||
diary: w.diary,
|
||||
stats: w.stats,
|
||||
user: w.user,
|
||||
import_session: w.import_session,
|
||||
import_profile: w.import_profile,
|
||||
movie_profile: w.movie_profile,
|
||||
watchlist: w.watchlist,
|
||||
watch_event: we,
|
||||
webhook_token: wt,
|
||||
person_command,
|
||||
person_query,
|
||||
search_command,
|
||||
search_port,
|
||||
profile_fields: pf,
|
||||
ap_content: w.ap_content,
|
||||
image_ref_command,
|
||||
image_ref_query,
|
||||
db_pool: DbPool::Sqlite(w.pool),
|
||||
})
|
||||
}
|
||||
#[cfg(not(feature = "sqlite"))]
|
||||
_ => anyhow::bail!("DATABASE_BACKEND={backend} is not supported by this build"),
|
||||
|
||||
Reference in New Issue
Block a user