Skip to main content

couchbase_core/options/
query.rs

1/*
2 *
3 *  * Copyright (c) 2025 Couchbase, Inc.
4 *  *
5 *  * Licensed under the Apache License, Version 2.0 (the "License");
6 *  * you may not use this file except in compliance with the License.
7 *  * You may obtain a copy of the License at
8 *  *
9 *  *    http://www.apache.org/licenses/LICENSE-2.0
10 *  *
11 *  * Unless required by applicable law or agreed to in writing, software
12 *  * distributed under the License is distributed on an "AS IS" BASIS,
13 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  * See the License for the specific language governing permissions and
15 *  * limitations under the License.
16 *
17 */
18
19use serde_json::Value;
20use std::collections::HashMap;
21use std::sync::Arc;
22use std::time::Duration;
23
24use crate::httpx::request::OnBehalfOfInfo;
25use crate::queryx;
26pub use crate::queryx::ensure_index_helper::DesiredState;
27use crate::queryx::query_options::{FullScanVectors, SparseScanVectors};
28use crate::retry::{RetryStrategy, DEFAULT_RETRY_STRATEGY};
29
30#[derive(Debug, Clone)]
31#[non_exhaustive]
32pub struct QueryOptions {
33    pub args: Option<Vec<Value>>,
34    pub atr_collection: Option<String>,
35    pub auto_execute: Option<bool>,
36    pub client_context_id: Option<String>,
37    pub compression: Option<queryx::query_options::Compression>,
38    pub controls: Option<bool>,
39    pub creds: Option<Vec<queryx::query_options::CredsJson>>,
40    pub durability_level: Option<queryx::query_options::DurabilityLevel>,
41    pub encoded_plan: Option<String>,
42    pub encoding: Option<queryx::query_options::Encoding>,
43    pub format: Option<queryx::query_options::Format>,
44    pub kv_timeout: Option<Duration>,
45    pub max_parallelism: Option<u32>,
46    pub memory_quota: Option<u32>,
47    pub metrics: Option<bool>,
48    pub namespace: Option<String>,
49    pub num_atrs: Option<u32>,
50    pub pipeline_batch: Option<u32>,
51    pub pipeline_cap: Option<u32>,
52    pub prepared: Option<String>,
53    pub preserve_expiry: Option<bool>,
54    pub pretty: Option<bool>,
55    pub profile: Option<queryx::query_options::ProfileMode>,
56    pub query_context: Option<String>,
57    pub read_only: Option<bool>,
58    pub scan_cap: Option<u32>,
59    pub scan_consistency: Option<queryx::query_options::ScanConsistency>,
60    pub sparse_scan_vector: Option<SparseScanVectors>,
61    pub full_scan_vector: Option<FullScanVectors>,
62    pub sparse_scan_vectors: Option<HashMap<String, SparseScanVectors>>,
63    pub full_scan_vectors: Option<HashMap<String, FullScanVectors>>,
64    pub scan_wait: Option<Duration>,
65    pub signature: Option<bool>,
66    pub statement: Option<String>,
67    pub timeout: Option<Duration>,
68    pub tx_data: Option<Vec<u8>>,
69    pub tx_id: Option<String>,
70    pub tx_implicit: Option<bool>,
71    pub tx_stmt_num: Option<u32>,
72    pub tx_timeout: Option<Duration>,
73    pub use_cbo: Option<bool>,
74    pub use_fts: Option<bool>,
75    pub use_replica: Option<queryx::query_options::ReplicaLevel>,
76
77    pub named_args: Option<HashMap<String, Value>>,
78    pub raw: Option<HashMap<String, Value>>,
79
80    pub on_behalf_of: Option<OnBehalfOfInfo>,
81    pub endpoint: Option<String>,
82    pub retry_strategy: Arc<dyn RetryStrategy>,
83}
84
85impl Default for QueryOptions {
86    fn default() -> Self {
87        Self {
88            args: None,
89            atr_collection: None,
90            auto_execute: None,
91            client_context_id: None,
92            compression: None,
93            controls: None,
94            creds: None,
95            durability_level: None,
96            encoded_plan: None,
97            encoding: None,
98            format: None,
99            kv_timeout: None,
100            max_parallelism: None,
101            memory_quota: None,
102            metrics: None,
103            namespace: None,
104            num_atrs: None,
105            pipeline_batch: None,
106            pipeline_cap: None,
107            prepared: None,
108            preserve_expiry: None,
109            pretty: None,
110            profile: None,
111            query_context: None,
112            read_only: None,
113            scan_cap: None,
114            scan_consistency: None,
115            sparse_scan_vector: None,
116            full_scan_vector: None,
117            sparse_scan_vectors: None,
118            full_scan_vectors: None,
119            scan_wait: None,
120            signature: None,
121            statement: None,
122            timeout: None,
123            tx_data: None,
124            tx_id: None,
125            tx_implicit: None,
126            tx_stmt_num: None,
127            tx_timeout: None,
128            use_cbo: None,
129            use_fts: None,
130            use_replica: None,
131            named_args: None,
132            raw: None,
133            on_behalf_of: None,
134            endpoint: None,
135            retry_strategy: DEFAULT_RETRY_STRATEGY.clone(),
136        }
137    }
138}
139
140impl QueryOptions {
141    pub fn new() -> Self {
142        Default::default()
143    }
144
145    pub fn args(mut self, args: impl Into<Option<Vec<Value>>>) -> Self {
146        self.args = args.into();
147        self
148    }
149
150    pub fn atr_collection(mut self, atr_collection: impl Into<Option<String>>) -> Self {
151        self.atr_collection = atr_collection.into();
152        self
153    }
154
155    pub fn auto_execute(mut self, auto_execute: impl Into<Option<bool>>) -> Self {
156        self.auto_execute = auto_execute.into();
157        self
158    }
159
160    pub fn client_context_id(mut self, client_context_id: impl Into<Option<String>>) -> Self {
161        self.client_context_id = client_context_id.into();
162        self
163    }
164
165    pub fn compression(
166        mut self,
167        compression: impl Into<Option<queryx::query_options::Compression>>,
168    ) -> Self {
169        self.compression = compression.into();
170        self
171    }
172
173    pub fn controls(mut self, controls: impl Into<Option<bool>>) -> Self {
174        self.controls = controls.into();
175        self
176    }
177
178    pub fn creds(
179        mut self,
180        creds: impl Into<Option<Vec<queryx::query_options::CredsJson>>>,
181    ) -> Self {
182        self.creds = creds.into();
183        self
184    }
185
186    pub fn durability_level(
187        mut self,
188        durability_level: impl Into<Option<queryx::query_options::DurabilityLevel>>,
189    ) -> Self {
190        self.durability_level = durability_level.into();
191        self
192    }
193
194    pub fn encoded_plan(mut self, encoded_plan: impl Into<Option<String>>) -> Self {
195        self.encoded_plan = encoded_plan.into();
196        self
197    }
198
199    pub fn encoding(
200        mut self,
201        encoding: impl Into<Option<queryx::query_options::Encoding>>,
202    ) -> Self {
203        self.encoding = encoding.into();
204        self
205    }
206
207    pub fn format(mut self, format: impl Into<Option<queryx::query_options::Format>>) -> Self {
208        self.format = format.into();
209        self
210    }
211
212    pub fn kv_timeout(mut self, kv_timeout: impl Into<Option<Duration>>) -> Self {
213        self.kv_timeout = kv_timeout.into();
214        self
215    }
216
217    pub fn max_parallelism(mut self, max_parallelism: impl Into<Option<u32>>) -> Self {
218        self.max_parallelism = max_parallelism.into();
219        self
220    }
221
222    pub fn memory_quota(mut self, memory_quota: impl Into<Option<u32>>) -> Self {
223        self.memory_quota = memory_quota.into();
224        self
225    }
226
227    pub fn metrics(mut self, metrics: impl Into<Option<bool>>) -> Self {
228        self.metrics = metrics.into();
229        self
230    }
231
232    pub fn namespace(mut self, namespace: impl Into<Option<String>>) -> Self {
233        self.namespace = namespace.into();
234        self
235    }
236
237    pub fn num_atrs(mut self, num_atrs: impl Into<Option<u32>>) -> Self {
238        self.num_atrs = num_atrs.into();
239        self
240    }
241
242    pub fn pipeline_batch(mut self, pipeline_batch: impl Into<Option<u32>>) -> Self {
243        self.pipeline_batch = pipeline_batch.into();
244        self
245    }
246
247    pub fn pipeline_cap(mut self, pipeline_cap: impl Into<Option<u32>>) -> Self {
248        self.pipeline_cap = pipeline_cap.into();
249        self
250    }
251
252    pub fn prepared(mut self, prepared: impl Into<Option<String>>) -> Self {
253        self.prepared = prepared.into();
254        self
255    }
256
257    pub fn preserve_expiry(mut self, preserve_expiry: impl Into<Option<bool>>) -> Self {
258        self.preserve_expiry = preserve_expiry.into();
259        self
260    }
261
262    pub fn pretty(mut self, pretty: impl Into<Option<bool>>) -> Self {
263        self.pretty = pretty.into();
264        self
265    }
266
267    pub fn profile(
268        mut self,
269        profile: impl Into<Option<queryx::query_options::ProfileMode>>,
270    ) -> Self {
271        self.profile = profile.into();
272        self
273    }
274
275    pub fn query_context(mut self, query_context: impl Into<Option<String>>) -> Self {
276        self.query_context = query_context.into();
277        self
278    }
279
280    pub fn read_only(mut self, read_only: impl Into<Option<bool>>) -> Self {
281        self.read_only = read_only.into();
282        self
283    }
284
285    pub fn scan_cap(mut self, scan_cap: impl Into<Option<u32>>) -> Self {
286        self.scan_cap = scan_cap.into();
287        self
288    }
289
290    pub fn scan_consistency(
291        mut self,
292        scan_consistency: impl Into<Option<queryx::query_options::ScanConsistency>>,
293    ) -> Self {
294        self.scan_consistency = scan_consistency.into();
295        self
296    }
297
298    pub fn sparse_scan_vector(
299        mut self,
300        sparse_scan_vector: impl Into<Option<SparseScanVectors>>,
301    ) -> Self {
302        self.sparse_scan_vector = sparse_scan_vector.into();
303        self
304    }
305
306    pub fn full_scan_vector(
307        mut self,
308        full_scan_vector: impl Into<Option<FullScanVectors>>,
309    ) -> Self {
310        self.full_scan_vector = full_scan_vector.into();
311        self
312    }
313
314    pub fn sparse_scan_vectors(
315        mut self,
316        sparse_scan_vectors: impl Into<Option<HashMap<String, SparseScanVectors>>>,
317    ) -> Self {
318        self.sparse_scan_vectors = sparse_scan_vectors.into();
319        self
320    }
321
322    pub fn full_scan_vectors(
323        mut self,
324        full_scan_vectors: impl Into<Option<HashMap<String, FullScanVectors>>>,
325    ) -> Self {
326        self.full_scan_vectors = full_scan_vectors.into();
327        self
328    }
329
330    pub fn scan_wait(mut self, scan_wait: impl Into<Option<Duration>>) -> Self {
331        self.scan_wait = scan_wait.into();
332        self
333    }
334
335    pub fn signature(mut self, signature: impl Into<Option<bool>>) -> Self {
336        self.signature = signature.into();
337        self
338    }
339
340    pub fn statement(mut self, statement: impl Into<Option<String>>) -> Self {
341        self.statement = statement.into();
342        self
343    }
344
345    pub fn timeout(mut self, timeout: impl Into<Option<Duration>>) -> Self {
346        self.timeout = timeout.into();
347        self
348    }
349
350    pub fn tx_data(mut self, tx_data: impl Into<Option<Vec<u8>>>) -> Self {
351        self.tx_data = tx_data.into();
352        self
353    }
354
355    pub fn tx_id(mut self, tx_id: impl Into<Option<String>>) -> Self {
356        self.tx_id = tx_id.into();
357        self
358    }
359
360    pub fn tx_implicit(mut self, tx_implicit: impl Into<Option<bool>>) -> Self {
361        self.tx_implicit = tx_implicit.into();
362        self
363    }
364
365    pub fn tx_stmt_num(mut self, tx_stmt_num: impl Into<Option<u32>>) -> Self {
366        self.tx_stmt_num = tx_stmt_num.into();
367        self
368    }
369
370    pub fn tx_timeout(mut self, tx_timeout: impl Into<Option<Duration>>) -> Self {
371        self.tx_timeout = tx_timeout.into();
372        self
373    }
374
375    pub fn use_cbo(mut self, use_cbo: impl Into<Option<bool>>) -> Self {
376        self.use_cbo = use_cbo.into();
377        self
378    }
379
380    pub fn use_fts(mut self, use_fts: impl Into<Option<bool>>) -> Self {
381        self.use_fts = use_fts.into();
382        self
383    }
384
385    pub fn use_replica(
386        mut self,
387        use_replica: impl Into<Option<queryx::query_options::ReplicaLevel>>,
388    ) -> Self {
389        self.use_replica = use_replica.into();
390        self
391    }
392
393    pub fn named_args(mut self, named_args: impl Into<Option<HashMap<String, Value>>>) -> Self {
394        self.named_args = named_args.into();
395        self
396    }
397
398    pub fn raw(mut self, raw: impl Into<Option<HashMap<String, Value>>>) -> Self {
399        self.raw = raw.into();
400        self
401    }
402
403    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<Option<OnBehalfOfInfo>>) -> Self {
404        self.on_behalf_of = on_behalf_of.into();
405        self
406    }
407
408    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
409        self.retry_strategy = retry_strategy;
410        self
411    }
412
413    pub fn endpoint(mut self, endpoint: impl Into<Option<String>>) -> Self {
414        self.endpoint = endpoint.into();
415        self
416    }
417}
418
419impl From<QueryOptions> for queryx::query_options::QueryOptions {
420    fn from(opts: QueryOptions) -> Self {
421        queryx::query_options::QueryOptions {
422            args: opts.args,
423            atr_collection: opts.atr_collection,
424            auto_execute: opts.auto_execute,
425            client_context_id: opts.client_context_id,
426            compression: opts.compression,
427            controls: opts.controls,
428            creds: opts.creds,
429            durability_level: opts.durability_level,
430            encoded_plan: opts.encoded_plan,
431            encoding: opts.encoding,
432            format: opts.format,
433            kv_timeout: opts.kv_timeout,
434            max_parallelism: opts.max_parallelism,
435            memory_quota: opts.memory_quota,
436            metrics: opts.metrics,
437            namespace: opts.namespace,
438            num_atrs: opts.num_atrs,
439            pipeline_batch: opts.pipeline_batch,
440            pipeline_cap: opts.pipeline_cap,
441            prepared: opts.prepared,
442            preserve_expiry: opts.preserve_expiry,
443            pretty: opts.pretty,
444            profile: opts.profile,
445            query_context: opts.query_context,
446            read_only: opts.read_only,
447            scan_cap: opts.scan_cap,
448            scan_consistency: opts.scan_consistency,
449            sparse_scan_vector: opts.sparse_scan_vector,
450            full_scan_vector: opts.full_scan_vector,
451            sparse_scan_vectors: opts.sparse_scan_vectors,
452            full_scan_vectors: opts.full_scan_vectors,
453            scan_wait: opts.scan_wait,
454            signature: opts.signature,
455            statement: opts.statement,
456            timeout: opts.timeout,
457            tx_data: opts.tx_data,
458            tx_id: opts.tx_id,
459            tx_implicit: opts.tx_implicit,
460            tx_stmt_num: opts.tx_stmt_num,
461            tx_timeout: opts.tx_timeout,
462            use_cbo: opts.use_cbo,
463            use_fts: opts.use_fts,
464            use_replica: opts.use_replica,
465
466            named_args: opts.named_args,
467            raw: opts.raw,
468
469            on_behalf_of: opts.on_behalf_of,
470        }
471    }
472}
473
474#[derive(Debug, Clone)]
475#[non_exhaustive]
476pub struct GetAllIndexesOptions<'a> {
477    pub bucket_name: &'a str,
478    pub scope_name: Option<&'a str>,
479    pub collection_name: Option<&'a str>,
480    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
481    pub endpoint: Option<String>,
482    pub retry_strategy: Arc<dyn RetryStrategy>,
483}
484
485impl<'a> GetAllIndexesOptions<'a> {
486    pub fn new(bucket_name: &'a str) -> Self {
487        Self {
488            bucket_name,
489            scope_name: None,
490            collection_name: None,
491            on_behalf_of: None,
492            endpoint: None,
493            retry_strategy: DEFAULT_RETRY_STRATEGY.clone(),
494        }
495    }
496
497    pub fn scope_name(mut self, scope_name: &'a str) -> Self {
498        self.scope_name = Some(scope_name);
499        self
500    }
501
502    pub fn collection_name(mut self, collection_name: &'a str) -> Self {
503        self.collection_name = Some(collection_name);
504        self
505    }
506
507    pub fn on_behalf_of(mut self, on_behalf_of: &'a OnBehalfOfInfo) -> Self {
508        self.on_behalf_of = Some(on_behalf_of);
509        self
510    }
511
512    pub fn endpoint(mut self, endpoint: String) -> Self {
513        self.endpoint = Some(endpoint);
514        self
515    }
516
517    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
518        self.retry_strategy = retry_strategy;
519        self
520    }
521}
522
523impl<'a> From<&GetAllIndexesOptions<'a>> for queryx::query_options::GetAllIndexesOptions<'a> {
524    fn from(opts: &GetAllIndexesOptions<'a>) -> Self {
525        queryx::query_options::GetAllIndexesOptions {
526            bucket_name: opts.bucket_name,
527            scope_name: opts.scope_name,
528            collection_name: opts.collection_name,
529            on_behalf_of: opts.on_behalf_of,
530        }
531    }
532}
533
534#[derive(Debug, Clone)]
535#[non_exhaustive]
536pub struct CreatePrimaryIndexOptions<'a> {
537    pub bucket_name: &'a str,
538    pub scope_name: Option<&'a str>,
539    pub collection_name: Option<&'a str>,
540    pub index_name: Option<&'a str>,
541    pub num_replicas: Option<u32>,
542    pub deferred: Option<bool>,
543    pub ignore_if_exists: Option<bool>,
544    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
545    pub endpoint: Option<String>,
546    pub retry_strategy: Arc<dyn RetryStrategy>,
547}
548
549impl<'a> CreatePrimaryIndexOptions<'a> {
550    pub fn new(bucket_name: &'a str) -> Self {
551        Self {
552            bucket_name,
553            scope_name: None,
554            collection_name: None,
555            index_name: None,
556            num_replicas: None,
557            deferred: None,
558            ignore_if_exists: None,
559            on_behalf_of: None,
560            endpoint: None,
561            retry_strategy: DEFAULT_RETRY_STRATEGY.clone(),
562        }
563    }
564
565    pub fn scope_name(mut self, scope_name: &'a str) -> Self {
566        self.scope_name = Some(scope_name);
567        self
568    }
569
570    pub fn collection_name(mut self, collection_name: &'a str) -> Self {
571        self.collection_name = Some(collection_name);
572        self
573    }
574
575    pub fn index_name(mut self, index_name: &'a str) -> Self {
576        self.index_name = Some(index_name);
577        self
578    }
579
580    pub fn num_replicas(mut self, num_replicas: u32) -> Self {
581        self.num_replicas = Some(num_replicas);
582        self
583    }
584
585    pub fn deferred(mut self, deferred: bool) -> Self {
586        self.deferred = Some(deferred);
587        self
588    }
589
590    pub fn ignore_if_exists(mut self, ignore_if_exists: bool) -> Self {
591        self.ignore_if_exists = Some(ignore_if_exists);
592        self
593    }
594
595    pub fn on_behalf_of(mut self, on_behalf_of: &'a OnBehalfOfInfo) -> Self {
596        self.on_behalf_of = Some(on_behalf_of);
597        self
598    }
599
600    pub fn endpoint(mut self, endpoint: String) -> Self {
601        self.endpoint = Some(endpoint);
602        self
603    }
604
605    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
606        self.retry_strategy = retry_strategy;
607        self
608    }
609}
610
611impl<'a> From<&CreatePrimaryIndexOptions<'a>>
612    for queryx::query_options::CreatePrimaryIndexOptions<'a>
613{
614    fn from(opts: &CreatePrimaryIndexOptions<'a>) -> Self {
615        queryx::query_options::CreatePrimaryIndexOptions {
616            bucket_name: opts.bucket_name,
617            scope_name: opts.scope_name,
618            collection_name: opts.collection_name,
619            index_name: opts.index_name,
620            num_replicas: opts.num_replicas,
621            deferred: opts.deferred,
622            ignore_if_exists: opts.ignore_if_exists,
623            on_behalf_of: opts.on_behalf_of,
624        }
625    }
626}
627
628#[derive(Debug, Clone)]
629#[non_exhaustive]
630pub struct CreateIndexOptions<'a> {
631    pub bucket_name: &'a str,
632    pub scope_name: Option<&'a str>,
633    pub collection_name: Option<&'a str>,
634    pub index_name: &'a str,
635    pub num_replicas: Option<u32>,
636    pub fields: &'a [&'a str],
637    pub deferred: Option<bool>,
638    pub ignore_if_exists: Option<bool>,
639    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
640    pub endpoint: Option<String>,
641    pub retry_strategy: Arc<dyn RetryStrategy>,
642}
643
644impl<'a> CreateIndexOptions<'a> {
645    pub fn new(bucket_name: &'a str, index_name: &'a str, fields: &'a [&'a str]) -> Self {
646        Self {
647            bucket_name,
648            scope_name: None,
649            collection_name: None,
650            index_name,
651            num_replicas: None,
652            fields,
653            deferred: None,
654            ignore_if_exists: None,
655            on_behalf_of: None,
656            endpoint: None,
657            retry_strategy: DEFAULT_RETRY_STRATEGY.clone(),
658        }
659    }
660
661    pub fn scope_name(mut self, scope_name: &'a str) -> Self {
662        self.scope_name = Some(scope_name);
663        self
664    }
665
666    pub fn collection_name(mut self, collection_name: &'a str) -> Self {
667        self.collection_name = Some(collection_name);
668        self
669    }
670
671    pub fn num_replicas(mut self, num_replicas: u32) -> Self {
672        self.num_replicas = Some(num_replicas);
673        self
674    }
675
676    pub fn deferred(mut self, deferred: bool) -> Self {
677        self.deferred = Some(deferred);
678        self
679    }
680
681    pub fn ignore_if_exists(mut self, ignore_if_exists: bool) -> Self {
682        self.ignore_if_exists = Some(ignore_if_exists);
683        self
684    }
685
686    pub fn on_behalf_of(mut self, on_behalf_of: &'a OnBehalfOfInfo) -> Self {
687        self.on_behalf_of = Some(on_behalf_of);
688        self
689    }
690
691    pub fn endpoint(mut self, endpoint: String) -> Self {
692        self.endpoint = Some(endpoint);
693        self
694    }
695
696    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
697        self.retry_strategy = retry_strategy;
698        self
699    }
700}
701
702impl<'a> From<&CreateIndexOptions<'a>> for queryx::query_options::CreateIndexOptions<'a> {
703    fn from(opts: &CreateIndexOptions<'a>) -> Self {
704        queryx::query_options::CreateIndexOptions {
705            bucket_name: opts.bucket_name,
706            scope_name: opts.scope_name,
707            collection_name: opts.collection_name,
708            index_name: opts.index_name,
709            num_replicas: opts.num_replicas,
710            fields: opts.fields,
711            deferred: opts.deferred,
712            ignore_if_exists: opts.ignore_if_exists,
713            on_behalf_of: opts.on_behalf_of,
714        }
715    }
716}
717
718#[derive(Debug, Clone)]
719#[non_exhaustive]
720pub struct DropPrimaryIndexOptions<'a> {
721    pub bucket_name: &'a str,
722    pub scope_name: Option<&'a str>,
723    pub collection_name: Option<&'a str>,
724    pub index_name: Option<&'a str>,
725    pub ignore_if_not_exists: Option<bool>,
726    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
727    pub endpoint: Option<String>,
728    pub retry_strategy: Arc<dyn RetryStrategy>,
729}
730
731impl<'a> DropPrimaryIndexOptions<'a> {
732    pub fn new(bucket_name: &'a str) -> Self {
733        Self {
734            bucket_name,
735            scope_name: None,
736            collection_name: None,
737            index_name: None,
738            ignore_if_not_exists: None,
739            on_behalf_of: None,
740            endpoint: None,
741            retry_strategy: DEFAULT_RETRY_STRATEGY.clone(),
742        }
743    }
744
745    pub fn scope_name(mut self, scope_name: &'a str) -> Self {
746        self.scope_name = Some(scope_name);
747        self
748    }
749
750    pub fn collection_name(mut self, collection_name: &'a str) -> Self {
751        self.collection_name = Some(collection_name);
752        self
753    }
754
755    pub fn index_name(mut self, index_name: &'a str) -> Self {
756        self.index_name = Some(index_name);
757        self
758    }
759
760    pub fn ignore_if_not_exists(mut self, ignore_if_not_exists: bool) -> Self {
761        self.ignore_if_not_exists = Some(ignore_if_not_exists);
762        self
763    }
764
765    pub fn on_behalf_of(mut self, on_behalf_of: &'a OnBehalfOfInfo) -> Self {
766        self.on_behalf_of = Some(on_behalf_of);
767        self
768    }
769
770    pub fn endpoint(mut self, endpoint: String) -> Self {
771        self.endpoint = Some(endpoint);
772        self
773    }
774
775    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
776        self.retry_strategy = retry_strategy;
777        self
778    }
779}
780
781impl<'a> From<&DropPrimaryIndexOptions<'a>> for queryx::query_options::DropPrimaryIndexOptions<'a> {
782    fn from(opts: &DropPrimaryIndexOptions<'a>) -> Self {
783        queryx::query_options::DropPrimaryIndexOptions {
784            bucket_name: opts.bucket_name,
785            scope_name: opts.scope_name,
786            collection_name: opts.collection_name,
787            index_name: opts.index_name,
788            ignore_if_not_exists: opts.ignore_if_not_exists,
789            on_behalf_of: opts.on_behalf_of,
790        }
791    }
792}
793
794#[derive(Debug, Clone)]
795#[non_exhaustive]
796pub struct DropIndexOptions<'a> {
797    pub bucket_name: &'a str,
798    pub scope_name: Option<&'a str>,
799    pub collection_name: Option<&'a str>,
800    pub index_name: &'a str,
801    pub ignore_if_not_exists: Option<bool>,
802    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
803    pub endpoint: Option<String>,
804    pub retry_strategy: Arc<dyn RetryStrategy>,
805}
806
807impl<'a> DropIndexOptions<'a> {
808    pub fn new(bucket_name: &'a str, index_name: &'a str) -> Self {
809        Self {
810            bucket_name,
811            scope_name: None,
812            collection_name: None,
813            index_name,
814            ignore_if_not_exists: None,
815            on_behalf_of: None,
816            endpoint: None,
817            retry_strategy: DEFAULT_RETRY_STRATEGY.clone(),
818        }
819    }
820
821    pub fn scope_name(mut self, scope_name: &'a str) -> Self {
822        self.scope_name = Some(scope_name);
823        self
824    }
825
826    pub fn collection_name(mut self, collection_name: &'a str) -> Self {
827        self.collection_name = Some(collection_name);
828        self
829    }
830
831    pub fn ignore_if_not_exists(mut self, ignore_if_not_exists: bool) -> Self {
832        self.ignore_if_not_exists = Some(ignore_if_not_exists);
833        self
834    }
835
836    pub fn on_behalf_of(mut self, on_behalf_of: &'a OnBehalfOfInfo) -> Self {
837        self.on_behalf_of = Some(on_behalf_of);
838        self
839    }
840
841    pub fn endpoint(mut self, endpoint: String) -> Self {
842        self.endpoint = Some(endpoint);
843        self
844    }
845
846    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
847        self.retry_strategy = retry_strategy;
848        self
849    }
850}
851
852impl<'a> From<&DropIndexOptions<'a>> for queryx::query_options::DropIndexOptions<'a> {
853    fn from(opts: &DropIndexOptions<'a>) -> Self {
854        queryx::query_options::DropIndexOptions {
855            bucket_name: opts.bucket_name,
856            scope_name: opts.scope_name,
857            collection_name: opts.collection_name,
858            index_name: opts.index_name,
859            ignore_if_not_exists: opts.ignore_if_not_exists,
860            on_behalf_of: opts.on_behalf_of,
861        }
862    }
863}
864
865#[derive(Debug, Clone)]
866#[non_exhaustive]
867pub struct BuildDeferredIndexesOptions<'a> {
868    pub bucket_name: &'a str,
869    pub scope_name: Option<&'a str>,
870    pub collection_name: Option<&'a str>,
871    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
872    pub endpoint: Option<String>,
873    pub retry_strategy: Arc<dyn RetryStrategy>,
874}
875
876impl<'a> BuildDeferredIndexesOptions<'a> {
877    pub fn new(bucket_name: &'a str) -> Self {
878        Self {
879            bucket_name,
880            scope_name: None,
881            collection_name: None,
882            on_behalf_of: None,
883            endpoint: None,
884            retry_strategy: DEFAULT_RETRY_STRATEGY.clone(),
885        }
886    }
887
888    pub fn scope_name(mut self, scope_name: &'a str) -> Self {
889        self.scope_name = Some(scope_name);
890        self
891    }
892
893    pub fn collection_name(mut self, collection_name: &'a str) -> Self {
894        self.collection_name = Some(collection_name);
895        self
896    }
897
898    pub fn on_behalf_of(mut self, on_behalf_of: &'a OnBehalfOfInfo) -> Self {
899        self.on_behalf_of = Some(on_behalf_of);
900        self
901    }
902
903    pub fn endpoint(mut self, endpoint: String) -> Self {
904        self.endpoint = Some(endpoint);
905        self
906    }
907
908    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
909        self.retry_strategy = retry_strategy;
910        self
911    }
912}
913
914impl<'a> From<&BuildDeferredIndexesOptions<'a>>
915    for queryx::query_options::BuildDeferredIndexesOptions<'a>
916{
917    fn from(opts: &BuildDeferredIndexesOptions<'a>) -> Self {
918        queryx::query_options::BuildDeferredIndexesOptions {
919            bucket_name: opts.bucket_name,
920            scope_name: opts.scope_name,
921            collection_name: opts.collection_name,
922            on_behalf_of: opts.on_behalf_of,
923        }
924    }
925}
926
927#[derive(Debug, Clone)]
928#[non_exhaustive]
929pub struct WatchIndexesOptions<'a> {
930    pub bucket_name: &'a str,
931    pub scope_name: Option<&'a str>,
932    pub collection_name: Option<&'a str>,
933    pub indexes: &'a [&'a str],
934    pub watch_primary: Option<bool>,
935    pub on_behalf_of: Option<&'a OnBehalfOfInfo>,
936    pub endpoint: Option<String>,
937    pub retry_strategy: Arc<dyn RetryStrategy>,
938}
939
940impl<'a> WatchIndexesOptions<'a> {
941    pub fn new(bucket_name: &'a str, indexes: &'a [&'a str]) -> Self {
942        Self {
943            bucket_name,
944            scope_name: None,
945            collection_name: None,
946            indexes,
947            watch_primary: None,
948            on_behalf_of: None,
949            endpoint: None,
950            retry_strategy: DEFAULT_RETRY_STRATEGY.clone(),
951        }
952    }
953
954    pub fn scope_name(mut self, scope_name: &'a str) -> Self {
955        self.scope_name = Some(scope_name);
956        self
957    }
958
959    pub fn collection_name(mut self, collection_name: &'a str) -> Self {
960        self.collection_name = Some(collection_name);
961        self
962    }
963
964    pub fn watch_primary(mut self, watch_primary: bool) -> Self {
965        self.watch_primary = Some(watch_primary);
966        self
967    }
968
969    pub fn on_behalf_of(mut self, on_behalf_of: &'a OnBehalfOfInfo) -> Self {
970        self.on_behalf_of = Some(on_behalf_of);
971        self
972    }
973
974    pub fn endpoint(mut self, endpoint: String) -> Self {
975        self.endpoint = Some(endpoint);
976        self
977    }
978
979    pub fn retry_strategy(mut self, retry_strategy: Arc<dyn RetryStrategy>) -> Self {
980        self.retry_strategy = retry_strategy;
981        self
982    }
983}
984
985impl<'a> From<&WatchIndexesOptions<'a>> for queryx::query_options::WatchIndexesOptions<'a> {
986    fn from(opts: &WatchIndexesOptions<'a>) -> Self {
987        queryx::query_options::WatchIndexesOptions {
988            bucket_name: opts.bucket_name,
989            scope_name: opts.scope_name,
990            collection_name: opts.collection_name,
991            indexes: opts.indexes,
992            watch_primary: opts.watch_primary,
993            on_behalf_of: opts.on_behalf_of,
994        }
995    }
996}
997
998#[derive(Debug, Clone)]
999#[non_exhaustive]
1000pub struct EnsureIndexOptions<'a> {
1001    pub index_name: &'a str,
1002    pub bucket_name: &'a str,
1003    pub scope_name: Option<&'a str>,
1004    pub collection_name: Option<&'a str>,
1005    pub on_behalf_of_info: Option<&'a OnBehalfOfInfo>,
1006    pub desired_state: DesiredState,
1007}
1008
1009impl<'a> EnsureIndexOptions<'a> {
1010    pub fn new(
1011        index_name: &'a str,
1012        bucket_name: &'a str,
1013        scope_name: Option<&'a str>,
1014        collection_name: Option<&'a str>,
1015        desired_state: DesiredState,
1016    ) -> Self {
1017        Self {
1018            index_name,
1019            bucket_name,
1020            scope_name,
1021            collection_name,
1022            on_behalf_of_info: None,
1023            desired_state,
1024        }
1025    }
1026}