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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
use ql2::term::TermType;
use serde::Serialize;
use unreql_macros::create_cmd;
use crate::{
cmd::args::{ManyArgs, OneAndSecondOptionalArg},
Command,
};
create_cmd!(
/// Returns the currently visited document.
///
/// *Note* that `row` does not work within subqueries to access nested documents;
/// you should use anonymous functions to access those documents instead.
/// (See the last example.)
///
/// ## Example
/// Get all users whose age is greater than 5.
///
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("users").filter(r.row().g("age").gt(5)).run(conn)
/// # })
/// ```
///
/// ## Example
/// Access the attribute ‘child’ of an embedded document.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("users").filter(r.row().g("embedded_doc").g("child").gt(5)).run(conn)
/// # })
/// ```
///
/// ## Example
/// Add 1 to every element of an array.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.expr([1, 2, 3]).map(r.row().add(1)).run(conn)
/// # })
/// ```
///
/// ## Example
/// For nested queries, use functions instead of `row`.
///
/// ```
/// # use unreql::func;
/// # unreql::example(|r, conn| {
/// r.table("users").filter(func!(|doc| {
/// doc.g("name").eq(r.table("prizes").get("winner"))
/// })).run(conn)
/// # })
/// ```
only_root,
row:ImplicitVar
);
create_cmd!(
/// Plucks out one or more attributes from either an object or a sequence of
/// objects (projection).
///
/// ## Example
/// We just need information about IronMan’s reactor and not the rest of
/// the document.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("marvel").get("IronMan").pluck(r.args(["reactorState", "reactorPower"])).run(conn)
/// # })
/// ```
///
/// ## Example
/// For the hero beauty contest we only care about certain qualities.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("marvel").pluck(r.args(["beauty", "muscleTone", "charm"])).run(conn)
/// # })
/// ```
///
/// ## Example
/// Pluck can also be used on nested objects.
///
/// ```
/// # use unreql::rjson;
/// # unreql::example(|r, conn| {
/// r.table("marvel")
/// .pluck(rjson!({"abilities" : {"damage" : true, "mana_cost" : true}, "weapons" : true}))
/// .run(conn)
/// # })
/// ```
///
/// ## Example
/// The nested syntax can quickly become overly verbose so there’s a shorthand for it.
///
/// ```
/// # use unreql::rjson;
/// # unreql::example(|r, conn| {
/// r.table("marvel")
/// .pluck(r.args((rjson!({"abilities" : ["damage", "mana_cost"]}), "weapons")))
/// .run(conn)
/// # })
/// ```
///
/// For more information read the [nested field documentation](https://rethinkdb.com/docs/nested-fields/javascript/).
///
/// # Related commands
/// - [without](Self::without)
/// - [map](Self::map)
only_command,
pluck(selector: ManyArgs<()>)
);
create_cmd!(
/// The opposite of pluck; takes an object or a sequence of objects, and
/// returns them with the specified paths removed.
///
/// ## Example
/// Since we don’t need it for this computation we’ll save bandwidth and
/// leave out the list of IronMan’s romantic conquests.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("marvel").get("IronMan").without("personalVictoriesList").run(conn)
/// # })
/// ```
///
/// ## Example
/// Without their prized weapons, our enemies will quickly be vanquished.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("enemies").without("weapons").run(conn)
/// # })
/// ```
///
/// ## Example
/// Nested objects can be used to remove the damage subfield from the weapons
/// and abilities fields.
///
/// ```
/// # use unreql::rjson;
/// # unreql::example(|r, conn| {
/// r.table("marvel")
/// .without(rjson!({"weapons" : {"damage" : true}, "abilities" : {"damage" : true}}))
/// .run(conn)
/// # })
/// ```
///
/// ## Example
/// The nested syntax can quickly become overly verbose so there’s a shorthand
/// for it.
///
/// ```
/// # use unreql::rjson;
/// # unreql::example(|r, conn| {
/// r.table("marvel")
/// .without(rjson!({"weapons":"damage", "abilities":"damage"}))
/// .run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [pluck](Self::pluck)
/// - [map](Self::map)
only_command,
without(selector: ManyArgs<()>)
);
create_cmd!(
/// Merge two or more objects together to construct a new object with
/// properties from all.
///
/// When there is a conflict between field names, preference is given to
/// fields in the rightmost object in the argument list. `merge` also accepts
/// a subquery function that returns an object, which will be used similarly
/// to a map function.
///
/// ## Example
/// Equip Thor for battle.
///
/// ```
/// # use unreql::r;
/// r.table("marvel").get("thor").merge(
/// r.args([
/// r.table("equipment").get("hammer"),
/// r.table("equipment").get("pimento_sandwich")
/// ])
/// );
/// ```
///
/// ## Example
/// Equip every hero for battle, using a subquery function to retrieve their weapons.
///
/// ```
/// # use unreql::{r, func};
/// # use unreql::rjson;
/// r.table("marvel").merge(func!(|hero| {
/// r.expr(rjson!({
/// "weapons": r.table("weapons").get(hero.g("weaponId")),
/// }))
/// }));
/// ```
///
/// ## Example
/// Use `merge` to join each blog post with its comments.
///
/// *Note* that the sequence being merged—in this example, the comments—must
/// be coerced from a selection to an array. Without `coerce_to` the operation
/// will throw an error (“Expected type DATUM but found SELECTION”).
///
/// ```
/// # use unreql::{r, func};
/// # use unreql::rjson;
/// r.table("posts").merge(func!(|post| {
/// r.expr(rjson!({
/// "comments": r.table("comments")
/// .get_all(r.with_opt(post.g("id"), r.index("postId")))
/// .coerce_to("array")
/// }))
/// }));
/// ```
///
/// ## Example
/// Merge can be used recursively to modify object within objects.
///
/// ```
/// # use unreql::{r, func};
/// # use unreql::rjson;
/// r.expr(rjson!({"weapons" : {"spectacular_graviton_beam" : {"dmg" : 10, "cooldown" : 20}}}))
/// .merge(rjson!({"weapons" : {"spectacular_graviton_beam" : {"dmg" : 10}}}));
/// ```
///
/// ## Example
/// To replace a nested object with another object you can use the literal keyword.
///
/// ```
/// # use unreql::{r, func};
/// # use unreql::rjson;
/// r.expr(rjson!({"weapons" : {"spectacular_graviton_beam" : {"dmg" : 10, "cooldown" : 20}}}))
/// .merge(rjson!({"weapons" : r.literal(rjson!({"repulsor_rays" : {"dmg" : 3, "cooldown" : 0}}))}));
/// ```
///
/// ## Example
/// Literal can be used to remove keys from an object as well.
///
/// ```
/// # use unreql::{r, func};
/// # use unreql::rjson;
/// r.expr(rjson!({"weapons" : {"spectacular_graviton_beam" : {"dmg" : 10, "cooldown" : 20}}}))
/// .merge(rjson!({"weapons" : {"spectacular_graviton_beam" : r.literal(())}}));
/// ```
///
/// # Related commands
/// - [pluck](Self::pluck)
/// - [without](Self::without)
/// - [map](Self::map)
only_command,
merge(objects_or_functions: ManyArgs<()>)
);
create_cmd!(
/// Append a value to an array.
///
/// ## Example
/// Retrieve Iron Man’s equipment list with the addition of some new boots.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("marvel").get("IronMan").g("equipment").append("newBoots").run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [prepend](Self::prepend)
/// - [insert_at](Self::insert_at)
/// - [delete_at](Self::delete_at)
/// - [change_at](Self::change_at)
/// - [merge](Self::merge)
append(value: Serialize)
);
create_cmd!(
/// Prepend a value to an array.
///
/// ## Example
/// Retrieve Iron Man’s equipment list with the addition of some new boots.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("marvel").get("IronMan").g("equipment").prepend("newBoots").run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [append](Self::append)
/// - [insert_at](Self::insert_at)
/// - [delete_at](Self::delete_at)
/// - [change_at](Self::change_at)
/// - [merge](Self::merge)
prepend(value: Serialize)
);
create_cmd!(
/// Remove the elements of one array from another array.
///
/// ## Example
/// Retrieve Iron Man’s equipment list without boots.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("marvel").get("IronMan").g("equipment").difference(["Boots"]).run(conn)
/// # })
/// ```
///
/// ## Example
/// Remove Iron Man’s boots from his equipment.
///
/// ```
/// # use unreql::rjson;
/// # unreql::example(|r, conn| {
/// r.table("marvel")
/// .get("IronMan")
/// .update(rjson!({ "equipment": r.row().g("equipment").difference(["Boots"]) }))
/// .run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [set_insert](Self::set_insert)
/// - [set_union](Self::set_union)
/// - [set_intersection](Self::set_intersection)
/// - [set_difference](Self::set_difference)
/// - [union](Self::union)
difference(array: Serialize)
);
create_cmd!(
/// Add a value to an array and return it as a set (an array with distinct values).
///
/// ## Example
/// Retrieve Iron Man’s equipment list with the addition of some new boots.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("marvel").get("IronMan").g("equipment").set_insert("newBoots").run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [difference](Self::difference)
/// - [set_union](Self::set_union)
/// - [set_intersection](Self::set_intersection)
/// - [set_difference](Self::set_difference)
/// - [union](Self::union)
set_insert(value: Serialize)
);
create_cmd!(
/// Add a several values to an array and return it as a set (an array with distinct values).
///
/// # Example
/// Retrieve Iron Man’s equipment list with the addition of some new boots and an arc reactor.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("marvel").get("IronMan").g("equipment").set_union(["newBoots", "arc_reactor"]).run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [difference](Self::difference)
/// - [set_insert](Self::set_insert)
/// - [set_intersection](Self::set_intersection)
/// - [set_difference](Self::set_difference)
/// - [union](Self::union)
set_union(array: Serialize)
);
create_cmd!(
/// Intersect two arrays returning values that occur in both of them as a set (an array with distinct values).
///
/// ## Example
/// Check which pieces of equipment Iron Man has from a fixed list.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("marvel").get("IronMan").g("equipment").set_intersection(["newBoots", "arc_reactor"]).run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [difference](Self::difference)
/// - [set_insert](Self::set_insert)
/// - [set_union](Self::set_union)
/// - [set_difference](Self::set_difference)
/// - [union](Self::union)
set_intersection(array: Serialize)
);
create_cmd!(
/// Remove the elements of one array from another and return them as a set (an array with distinct values).
///
/// ## Example
/// Check which pieces of equipment Iron Man has, excluding a fixed list.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("marvel").get("IronMan").g("equipment").set_difference(["newBoots", "arc_reactor"]).run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [difference](Self::difference)
/// - [set_insert](Self::set_insert)
/// - [set_union](Self::set_union)
/// - [set_intersection](Self::set_intersection)
/// - [union](Self::union)
set_difference(array: Serialize)
);
create_cmd!(
/// Get a single field from an object.
///
/// If called on a sequence, gets that field from every object in the
/// sequence, skipping objects that lack it.
///
/// *Note*: Under most circumstances, you’ll want to use `get_field` (or
/// its shorthand `g`) or nth rather than bracket. The bracket term may
/// be useful in situations where you are unsure of the data type
/// returned by the term you are calling bracket on.
///
/// ## Example
/// What was Iron Man’s first appearance in a comic?
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("marvel").get("IronMan").bracket("firstAppearance").run(conn)
/// # })
/// ```
///
/// The `bracket` command also accepts integer arguments as array offsets,
/// like the `nth` command.
///
/// ## Example
/// Get the fourth element in a sequence. (The first element is position 0,
/// so the fourth element is position 3.)
///
/// ```
/// # unreql::example(|r, conn| {
/// r.expr([10, 20, 30, 40, 50]).bracket(3).run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [get_field](Self::get_field)
/// - [nth](Self::nth)
bracket(attr_or_index: Serialize)
);
create_cmd!(
/// Get a single field from an object. If called on a sequence, gets that field from
/// every object in the sequence, skipping objects that lack it.
///
/// You may use either `get_field` or its shorthand, `g`.
///
/// ## Example
/// What was Iron Man’s first appearance in a comic?
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("marvel").get("IronMan").g("firstAppearance").run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [nth](Self::nth)
g:GetField(attr: Serialize)
get_field(attr: Serialize)
);
create_cmd!(
/// Test if an object has one or more fields. An object has a field if it
/// has that key and the key has a non-null value. For instance, the object
/// `{'a': 1,'b': 2,'c': null}` has the fields `a` and `b`.
///
/// When applied to a single object, `has_fields` returns `true` if the
/// object has the fields and false if it does not. When applied to
/// a sequence, it will return a new sequence (an array or stream)
/// containing the elements that have the specified fields.
///
/// ## Example
/// Return the players who have won games.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("players").has_fields("games_won").run(conn)
/// # })
/// ```
///
/// ## Example
/// Return the players who have not won games. To do this, use `has_fields`
/// with not, wrapped with `filter`.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("players").filter(r.row().has_fields("games_won").not()).run(conn)
/// # })
/// ```
///
/// ## Example
/// Test if a specific player has won any games.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.table("players").get(1).has_fields("games_won").run(conn)
/// # })
/// ```
///
/// ## Nested Fields
///
/// `has_fields` lets you test for nested fields in objects. If the value of a field is itself a set of key/value pairs, you can test for the presence of specific keys.
///
/// ## Example
/// In the `players` table, the `games_won` field contains one or more fields for kinds of games won:
///
/// ```json
/// {
/// "games_won": {
/// "playoffs": 2,
/// "championships": 1
/// }
/// }
/// ```
///
/// Return players who have the “championships” field.
///
/// ```
/// # use unreql::rjson;
/// # unreql::example(|r, conn| {
/// r.table("players")
/// .has_fields(rjson!({"games_won": {"championships": true}}))
/// .run(conn)
/// # })
/// ```
///
/// *Note* that `true` in the example above is testing for the existence
/// of `championships` as a field, not testing to see if the value of the
/// `championships` field is set to `true`. There’s a more convenient
/// shorthand form available. (See [pluck](Command::pluck) for more details on this.)
///
/// ```
/// # use unreql::rjson;
/// # unreql::example(|r, conn| {
/// r.table("players")
/// .has_fields(rjson!({"games_won": "championships"}))
/// .run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [with_fields](Self::with_fields)
only_command,
has_fields(selector: ManyArgs<()>)
);
create_cmd!(
/// Insert a value in to an array at a given index. Returns the modified array.
///
/// ## Example
/// Hulk decides to join the avengers.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.expr(["Iron Man", "Spider-Man"]).insert_at(1, "Hulk").run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [splice_at](Self::splice_at)
/// - [delete_at](Self::delete_at)
/// - [change_at](Self::change_at)
only_command,
insert_at(offset: Serialize, value: Serialize)
);
create_cmd!(
/// Insert several values in to an array at a given index. Returns the modified array.
///
/// ## Example
/// Hulk and Thor decide to join the avengers.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.expr(["Iron Man", "Spider-Man"]).splice_at(1, ["Hulk", "Thor"]).run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [insert_at](Self::insert_at)
/// - [delete_at](Self::delete_at)
/// - [change_at](Self::change_at)
only_command,
splice_at(offset: Serialize, array: Serialize)
);
create_cmd!(
/// Remove one or more elements from an array at a given index. Returns the
/// modified array. (Note: `delete_at` operates on arrays, not documents; to
/// delete documents, see the [delete](Self::delete) command.)
///
/// If only `offset` is specified, `delete_at` removes the element at that
/// index. If both `offset` and `endOffset` are specified, `delete_at`
/// removes the range of elements between `offset` and `endOffset`,
/// inclusive of `offset` but not inclusive of `endOffset`.
///
/// If `endOffset` is specified, it must not be less than offset. Both
/// `offset` and `endOffset` must be within the array’s bounds (i.e., if
/// the array has 10 elements, an `offset` or `endOffset` of 10 or
/// higher is invalid).
///
/// By using a negative `offset` you can delete from the end of the array.
/// `-1` is the last element in the array, -2 is the second-to-last element,
/// and so on. You may specify a negative `endOffset`, although just as
/// with a positive value, this will not be inclusive. The range `(2,-1)`
/// specifies the third element through the next-to-last element.
///
/// ## Example
/// Delete the second element of an array.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.expr(["a","b","c","d","e","f"]).delete_at(1).run(conn)
/// // Result: ["a", "c", "d", "e", "f"]
/// # })
/// ```
///
/// ## Example
/// Delete the second and third elements of an array.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.expr(["a","b","c","d","e","f"]).delete_at(r.args((1, 3))).run(conn)
/// // Result: ["a", "d", "e", "f"]
/// # })
/// ```
///
/// ## Example
/// Delete the next-to-last element of an array.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.expr(["a","b","c","d","e","f"]).delete_at(-2).run(conn)
/// // Result: ["a", "b", "c", "d", "f"]
/// # })
/// ```
///
/// ## Example
/// Delete a comment on a post.
/// Given a post document such as:
///
/// ```json
/// {
/// "id": "4cf47834-b6f9-438f-9dec-74087e84eb63",
/// "title": "Post title",
/// "author": "Bob",
/// "comments": [
/// { "author": "Agatha", "text": "Comment 1" },
/// { "author": "Fred", "text": "Comment 2" }
/// ]
/// }
/// ```
///
/// The second comment can be deleted by using update and deleteAt together.
///
/// ```
/// # use unreql::rjson;
/// # unreql::example(|r, conn| {
/// r.table("posts")
/// .get("4cf47834-b6f9-438f-9dec-74087e84eb63")
/// .update(rjson!({ "comments": r.row().g("comments").delete_at(1) }))
/// .run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [insert_at](Self::insert_at)
/// - [splice_at](Self::splice_at)
/// - [change_at](Self::change_at)
only_command,
delete_at(start_end_offset: OneAndSecondOptionalArg<()>)
);
create_cmd!(
/// Change a value in an array at a given index. Returns the modified array.
///
/// ## Example
/// Bruce Banner hulks out.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.expr(["Iron Man", "Bruce", "Spider-Man"]).change_at(1, "Hulk").run(conn)
/// # })
/// ```
///
/// # Related commands
/// - [insert_at](Self::insert_at)
/// - [splice_at](Self::splice_at)
/// - [delete_at](Self::delete_at)
only_command,
change_at(offset: Serialize, value: Serialize)
);
create_cmd!(
/// Return an array containing all of an object’s keys. Note that the keys will be sorted as described in ReQL data types (for strings, lexicographically).
///
/// ## Example
/// Get all the keys from a table row.
///
/// ```
/// # unreql::example(|r, conn| {
/// // row: { id: 1, mail: "fred@example.com", name: "fred" }
///
/// r.table("users").get(1).keys().run(conn)
/// // Result: [ "id", "mail", "name" ]
/// # })
/// ```
///
/// # Related commands
/// - [insert_at](Self::insert_at)
/// - [splice_at](Self::splice_at)
/// - [delete_at](Self::delete_at)
only_command,
keys
);
create_cmd!(
/// Return an array containing all of an object’s values. values() guarantees the values will come out in the same order as keys.
///
/// ## Example
/// Get all of the values from a table row.
///
/// ```
/// # unreql::example(|r, conn| {
/// // row: { id: 1, mail: "fred@example.com", name: "fred" }
///
/// r.table("users").get(1).values().run(conn)
/// // Result: [ 1, "fred@example.com", "fred" ]
/// # })
/// ```
///
/// # Related commands
/// - [insert_at](Self::insert_at)
/// - [splice_at](Self::splice_at)
/// - [delete_at](Self::delete_at)
only_command,
values
);
create_cmd!(
/// Replace an object in a field instead of merging it with an existing
/// object in a `merge` or `update` operation. Using `literal` with no
/// arguments in a `merge` or `update` operation will remove the
/// corresponding field.
///
/// Assume your users table has this structure:
///
/// ```json
/// [
/// {
/// "id": 1,
/// "name": "Alice",
/// "data": {
/// "age": 18,
/// "city": "Dallas"
/// }
/// }
/// ...
/// ]
/// ```
///
/// Using `update` to modify the `data` field will normally merge
/// the nested documents:
///
/// ```
/// # use unreql::rjson;
/// # unreql::example(|r, conn| {
/// r.table("users").get(1).update(rjson!({ "data": { "age": 19, "job": "Engineer" } })).run(conn)
/// # })
/// ```
///
/// Result:
///
/// ```json
/// {
/// "id": 1,
/// "name": "Alice",
/// "data": {
/// "age": 19,
/// "city": "Dallas",
/// "job": "Engineer"
/// }
/// }
/// ```
///
/// That will preserve `city` and other existing fields. But to replace
/// the entire `data` document with a new object, use `literal`.
///
/// ## Example
/// Replace one nested document with another rather than merging the fields.
///
/// ```
/// # use unreql::rjson;
/// # unreql::example(|r, conn| {
/// r.table("users")
/// .get(1)
/// .update(rjson!({ "data": r.literal(rjson!({ "age": 19, "job": "Engineer" })) }))
/// .run(conn)
/// # })
/// ```
///
/// Result:
///
/// ```json
/// {
/// "id": 1,
/// "name": "Alice",
/// "data": {
/// "age": 19,
/// "job": "Engineer"
/// }
/// }
/// ```
///
/// ## Example
/// Use literal to remove a field from a document.
///
/// ```
/// # use unreql::rjson;
/// # unreql::example(|r, conn| {
/// r.table("users")
/// .get(1)
/// .merge(rjson!({ "data": r.literal(()) }))
/// .run(conn)
/// # })
/// ```
///
/// Result:
///
/// ```json
/// {
/// "id": 1,
/// "name": "Alice"
/// }
/// ```
///
/// # Related commands
/// - [merge](Self::merge)
/// - [filter](Self::filter)
only_root,
literal(object: Serialize)
);
create_cmd!(
/// Creates an object from a list of key-value pairs, where the keys must
/// be strings. `r.object(A, B, C, D)` is equivalent to
/// `r.expr([[A, B], [C, D]]).coerce_to('OBJECT')`.
///
/// ## Example
/// Create a simple object.
///
/// ```
/// # unreql::example(|r, conn| {
/// r.object(r.args(("id", 5, "data", ["foo", "bar"]))).run(conn)
/// // Result: {"data": ["foo", "bar"], "id": 5}
/// # })
/// ```
///
/// or for many args, use array of `serde_json::Value`:
///
/// ```
/// # use unreql::rjson;
/// # unreql::example(|r, conn| {
/// r.object(r.args([rjson!("id"), rjson!(5), rjson!("data"), rjson!(["foo", "bar"])])).run(conn)
/// // Result: {"data": ["foo", "bar"], "id": 5}
/// # })
/// ```
///
/// # Related commands
/// - [coerce_to](Self::coerce_to)
/// - [merge](Self::merge)
/// - [keys](Self::keys)
only_root,
object(key_value: ManyArgs<()>)
);