Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: where clauses recognize nested properties #2035

Merged
merged 9 commits into from
Aug 21, 2024
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
Loading