unreql 0.2.1

Well documented and easy to use RethinkDB Rust Driver
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
use std::{borrow::Cow, collections::HashMap};

use serde::{Serialize, Serializer};
use serde_with::skip_serializing_none;
use unreql_macros::{OptionsBuilder, WithOpts};

use crate::{r, Command};

use super::args;

#[derive(Debug)]
pub struct Index(pub(crate) Command);

impl args::WithOpts for Index {
    fn with_opts(self, cmd: Command) -> Command {
        cmd.with_opts(self.0)
    }
}

#[derive(Debug, Clone, Copy, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[serde(rename_all = "lowercase")]
pub enum Durability {
    Hard,
    Soft,
}

#[derive(Debug, Clone, Copy, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[serde(rename_all = "lowercase")]
pub enum ReadMode {
    Single,
    Majority,
    Outdated,
}

#[skip_serializing_none]
#[derive(Debug, Clone, OptionsBuilder, Serialize, Default, PartialEq, PartialOrd)]
#[non_exhaustive]
pub struct RunOptions {
    /// One of three possible values affecting the consistency guarantee for the query (default: `single`).
    /// - `single` (the default) returns values that are in memory (but not necessarily written to disk) on the primary replica.
    /// - `majority` will only return values that are safely committed on disk on a majority of replicas. This requires sending a message to every replica on each read, so it is the slowest but most consistent.
    /// - `outdated` will return values that are in memory on an arbitrarily-selected replica. This is the fastest but least consistent.
    pub read_mode: Option<ReadMode>,
    /// What format to return times in (default: 'native'). Set this to 'raw' if you want times returned as JSON objects for exporting.
    pub time_format: Option<Format>,
    /// Whether or not to return a profile of the query’s execution (default: `false`).
    pub profile: Option<bool>,
    /// Possible values are `hard` and `soft`.
    /// In soft durability mode RethinkDB will acknowledge the write immediately after receiving it, but before the write has been committed to disk.
    pub durability: Option<Durability>,
    /// What format to return grouped_data and grouped_streams in (default: `native`). Set this to `raw` if you want the raw pseudotype.
    pub group_format: Option<Format>,
    /// Set to `true` to not receive the result object or cursor and return immediately.
    pub noreply: Option<bool>,
    /// The database to run this query against as a string.
    /// The default is the database specified in the db parameter to `connect` (which defaults to `test`).
    /// The database may also be specified with the `db` command.
    pub db: Option<Db>,
    /// The maximum numbers of array elements that can be returned by a query (default: 100,000).
    /// This affects all ReQL commands that return arrays.
    /// Note that it has no effect on the size of arrays being written to the database;
    /// those always have an upper limit of 100,000 elements.
    pub array_limit: Option<i64>,
    /// What format to return binary data in (default: `native`). Set this to `raw` if you want the raw pseudotype.
    pub binary_format: Option<Format>,
    /// Minimum number of rows to wait for before batching a result set (default: `8`). This is an integer.
    pub min_batch_rows: Option<i64>,
    /// Maximum number of rows to wait for before batching a result set (default: `unlimited`). This is an integer.
    pub max_batch_rows: Option<i64>,
    /// Maximum number of bytes to wait for before batching a result set (default: `1MB`). This is an integer.
    pub max_batch_bytes: Option<i64>,
    /// Maximum number of seconds to wait before batching a result set (default: `0.5`). This is a float (not an integer) and may be specified to the microsecond.
    pub max_batch_seconds: Option<f32>,
    /// Factor to scale the other parameters down by on the first batch (default: `4`).
    /// For example, with this set to 8 and `max_batch_rows` set to 80, on the first batch `max_batch_rows` will be adjusted to 10 (80 / 8).
    /// This allows the first batch to return faster.
    pub firt_batch_scaledown_factor: Option<i64>,
}

#[derive(Debug, Clone, Copy, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[non_exhaustive]
#[serde(rename_all = "lowercase")]
pub enum Format {
    Native,
    Raw,
}

#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Db(pub Cow<'static, str>);

impl Serialize for Db {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        let Self(name) = self;
        let cmd = r.db(name.clone());
        cmd.serialize(serializer)
    }
}

