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