Skip to content

Commit

Permalink
Explain options support
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Apr 2, 2024
1 parent 9ff2ed7 commit 94dd224
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/db/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ impl FirestoreDb {
.as_ref()
.map(|selector| selector.try_into())
.transpose()?,
explain_options: params
.explain_options
.as_ref()
.map(|eo| eo.try_into())
.transpose()?,
query_type: Some(run_query_request::QueryType::StructuredQuery(params.into())),
explain_options: None,
}))
}

Expand Down
16 changes: 16 additions & 0 deletions src/db/query_models.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(clippy::derive_partial_eq_without_eq)] // Since we may not be able to implement Eq for the changes coming from Firestore protos

use crate::errors::FirestoreError;
use crate::FirestoreValue;
use gcloud_sdk::google::firestore::v1::*;
use rsb_derive::Builder;
Expand Down Expand Up @@ -37,6 +38,7 @@ pub struct FirestoreQueryParams {
pub return_only_fields: Option<Vec<String>>,
pub start_at: Option<FirestoreQueryCursor>,
pub end_at: Option<FirestoreQueryCursor>,
pub explain_options: Option<FirestoreExplainOptions>,
}

impl From<FirestoreQueryParams> for StructuredQuery {
Expand Down Expand Up @@ -409,3 +411,17 @@ pub struct FirestorePartition {
pub start_at: Option<FirestoreQueryCursor>,
pub end_at: Option<FirestoreQueryCursor>,
}

#[derive(Debug, PartialEq, Clone, Builder)]
pub struct FirestoreExplainOptions {
pub analyze: Option<bool>,
}

impl TryFrom<&FirestoreExplainOptions> for gcloud_sdk::google::firestore::v1::ExplainOptions {
type Error = FirestoreError;
fn try_from(explain_options: &FirestoreExplainOptions) -> Result<Self, Self::Error> {
Ok(ExplainOptions {
analyze: explain_options.analyze.unwrap_or(false),
})
}
}

0 comments on commit 94dd224

Please sign in to comment.