From 94dd2244f8b4e2be836a2c412deb9790663cba67 Mon Sep 17 00:00:00 2001 From: Abdulla Abdurakhmanov Date: Tue, 2 Apr 2024 19:39:02 +0200 Subject: [PATCH] Explain options support --- src/db/query.rs | 6 +++++- src/db/query_models.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/db/query.rs b/src/db/query.rs index 67ba7ab..9dc5338 100644 --- a/src/db/query.rs +++ b/src/db/query.rs @@ -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, })) } diff --git a/src/db/query_models.rs b/src/db/query_models.rs index 42a1ac1..517f621 100644 --- a/src/db/query_models.rs +++ b/src/db/query_models.rs @@ -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; @@ -37,6 +38,7 @@ pub struct FirestoreQueryParams { pub return_only_fields: Option>, pub start_at: Option, pub end_at: Option, + pub explain_options: Option, } impl From for StructuredQuery { @@ -409,3 +411,17 @@ pub struct FirestorePartition { pub start_at: Option, pub end_at: Option, } + +#[derive(Debug, PartialEq, Clone, Builder)] +pub struct FirestoreExplainOptions { + pub analyze: Option, +} + +impl TryFrom<&FirestoreExplainOptions> for gcloud_sdk::google::firestore::v1::ExplainOptions { + type Error = FirestoreError; + fn try_from(explain_options: &FirestoreExplainOptions) -> Result { + Ok(ExplainOptions { + analyze: explain_options.analyze.unwrap_or(false), + }) + } +}