#[skip_serializing_none]
#[derive(Debug, Clone, Copy, Default, Serialize, WithOpts, OptionsBuilder)]
pub struct RandomOptions {
    pub float: Option<bool>,
}

#[skip_serializing_none]
#[derive(
    Debug, Clone, Copy, Serialize, Default, PartialEq, PartialOrd, WithOpts, OptionsBuilder,
)]
pub struct FilterOptions {
    // TODO implement for `true`, `false` and `r.error()`
    pub default: Option<bool>,
}

#[skip_serializing_none]
#[derive(
    Debug, Clone, Copy, Serialize, Default, PartialEq, PartialOrd, WithOpts, OptionsBuilder,
)]
pub struct TableOptions {
    pub read_mode: Option<ReadMode>,
    pub identifier_format: Option<IdentifierFormat>,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Copy, Serialize, PartialEq, PartialOrd)]
#[serde(rename_all = "lowercase")]
pub enum IdentifierFormat {
    Name,
    Uuid,
}

/// Optional arguments to `changes`
#[skip_serializing_none]
#[derive(
    Debug, Clone, Copy, Serialize, Default, PartialEq, PartialOrd, WithOpts, OptionsBuilder,
)]
pub struct ChangesOptions {
    /// Controls how change notifications are batched
    pub squash: Option<Squash>,
    /// The number of changes the server will buffer between client reads
    /// before it starts dropping changes and generates an error
    /// (default: 100,000).
    pub changefeed_queue_size: Option<u32>,
    /// If `true`, the changefeed stream will begin with the current contents
    /// of the table or selection being monitored. These initial results will
    /// have `new_val` fields, but no `old_val` fields. The initial results
    /// may be intermixed with actual changes, as long as an initial result
    /// for the changed document has already been given. If an initial result
    /// for a document has been sent and a change is made to that document
    /// that would move it to the unsent part of the result set (e.g., a
    /// changefeed monitors the top 100 posters, the first 50 have been sent,
    /// and poster 48 has become poster 52), an "uninitial" notification will
    /// be sent, with an `old_val` field but no `new_val` field.
    pub include_initial: Option<bool>,
    /// If `true`, the changefeed stream will include special status documents
    /// consisting of the field `state` and a string indicating a change in the
    /// feed's state. These documents can occur at any point in the feed between
    /// the notification documents described below. If `includeStates` is `false`
    /// (the default), the status documents will not be sent.
    pub include_states: Option<bool>,
    /// If `true`, a changefeed stream on an `order_by.limit` changefeed will
    /// include `old_offset` and `new_offset` fields in status documents that
    /// include `old_val` and `new_val`. This allows applications to maintain
    /// ordered lists of the stream's result set. If `old_offset` is set and not
    /// `null`, the element at `old_offset` is being deleted; if `new_offset` is
    /// set and not `null`, then `new_val` is being inserted at `new_offset`.
    /// Setting `include_offsets` to `true` on a changefeed that does not support
    /// it will raise an error.
    pub include_offsets: Option<bool>,
    /// If `true`, every result on a changefeed will include a `type` field with
    /// a string that indicates the kind of change the result represents:
    /// `add`, `remove`, `change`, `initial`, `uninitial`, `state`.
    /// Defaults to `false`.
    ///
    /// There are currently two states:
    ///
    /// * `{state: 'initializing'}` indicates the following documents represent
    /// initial values on the feed rather than changes. This will be the first
    /// document of a feed that returns initial values.
    /// * `{state: 'ready'}` indicates the following documents represent changes.
    /// This will be the first document of a feed that does *not* return initial
    /// values; otherwise, it will indicate the initial values have all been sent.
    pub include_types: Option<bool>,
}

/// Controls how change notifications are batched
#[derive(Debug, Clone, Copy, Serialize, PartialEq, PartialOrd)]
#[serde(untagged)]
pub enum Squash {
    /// `true`: When multiple changes to the same document occur before a
    /// batch of notifications is sent, the changes are "squashed" into one
    /// change. The client receives a notification that will bring it fully
    /// up to date with the server.
    /// `false`: All changes will be sent to the client verbatim. This is
    /// the default.
    Bool(bool),
    /// `n`: A numeric value (floating point). Similar to `true`, but the
    /// server will wait `n` seconds to respond in order to squash as many
    /// changes together as possible, reducing network traffic. The first
    /// batch will always be returned immediately.
    Float(f32),
}

