AND search params together properly (#2430)

This commit is contained in:
Brendan Allan 2024-05-01 15:17:44 +08:00 committed by GitHub
parent 312524a860
commit 334254abe6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,6 +6,7 @@ use crate::{
util::{unsafe_streamed_query, BatchedStream}, util::{unsafe_streamed_query, BatchedStream},
}; };
use prisma_client_rust::Operator;
use sd_core_indexer_rules::seed::no_hidden; use sd_core_indexer_rules::seed::no_hidden;
use sd_core_indexer_rules::IndexerRule; use sd_core_indexer_rules::IndexerRule;
use sd_core_prisma_helpers::{file_path_with_object, object_with_file_paths}; use sd_core_prisma_helpers::{file_path_with_object, object_with_file_paths};
@ -195,7 +196,7 @@ pub fn mount() -> AlphaRouter<Ctx> {
fp fp
}; };
let mut query = db.file_path().find_many(params); let mut query = db.file_path().find_many(andify(params));
if let Some(take) = take { if let Some(take) = take {
query = query.take(take as i64); query = query.take(take as i64);
@ -306,7 +307,7 @@ pub fn mount() -> AlphaRouter<Ctx> {
obj.push(prisma::object::file_paths::some(fp)); obj.push(prisma::object::file_paths::some(fp));
} }
obj andify(obj)
}) })
.take(take as i64); .take(take as i64);
@ -412,3 +413,13 @@ async fn merge_filters(
Ok((fp, obj)) Ok((fp, obj))
} }
/// PCR 0.6.x's AND does { AND: [{ ...}] } instead of { AND: [{ ... }, { ... }, { ... }] },
/// this works around it.
fn andify<T: From<Operator<T>>>(params: Vec<T>) -> Vec<T> {
params.into_iter().fold(vec![], |mut params, param| {
params.push(param);
vec![prisma_client_rust::operator::and(params).into()]
})
}