Skip to content

Commit

Permalink
feat: where clauses recognize nested properties (dashpay#2035)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldelucia authored Aug 21, 2024
2 parents d0fe6dd + 7faadca commit 55da39f
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions packages/rs-drive/src/query/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,6 @@ impl<'a> WhereClause {
Ok(query)
}

/// Build where clauses from operations
pub(crate) fn build_where_clauses_from_operations(
binary_operation: &ast::Expr,
document_type: &DocumentType,
Expand Down Expand Up @@ -1078,13 +1077,16 @@ impl<'a> WhereClause {
"$id" | "$ownerId" => Cow::Owned(DocumentPropertyType::Identifier),
"$createdAt" | "$updatedAt" => Cow::Owned(DocumentPropertyType::Date),
"$revision" => Cow::Owned(DocumentPropertyType::U64),
property_name => {
let Some(property) = document_type.properties().get(property_name) else {
return Err(Error::Query(QuerySyntaxError::InvalidInClause(
"Invalid query: in clause property not in document type"
.to_string(),
)));
};
_ => {
let property = document_type
.flattened_properties()
.get(&field_name)
.ok_or_else(|| {
Error::Query(QuerySyntaxError::InvalidSQL(format!(
"Invalid query: property named {} not in document type",
field_name
)))
})?;
Cow::Borrowed(&property.property_type)
}
};
Expand Down Expand Up @@ -1213,14 +1215,16 @@ impl<'a> WhereClause {
"$id" | "$ownerId" => Cow::Owned(DocumentPropertyType::Identifier),
"$createdAt" | "$updatedAt" => Cow::Owned(DocumentPropertyType::Date),
"$revision" => Cow::Owned(DocumentPropertyType::U64),
property_name => {
let Some(property) = document_type.properties().get(property_name)
else {
return Err(Error::Query(QuerySyntaxError::InvalidSQL(format!(
"Invalid query: property named {} not in document type",
field_name.as_str()
))));
};
_ => {
let property = document_type
.flattened_properties()
.get(&field_name)
.ok_or_else(|| {
Error::Query(QuerySyntaxError::InvalidSQL(format!(
"Invalid query: property named {} not in document type",
field_name
)))
})?;
Cow::Borrowed(&property.property_type)
}
};
Expand Down

0 comments on commit 55da39f

Please sign in to comment.