#[derive(Debug, Clone, Default, PartialEq, WithOpts, OptionsBuilder)]
pub struct TableCreateOptions {
    pub primary_key: Option<Cow<'static, str>>,
    pub durability: Option<Durability>,
    pub shards: Option<u8>,
    pub replicas: Option<Replicas>,
}

#[derive(Debug, Clone, PartialEq)]
pub enum Replicas {
    Int(u8),
    Map {
        replicas: HashMap<Cow<'static, str>, u8>,
        primary_replica_tag: Cow<'static, str>,
    },
}

impl Serialize for TableCreateOptions {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        #[derive(Serialize)]
        struct InnerOptions<'a> {
            #[serde(skip_serializing_if = "Option::is_none")]
            primary_key: Option<&'a Cow<'static, str>>,
            #[serde(skip_serializing_if = "Option::is_none")]
            durability: Option<Durability>,
            #[serde(skip_serializing_if = "Option::is_none")]
            shards: Option<u8>,
            #[serde(skip_serializing_if = "Option::is_none")]
            replicas: Option<InnerReplicas<'a>>,
            #[serde(skip_serializing_if = "Option::is_none")]
            primary_replica_tag: Option<&'a Cow<'static, str>>,
        }

        #[derive(Serialize)]
        #[serde(untagged)]
        enum InnerReplicas<'a> {
            Int(u8),
            Map(&'a HashMap<Cow<'static, str>, u8>),
        }

        let (replicas, primary_replica_tag) = match &self.replicas {
            Some(Replicas::Int(i)) => (Some(InnerReplicas::Int(*i)), None),
            Some(Replicas::Map {
                replicas,
                primary_replica_tag,
            }) => (
                Some(InnerReplicas::Map(replicas)),
                Some(primary_replica_tag),
            ),
            None => (None, None),
        };

        let opts = InnerOptions {
            replicas,
            primary_replica_tag,
            primary_key: self.primary_key.as_ref(),
            durability: self.durability,
            shards: self.shards,
        };

        opts.serialize(serializer)
    }
}

#[skip_serializing_none]
#[derive(
    Debug, Clone, Copy, Serialize, Default, PartialEq, PartialOrd, WithOpts, OptionsBuilder,
)]
pub struct IndexCreateOptions {
    pub multi: Option<bool>,
    pub geo: Option<bool>,
}

#[skip_serializing_none]
#[derive(
    Debug, Clone, Copy, Serialize, Default, PartialEq, PartialOrd, WithOpts, OptionsBuilder,
)]
pub struct IndexRenameOptions {
    pub overwrite: Option<bool>,
}

#[skip_serializing_none]
#[derive(
    Debug, Clone, Copy, Serialize, Default, PartialEq, PartialOrd, WithOpts, OptionsBuilder,
)]
pub struct InsertOptions {
    /// possible values are hard and soft. This option will override the table or query’s durability setting (set in run).
    /// In soft durability mode RethinkDB will acknowledge the write immediately after receiving and caching it,
    /// but before the write has been committed to disk.
    pub durability: Option<Durability>,
    /// - `true`: return a `changes` array consisting of `old_val`/`new_val` objects describing the changes made,
    ///   only including the documents actually updated.
    /// - `false`: do not return a `changes` array (the default).
    /// - `"always"`: behave as `true`, but include all documents the command tried to update whether
    ///   or not the update was successful. (This was the behavior of true pre-2.0.)
    pub return_changes: Option<ReturnChanges>,
    /// Determine handling of inserting documents with the same primary key as existing entries.
    /// There are three built-in methods: `"error"`, `"replace"` or `"update"`; alternatively, you may provide a conflict resolution function
    /// - `"error"`: Do not insert the new document and record the conflict as an error. This is the default.
    /// - `"replace"`: Replace the old document in its entirety with the new one.
    /// - `"update"`: Update fields of the old document with fields from the new one.
    /// - `function (id, oldDoc, newDoc) { return resolvedDoc }`: a function that receives the id, old and new documents as arguments and returns a document which will be inserted in place of the conflicted one.
    pub conflict: Option<Conflict>,
    /// If true, and if the user has the config permission, ignores any write hook, inserting the document unmodified
    pub ignore_write_hook: Option<bool>,
}

