Skip to content

Commit

Permalink
add value-only SerializedWhereValue
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Dec 17, 2022
1 parent bebe1e7 commit 3637240
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 2 additions & 5 deletions cli/src/generator/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,7 @@ pub fn generate(args: &GenerateArgs, module_path: TokenStream) -> Vec<TokenStrea
quote! {
Self::#is_null_variant => (
#field_string,
#pcr::SerializedWhereValue::Object(vec![(
"equals".to_string(),
#pcr::PrismaValue::Null
)])
#pcr::SerializedWhereValue::Value(#pcr::PrismaValue::Null)
)
},
);
Expand Down Expand Up @@ -648,7 +645,7 @@ pub fn generate(args: &GenerateArgs, module_path: TokenStream) -> Vec<TokenStrea
quote! {
Self::#equals_variant_name(value) => (
#field_string,
#pcr::SerializedWhereValue::Object(vec![("equals".to_string(), #type_as_prisma_value)])
#pcr::SerializedWhereValue::Value(#type_as_prisma_value)
)
}
);
Expand Down
9 changes: 9 additions & 0 deletions integration-tests/tests/find_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@ async fn filtering_one_to_one_relation() -> TestResult {
assert_eq!(users.len(), 1);
assert_eq!(users[0].name, "Jamie");

let users = client
.user()
.find_many(vec![user::profile::is_null()])
.exec()
.await?;
dbg!(&users);
assert_eq!(users.len(), 1);
assert_eq!(users[0].name, "Jamie");

cleanup(client).await
}

Expand Down
3 changes: 3 additions & 0 deletions src/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ impl ModelActionType {
pub enum SerializedWhereValue {
Object(Vec<(String, prisma_models::PrismaValue)>),
List(Vec<prisma_models::PrismaValue>),
Value(prisma_models::PrismaValue),
}

impl Into<prisma_models::PrismaValue> for SerializedWhereValue {
fn into(self) -> prisma_models::PrismaValue {
match self {
Self::Object(v) => prisma_models::PrismaValue::Object(v),
Self::List(v) => prisma_models::PrismaValue::List(v),
Self::Value(v) => v,
}
}
}
Expand Down Expand Up @@ -138,6 +140,7 @@ impl SerializedWhereInput {
None => prisma_models::PrismaValue::Object(params),
},
SerializedWhereValue::List(values) => prisma_models::PrismaValue::List(values),
SerializedWhereValue::Value(v) => v,
},
)
}
Expand Down

0 comments on commit 3637240

Please sign in to comment.