#[derive(Debug, Clone, Copy, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[serde(rename_all = "lowercase")]
pub enum Conflict {
    Replace,
    Update,
    Error,
}

#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub enum ReturnChanges {
    Bool(bool),
    Always,
}

impl Serialize for ReturnChanges {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        match self {
            Self::Bool(boolean) => boolean.serialize(serializer),
            Self::Always => "always".serialize(serializer),
        }
    }
}

impl From<bool> for ReturnChanges {
    fn from(value: bool) -> Self {
        Self::Bool(value)
    }
}

#[skip_serializing_none]
#[derive(
    Debug, Clone, Copy, Serialize, Default, PartialEq, PartialOrd, WithOpts, OptionsBuilder,
)]
pub struct UpdateOptions {
    /// possible values are hard and soft. This option will override the table or query’s durability setting (set in run).
    /// In soft durability mode RethinkDB will acknowledge the write immediately after receiving and caching it,
    /// but before the write has been committed to disk.
    pub durability: Option<Durability>,
    /// - `true`: return a `changes` array consisting of `old_val`/`new_val` objects describing the changes made,
    ///   only including the documents actually updated.
    /// - `false`: do not return a `changes` array (the default).
    /// - `"always"`: behave as `true`, but include all documents the command tried to update whether
    ///   or not the update was successful. (This was the behavior of true pre-2.0.)
    pub return_changes: Option<ReturnChanges>,
    /// if set to `true`, executes the update and distributes the result to replicas
    /// in a non-atomic fashion. This flag is required to perform non-deterministic updates,
    /// such as those that require reading data from another table.
    pub non_atomic: Option<bool>,
    /// If `true`, and if the user has the config permission,
    /// ignores any write hook when performing the update.
    pub ignore_write_hook: Option<bool>,
}

#[skip_serializing_none]
#[derive(
    Debug, Clone, Copy, Serialize, Default, PartialEq, PartialOrd, WithOpts, OptionsBuilder,
)]
pub struct ReplaceOptions {
    /// possible values are hard and soft. This option will override the table or query’s durability setting (set in run).
    /// In soft durability mode RethinkDB will acknowledge the write immediately after receiving and caching it,
    /// but before the write has been committed to disk.
    pub durability: Option<Durability>,
    /// - `true`: return a `changes` array consisting of `old_val`/`new_val` objects describing the changes made,
    ///   only including the documents actually updated.
    /// - `false`: do not return a `changes` array (the default).
    /// - `"always"`: behave as `true`, but include all documents the command tried to update whether
    ///   or not the update was successful. (This was the behavior of true pre-2.0.)
    pub return_changes: Option<ReturnChanges>,
    /// if set to `true`, executes the update and distributes the result to replicas
    /// in a non-atomic fashion. This flag is required to perform non-deterministic updates,
    /// such as those that require reading data from another table.
    pub non_atomic: Option<bool>,
    /// If `true`, and if the user has the config permission,
    /// ignores any write hook when performing the update.
    pub ignore_write_hook: Option<bool>,
}

#[skip_serializing_none]
#[derive(
    Debug, Clone, Copy, Serialize, Default, PartialEq, PartialOrd, WithOpts, OptionsBuilder,
)]
pub struct DeleteOptions {
    /// possible values are hard and soft. This option will override the table or query’s durability setting (set in run).
    /// In soft durability mode RethinkDB will acknowledge the write immediately after receiving and caching it,
    /// but before the write has been committed to disk.
    pub durability: Option<Durability>,
    /// - `true`: return a `changes` array consisting of `old_val`/`new_val` objects describing the changes made,
    ///   only including the documents actually updated.
    /// - `false`: do not return a `changes` array (the default).
    /// - `"always"`: behave as `true`, but include all documents the command tried to update whether
    ///   or not the update was successful. (This was the behavior of true pre-2.0.)
    pub return_changes: Option<ReturnChanges>,
    /// If `true`, and if the user has the config permission,
    /// ignores any write hook when performing the update.
    pub ignore_write_hook: Option<bool>,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, PartialEq, PartialOrd, WithOpts, OptionsBuilder)]
pub struct BetweenOptions {
    /// If `index` is set to the name of a secondary index, `between` will return all
    /// documents where that index’s value is in the specified range (it uses the primary
    /// key by default).
    pub index: Option<String>,
    /// `left_bound` may be set to open or closed to indicate whether or not to include
    /// that endpoint of the range (*by default*, `left_bound` is `closed`).
    pub left_bound: Option<Status>,
    /// `right_bound` may be set to open or closed to indicate whether or not to include
    /// that endpoint of the range (*by default*, `right_bound` is `open`).
    pub right_bound: Option<Status>,
}

#[derive(Debug, Clone, Copy, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[serde(rename_all = "lowercase")]
pub enum Status {
    Open,
    Closed,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, PartialEq, PartialOrd, WithOpts, OptionsBuilder)]
pub struct DuringOptions {
    /// `left_bound` may be set to open or closed to indicate whether or not to include
    /// that endpoint of the range (*by default*, `left_bound` is `closed`).
    pub left_bound: Option<Status>,
    /// `right_bound` may be set to open or closed to indicate whether or not to include
    /// that endpoint of the range (*by default*, `right_bound` is `open`).
    pub right_bound: Option<Status>,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, PartialEq, PartialOrd, WithOpts, OptionsBuilder)]
pub struct SliceOptions {
    /// `left_bound` may be set to open or closed to indicate whether or not to include
    /// that endpoint of the range (*by default*, `left_bound` is `closed`).
    pub left_bound: Option<Status>,
    /// `right_bound` may be set to open or closed to indicate whether or not to include
    /// that endpoint of the range (*by default*, `right_bound` is `open`).
    pub right_bound: Option<Status>,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, WithOpts, OptionsBuilder)]
pub struct UnionOptions {
    pub interleave: Option<Interleave>,
}

#[derive(Debug, Clone)]
pub enum Interleave {
    Bool(bool),
    Command(Command),
}

impl Serialize for Interleave {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        match self {
            Self::Bool(boolean) => boolean.serialize(serializer),
            Self::Command(cmd) => cmd.serialize(serializer),
        }
    }
}

impl From<bool> for Interleave {
    fn from(value: bool) -> Self {
        Self::Bool(value)
    }
}

impl From<String> for Interleave {
    fn from(value: String) -> Self {
        Self::Command(Command::from_json(value))
    }
}
impl From<&str> for Interleave {
    fn from(value: &str) -> Self {
        Self::Command(Command::from_json(value))
    }
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, PartialEq, PartialOrd, WithOpts, OptionsBuilder)]
pub struct GroupOptions {
    pub index: Option<String>,
    pub multi: Option<bool>,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, WithOpts, OptionsBuilder)]
pub struct FoldOptions {
    pub emit: Option<Command>,
    pub final_emit: Option<Command>,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, WithOpts, OptionsBuilder)]
pub struct JsOptions {
    pub timeout: Option<f64>,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, WithOpts, OptionsBuilder)]
pub struct HttpOptions {
    /// timeout period in seconds to wait before aborting the connect (default `30`)
    pub timeout: Option<f64>,
    /// number of retry attempts to make after failed connections (default `5`)
    pub attempts: Option<i64>,
    /// number of redirect and location headers to follow (default `1`)
    pub redirects: Option<i64>,
    /// if `true`, verify the server’s SSL certificate (default `true`)
    pub verify: Option<bool>,
    /// string specifying the format to return results in
    pub result_format: Option<ResultFormat>,

    /// HTTP method to use for the request. Default: `GET`
    pub method: Option<HttpMethod>,
    /// object giving authentication
    pub auth: Option<HttpAuth>,
    /// object specifying URL parameters to append to the URL as encoded key/value pairs. { query: 'banana', limit: 2 } will be appended as ?query=banana&limit=2. Default: no parameters.
    pub params: Option<serde_json::Value>,
    /// Extra header lines to include. The value may be an array of strings or an object. Default: Accept-Encoding: deflate;q=1, gzip;q=0.5 and User-Agent: RethinkDB/<VERSION>.
    pub header: Option<serde_json::Value>,
    /// Data to send to the server on a POST, PUT, PATCH, or DELETE request. For POST requests, data may be either an object (which will be written to the body as form-encoded key/value pairs) or a string; for all other requests, data will be serialized as JSON and placed in the request body, sent as Content-Type: application/json. Default: no data will be sent.
    pub data: Option<serde_json::Value>,

    /// This option may specify either a built-in pagination strategy (see below), or a function to provide the next URL and/or params to request.
    pub page: Option<i64>,
    /// An integer specifying the maximum number of requests to issue using the page functionality. This is to prevent overuse of API quotas, and must be specified with page.
    /// - `-1`: no limit
    /// - `0`: no requests will be made, an empty stream will be returned
    /// - `n`: `n` requests will be made
    pub page_limit: Option<i64>,
}

#[derive(Debug, Clone, Copy, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[serde(rename_all = "lowercase")]
pub enum ResultFormat {
    /// always return a string
    Text,
    /// parse the result as JSON, raising an error on failure
    Json,
    /// parse the result as Padded JSON
    Jsonp,
    /// return a binary object
    Binary,
    /// parse the result based on its Content-Type (the default):
    /// - `application/json`: as `json`
    /// - `application/json-p`, `text/json-p`, `text/javascript`: as `jsonp`
    /// - `audio/*`, `video/*`, `image/*`, `application/octet-stream`: as `binary`
    /// - anything else: as `text`
    Auto,
}

#[derive(Debug, Clone, Copy, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[serde(rename_all = "UPPERCASE")]
pub enum HttpMethod {
    Get,
    Post,
    Put,
    Patch,
    Delete,
    Head,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, WithOpts, OptionsBuilder)]
pub struct HttpAuth {
    /// basic (default) or digest
    #[serde(rename = "type")]
    pub type_: Option<String>,
    /// username
    pub user: Option<String>,
    /// password in plain text
    pub pass: Option<String>,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, WithOpts, OptionsBuilder)]
pub struct CircleOptions {
    /// the number of vertices in the polygon or line. Defaults to 32.
    pub num_vertices: Option<i64>,
    /// the reference ellipsoid to use for geographic coordinates. Possible values are WGS84 (the default), a common standard for Earth’s geometry, or unit_sphere, a perfect sphere of 1 meter radius.
    pub geo_system: Option<String>,
    /// Unit for the radius distance. Possible values are m (meter, the default), km (kilometer), mi (international mile), nm (nautical mile), ft (international foot).
    pub unit: Option<String>,
    /// if `true` (the default) the circle is filled, creating a polygon; if false the circle is unfilled (creating a line).
    pub fill: Option<bool>,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, WithOpts, OptionsBuilder)]
pub struct DistanceOptions {
    pub geo_system: Option<String>,
    pub unit: Option<String>,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, WithOpts, OptionsBuilder)]
pub struct GetNearestOptions {
    pub index: Option<String>,
    pub max_results: Option<i64>,
    pub unit: Option<String>,
    pub max_dist: Option<i64>,
    pub geo_system: Option<String>,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, WithOpts, OptionsBuilder)]
pub struct GrantOptions {
    pub read: Option<GrantValue>,
    pub write: Option<GrantValue>,
    pub connect: Option<GrantValue>,
    pub config: Option<GrantValue>,
}

#[derive(Debug, Copy, Clone)]
pub enum GrantValue {
    Bool(bool),
    Null,
}

impl From<bool> for GrantValue {
    fn from(value: bool) -> Self {
        Self::Bool(value)
    }
}

impl Serialize for GrantValue {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        match self {
            Self::Bool(b) => serializer.serialize_bool(*b),
            Self::Null => serializer.serialize_none(),
        }
    }
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, WithOpts, OptionsBuilder)]
pub struct WaitOptions {
    pub wait_for: Option<WaitFor>,
    pub timeout: Option<i64>,
}

#[derive(Debug, Copy, Clone, Default, Serialize)]
pub enum WaitFor {
    ReadyForOutdatedReads,
    ReadyForReads,
    ReadyForWrites,
    #[default]
    AllReplicasReady,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Default, WithOpts, OptionsBuilder)]
pub struct ReconfigureOptions {
    pub shards: Option<i64>,
    pub replicas: Option<i64>,
    pub primary_replica_tag: Option<String>,
    pub dry_run: Option<bool>,
    pub nonvoting_replica_tags: Option<serde_json::Value>,
    pub emergency_repair: Option<String>,
}