File Coverage

blib/lib/Rethinkdb/Query.pm
Criterion Covered Total %
statement 15 461 3.2
branch 0 54 0.0
condition 0 24 0.0
subroutine 5 106 4.7
pod 98 98 100.0
total 118 743 15.8


line stmt bran cond sub pod time code
1             package Rethinkdb::Query;
2 15     15   55 use Rethinkdb::Base -base;
  15         23  
  15         129  
3              
4 15     15   65 use Carp 'croak';
  15         24  
  15         624  
5 15     15   60 use Scalar::Util 'weaken';
  15         25  
  15         595  
6              
7 15     15   55 use Rethinkdb;
  15         20  
  15         89  
8 15     15   88 use Rethinkdb::Protocol;
  15         34  
  15         77  
9              
10             has [qw{ _rdb _parent _type args optargs }];
11             has '_termType' => sub { Rethinkdb::Protocol->new->term->termType; };
12              
13             sub new {
14 0     0 1   my $class = shift;
15 0 0 0       my $self = bless @_ ? @_ > 1 ? {@_} : { %{ $_[0] } } : {},
  0 0          
16             ref $class || $class;
17              
18 0 0 0       if ( $self->_parent && $self->_parent->_rdb ) {
19 0           my $rdb = $self->_parent->_rdb;
20 0           delete $self->_parent->{_rdb};
21 0           $self->_rdb($rdb);
22             }
23              
24             # process args and optargs
25 0           $self->_args;
26 0           $self->_optargs;
27              
28             # ditch parent
29 0           delete $self->{_parent};
30              
31 0           return $self;
32             }
33              
34             sub _build {
35 0     0     my $self = shift;
36 0           my $q = { type => $self->_type };
37              
38 0 0         if ( $self->args ) {
39 0           foreach ( @{ $self->args } ) {
  0            
40 0 0 0       if ( ref $_ && UNIVERSAL::can( $_, 'can' ) && $_->can('_build') ) {
      0        
41 0           push @{ $q->{args} }, $_->_build;
  0            
42             }
43             else {
44 0           push @{ $q->{args} }, $_;
  0            
45             }
46             }
47             }
48             # else {
49             # push @{ $q->{args} }, undef;
50             # }
51              
52 0 0         if ( $self->optargs ) {
53 0           foreach ( keys %{ $self->optargs } ) {
  0            
54 0           my $value = $self->{optargs}->{$_};
55 0 0 0       if ( ref $value
      0        
56             && UNIVERSAL::can( $value, 'can' )
57             && $value->can('_build') )
58             {
59 0           push @{ $q->{optargs} }, { key => $_, val => $value->_build };
  0            
60             }
61             else {
62 0           push @{ $q->{optargs} }, { key => $_, val => $value };
  0            
63             }
64             }
65             }
66              
67 0           return $q;
68             }
69              
70             sub _args {
71 0     0     my $self = shift;
72 0           my $args = $self->args;
73 0           my $parent = $self->_parent;
74 0           delete $self->{args};
75              
76 0 0         if ( defined $args ) {
    0          
77              
78 0 0         if ( ref $args ne 'ARRAY' ) {
79 0           $args = [$args];
80             }
81              
82 0           my $expr_args = [];
83              
84 0 0         if ($parent) {
85 0           push @{$expr_args}, $parent;
  0            
86             }
87              
88 0           foreach ( @{$args} ) {
  0            
89 0           push @{$expr_args}, Rethinkdb::Util->_expr($_);
  0            
90             }
91              
92 0           $self->args($expr_args);
93             }
94             elsif ( defined $parent ) {
95 0           $self->args( [$parent] );
96             }
97              
98 0           return;
99             }
100              
101             sub _optargs {
102 0     0     my $self = shift;
103 0           my $optargs = $self->optargs;
104 0           delete $self->{optargs};
105              
106 0 0         if ($optargs) {
107 0 0         if ( ref $optargs ) {
108 0           my $expr_optargs = {};
109              
110 0           foreach ( keys %{$optargs} ) {
  0            
111 0           $expr_optargs->{$_} = Rethinkdb::Util->_expr( $optargs->{$_} );
112             }
113              
114 0           $self->optargs($expr_optargs);
115             }
116             }
117              
118 0           return;
119             }
120              
121             sub run {
122 0     0 1   my $self = shift;
123 0           my ( $connection, $args, $callback ) = @_;
124              
125 0 0         if ( ref $connection ne 'Rethinkdb::IO' ) {
126 0           $callback = $args;
127 0           $args = $connection;
128 0 0 0       if ( $self->_rdb && $self->_rdb->io ) {
129 0           $connection = $self->_rdb->io;
130             }
131             else {
132 0           croak 'ERROR: run() was not given a connection';
133             }
134             }
135              
136 0 0         if ( ref $args eq 'CODE' ) {
137 0           $callback = $args;
138 0           $args = {};
139             }
140              
141 0           return $connection->_start( $self, $args, $callback );
142             }
143              
144             # WRITING DATA
145              
146             sub update {
147 0     0 1   my $self = shift;
148 0           my $args = shift;
149 0 0         my $optargs = @_ ? @_ > 1 ? {@_} : { %{ $_[0] } } : {};
  0 0          
150              
151 0           my $q = Rethinkdb::Query->new(
152             _parent => $self,
153             _type => $self->_termType->update,
154             args => Rethinkdb::Util->_wrap_func( $args, 1 ),
155             optargs => $optargs,
156             );
157              
158 0           return $q;
159             }
160              
161             sub replace {
162 0     0 1   my $self = shift;
163 0           my $args = shift;
164 0 0         my $optargs = @_ ? @_ > 1 ? {@_} : { %{ $_[0] } } : {};
  0 0          
165              
166 0           my $q = Rethinkdb::Query->new(
167             _parent => $self,
168             _type => $self->_termType->replace,
169             args => Rethinkdb::Util->_wrap_func($args),
170             optargs => $optargs,
171             );
172              
173 0           return $q;
174             }
175              
176             sub delete {
177 0     0 1   my $self = shift;
178 0 0         my $optargs = @_ ? @_ > 1 ? {@_} : { %{ $_[0] } } : {};
  0 0          
179              
180 0           my $q = Rethinkdb::Query->new(
181             _parent => $self,
182             _type => $self->_termType->delete,
183             optargs => $optargs,
184             );
185              
186 0           return $q;
187             }
188              
189             # SELECTING DATA
190              
191             sub filter {
192 0     0 1   my $self = shift;
193 0           my $args = shift;
194              
195 0           my $q = Rethinkdb::Query->new(
196             _parent => $self,
197             _type => $self->_termType->filter,
198             args => Rethinkdb::Util->_wrap_func($args),
199             );
200              
201 0           return $q;
202             }
203              
204             # JOINS
205              
206             sub inner_join {
207 0     0 1   my $self = shift;
208 0           my ( $table, $predicate ) = @_;
209              
210 0           my $q = Rethinkdb::Query->new(
211             _parent => $self,
212             _type => $self->_termType->inner_join,
213             args => [ $table, $predicate ],
214             );
215              
216 0           return $q;
217             }
218              
219             sub outer_join {
220 0     0 1   my $self = shift;
221 0           my ( $table, $predicate ) = @_;
222              
223 0           my $q = Rethinkdb::Query->new(
224             _parent => $self,
225             _type => $self->_termType->outer_join,
226             args => [ $table, $predicate ],
227             );
228              
229 0           return $q;
230             }
231              
232             sub eq_join {
233 0     0 1   my $self = shift;
234 0           my ( $left, $table, $optargs ) = @_;
235              
236 0           my $q = Rethinkdb::Query->new(
237             _parent => $self,
238             _type => $self->_termType->eq_join,
239             args => [ $left, $table ],
240             optargs => $optargs,
241             );
242              
243 0           return $q;
244             }
245              
246             sub zip {
247 0     0 1   my $self = shift;
248              
249 0           my $q
250             = Rethinkdb::Query->new( _parent => $self, _type => $self->_termType->zip,
251             );
252              
253 0           return $q;
254             }
255              
256             # TRANSFORMATIONS
257              
258             sub map {
259 0     0 1   my $self = shift;
260 0           my ($args) = @_;
261              
262 0           my $q = Rethinkdb::Query->new(
263             _parent => $self,
264             _type => $self->_termType->map,
265             args => Rethinkdb::Util->_wrap_func($args),
266             );
267              
268 0           return $q;
269             }
270              
271             sub with_fields {
272 0     0 1   my $self = shift;
273 0           my $args = [@_];
274              
275 0           my $q = Rethinkdb::Query->new(
276             _parent => $self,
277             _type => $self->_termType->with_fields,
278             args => $args,
279             );
280              
281 0           return $q;
282             }
283              
284             sub concat_map {
285 0     0 1   my $self = shift;
286 0           my $args = [@_];
287              
288 0           my $q = Rethinkdb::Query->new(
289             _parent => $self,
290             _type => $self->_termType->concat_map,
291             args => $args,
292             );
293              
294 0           return $q;
295             }
296              
297             sub order_by {
298 0     0 1   my $self = shift;
299 0           my $args = [@_];
300              
301 0           my $q = Rethinkdb::Query->new(
302             _parent => $self,
303             _type => $self->_termType->order_by,
304             args => $args,
305             );
306              
307 0           return $q;
308             }
309              
310             sub skip {
311 0     0 1   my $self = shift;
312 0           my $number = shift;
313              
314 0           my $q = Rethinkdb::Query->new(
315             _parent => $self,
316             _type => $self->_termType->skip,
317             args => $number,
318             );
319              
320 0           return $q;
321             }
322              
323             sub limit {
324 0     0 1   my $self = shift;
325 0           my $number = shift;
326              
327 0           my $q = Rethinkdb::Query->new(
328             _parent => $self,
329             _type => $self->_termType->limit,
330             args => $number,
331             );
332              
333 0           return $q;
334             }
335              
336             sub slice {
337 0     0 1   my $self = shift;
338 0           my $args = [@_];
339              
340 0           my $q = Rethinkdb::Query->new(
341             _parent => $self,
342             _type => $self->_termType->slice,
343             args => $args,
344             );
345              
346 0           return $q;
347             }
348              
349             sub nth {
350 0     0 1   my $self = shift;
351 0           my $number = [@_];
352              
353 0           my $q = Rethinkdb::Query->new(
354             _parent => $self,
355             _type => $self->_termType->nth,
356             args => $number,
357             );
358              
359 0           return $q;
360             }
361              
362             sub offsets_of {
363 0     0 1   my $self = shift;
364 0           my ($args) = @_;
365              
366 0           my $q = Rethinkdb::Query->new(
367             _parent => $self,
368             _type => $self->_termType->offsets_of,
369             args => Rethinkdb::Util->_wrap_func($args),
370             );
371              
372 0           return $q;
373             }
374              
375             sub is_empty {
376 0     0 1   my $self = shift;
377              
378 0           my $q = Rethinkdb::Query->new(
379             _parent => $self,
380             _type => $self->_termType->is_empty,
381             );
382              
383 0           return $q;
384             }
385              
386             sub union {
387 0     0 1   my $self = shift;
388 0           my $args = shift;
389              
390 0           my $q = Rethinkdb::Query->new(
391             _parent => $self,
392             _type => $self->_termType->union,
393             args => $args,
394             );
395              
396 0           return $q;
397             }
398              
399             sub sample {
400 0     0 1   my $self = shift;
401 0           my $args = shift;
402              
403 0           my $q = Rethinkdb::Query->new(
404             _parent => $self,
405             _type => $self->_termType->sample,
406             args => $args,
407             );
408              
409 0           return $q;
410             }
411              
412             # AGGREGATION
413              
414             sub group {
415 0     0 1   my $self = shift;
416 0           my $args = [@_];
417 0           my $optargs = {};
418              
419 0 0         if ( ref $args->[ $#{$args} ] eq 'HASH' ) {
  0            
420 0           $optargs = pop @{$args};
  0            
421             }
422              
423 0 0 0       if( ref $args->[0] && ref $args->[0] ne 'CODE' ) {
424 0           $args = Rethinkdb::Util->_wrap_func($args->[0]);
425             }
426              
427 0           my $q = Rethinkdb::Query->new(
428             _parent => $self,
429             _type => $self->_termType->group,
430             args => $args,
431             optargs => $optargs
432             );
433              
434 0           return $q;
435             }
436              
437             sub ungroup {
438 0     0 1   my $self = shift;
439              
440 0           my $q = Rethinkdb::Query->new(
441             _parent => $self,
442             _type => $self->_termType->ungroup,
443             );
444              
445 0           return $q;
446             }
447              
448             sub reduce {
449 0     0 1   my $self = shift;
450 0           my $function = shift;
451              
452 0           my $q = Rethinkdb::Query->new(
453             _parent => $self,
454             _type => $self->_termType->reduce,
455             args => $function,
456             );
457              
458 0           return $q;
459             }
460              
461             sub count {
462 0     0 1   my $self = shift;
463 0           my $args = shift;
464              
465 0           my $q = Rethinkdb::Query->new(
466             _parent => $self,
467             _type => $self->_termType->count,
468             args => $args
469             );
470              
471 0           return $q;
472             }
473              
474             sub sum {
475 0     0 1   my $self = shift;
476 0           my $args = [@_];
477              
478 0           my $q = Rethinkdb::Query->new(
479             _parent => $self,
480             _type => $self->_termType->sum,
481             args => $args
482             );
483              
484 0           return $q;
485             }
486              
487             sub avg {
488 0     0 1   my $self = shift;
489 0           my $args = [@_];
490              
491 0           my $q = Rethinkdb::Query->new(
492             _parent => $self,
493             _type => $self->_termType->avg,
494             args => $args
495             );
496              
497 0           return $q;
498             }
499              
500             sub min {
501 0     0 1   my $self = shift;
502 0           my $args = [@_];
503              
504 0           my $q = Rethinkdb::Query->new(
505             _parent => $self,
506             _type => $self->_termType->min,
507             args => $args
508             );
509              
510 0           return $q;
511             }
512              
513             sub max {
514 0     0 1   my $self = shift;
515 0           my $args = [@_];
516              
517 0           my $q = Rethinkdb::Query->new(
518             _parent => $self,
519             _type => $self->_termType->max,
520             args => $args
521             );
522              
523 0           return $q;
524             }
525              
526             sub distinct {
527 0     0 1   my $self = shift;
528              
529 0           my $q = Rethinkdb::Query->new(
530             _parent => $self,
531             _type => $self->_termType->distinct,
532             );
533              
534 0           return $q;
535             }
536              
537             sub contains {
538 0     0 1   my $self = shift;
539 0           my $args = [@_];
540              
541 0           my $q = Rethinkdb::Query->new(
542             _parent => $self,
543             _type => $self->_termType->contains,
544             args => $args
545             );
546              
547 0           return $q;
548             }
549              
550             # DOCUMENT MANIPULATION
551              
552             sub pluck {
553 0     0 1   my $self = shift;
554 0           my $args = [@_];
555              
556 0           my $q = Rethinkdb::Query->new(
557             _parent => $self,
558             _type => $self->_termType->pluck,
559             args => $args
560             );
561              
562 0           return $q;
563             }
564              
565             sub without {
566 0     0 1   my $self = shift;
567 0 0         my $args = @_ ? @_ > 1 ? [@_] : [ @{ $_[0] } ] : [];
  0 0          
568              
569 0           my $q = Rethinkdb::Query->new(
570             _parent => $self,
571             _type => $self->_termType->without,
572             args => $args
573             );
574              
575 0           return $q;
576             }
577              
578             sub merge {
579 0     0 1   my $self = shift;
580 0           my $args = shift;
581              
582 0           my $q = Rethinkdb::Query->new(
583             _parent => $self,
584             _type => $self->_termType->merge,
585             args => $args
586             );
587              
588 0           return $q;
589             }
590              
591             sub append {
592 0     0 1   my $self = shift;
593              
594             # my $args = @_ ? @_ > 1 ? [@_] : [ @{ $_[0] } ] : [];
595 0           my $args = shift;
596              
597 0           my $q = Rethinkdb::Query->new(
598             _parent => $self,
599             _type => $self->_termType->append,
600             args => $args
601             );
602              
603 0           return $q;
604             }
605              
606             sub prepend {
607 0     0 1   my $self = shift;
608              
609             # my $args = @_ ? @_ > 1 ? [@_] : [ @{ $_[0] } ] : [];
610 0           my $args = shift;
611              
612 0           my $q = Rethinkdb::Query->new(
613             _parent => $self,
614             _type => $self->_termType->prepend,
615             args => $args
616             );
617              
618 0           return $q;
619             }
620              
621             sub difference {
622 0     0 1   my $self = shift;
623 0           my $args = shift;
624              
625 0           my $q = Rethinkdb::Query->new(
626             _parent => $self,
627             _type => $self->_termType->difference,
628             args => [$args],
629             );
630              
631 0           return $q;
632             }
633              
634             sub set_insert {
635 0     0 1   my $self = shift;
636 0           my $args = shift;
637              
638 0           my $q = Rethinkdb::Query->new(
639             _parent => $self,
640             _type => $self->_termType->set_insert,
641             args => $args,
642             );
643              
644 0           return $q;
645             }
646              
647             sub set_union {
648 0     0 1   my $self = shift;
649 0           my $args = shift;
650              
651 0           my $q = Rethinkdb::Query->new(
652             _parent => $self,
653             _type => $self->_termType->set_union,
654             args => [$args],
655             );
656              
657 0           return $q;
658             }
659              
660             sub set_intersection {
661 0     0 1   my $self = shift;
662 0           my $args = shift;
663              
664 0           my $q = Rethinkdb::Query->new(
665             _parent => $self,
666             _type => $self->_termType->set_intersection,
667             args => [$args],
668             );
669              
670 0           return $q;
671             }
672              
673             sub set_difference {
674 0     0 1   my $self = shift;
675 0           my $args = shift;
676              
677 0           my $q = Rethinkdb::Query->new(
678             _parent => $self,
679             _type => $self->_termType->set_difference,
680             args => [$args],
681             );
682              
683 0           return $q;
684             }
685              
686             sub get_field {
687 0     0 1   my $self = shift;
688 0           my $args = shift;
689              
690 0           my $q = Rethinkdb::Query->new(
691             _parent => $self,
692             _type => $self->_termType->get_field,
693             args => $args
694             );
695              
696 0           return $q;
697             }
698              
699             # TODO: replace this with AUTOLOAD or overload %{}
700             # to get something like r->table->get()->{attr}->run;
701             # or like r->table->get()->attr->run;
702             sub bracket {
703 0     0 1   my $self = shift;
704 0           my $args = shift;
705              
706 0           my $q = Rethinkdb::Query->new(
707             _parent => $self,
708             _type => $self->_termType->bracket,
709             args => $args
710             );
711              
712 0           return $q;
713             }
714              
715             # for backwards compatibility
716 0     0 1   sub attr { bracket(@_) }
717              
718             sub has_fields {
719 0     0 1   my $self = shift;
720 0           my $args = shift;
721              
722 0           my $q = Rethinkdb::Query->new(
723             _parent => $self,
724             _type => $self->_termType->has_fields,
725             args => $args
726             );
727              
728 0           return $q;
729             }
730              
731             sub insert_at {
732 0     0 1   my $self = shift;
733 0           my $args = [@_];
734              
735 0           my $q = Rethinkdb::Query->new(
736             _parent => $self,
737             _type => $self->_termType->insert_at,
738             args => $args,
739             );
740              
741 0           return $q;
742             }
743              
744             sub splice_at {
745 0     0 1   my $self = shift;
746 0           my $args = [@_];
747              
748 0           my $q = Rethinkdb::Query->new(
749             _parent => $self,
750             _type => $self->_termType->splice_at,
751             args => $args,
752             );
753              
754 0           return $q;
755             }
756              
757             sub delete_at {
758 0     0 1   my $self = shift;
759 0           my $args = [@_];
760              
761 0           my $q = Rethinkdb::Query->new(
762             _parent => $self,
763             _type => $self->_termType->delete_at,
764             args => $args,
765             );
766              
767 0           return $q;
768             }
769              
770             sub change_at {
771 0     0 1   my $self = shift;
772 0           my $args = [@_];
773              
774 0           my $q = Rethinkdb::Query->new(
775             _parent => $self,
776             _type => $self->_termType->change_at,
777             args => $args,
778             );
779              
780 0           return $q;
781             }
782              
783             sub keys {
784 0     0 1   my $self = shift;
785 0           my $args = [@_];
786              
787 0           my $q = Rethinkdb::Query->new(
788             _parent => $self,
789             _type => $self->_termType->keys,
790             args => $args,
791             );
792              
793 0           return $q;
794             }
795              
796             # STRING MANIPULATION
797              
798             sub match {
799 0     0 1   my $self = shift;
800 0           my ($expr) = @_;
801              
802 0           my $q = Rethinkdb::Query->new(
803             _parent => $self,
804             _type => $self->_termType->match,
805             args => $expr
806             );
807              
808 0           return $q;
809             }
810              
811             sub split {
812 0     0 1   my $self = shift;
813 0           my ($expr) = @_;
814              
815 0           my $q = Rethinkdb::Query->new(
816             _parent => $self,
817             _type => $self->_termType->split,
818             args => $expr
819             );
820              
821 0           return $q;
822             }
823              
824             sub upcase {
825 0     0 1   my $self = shift;
826              
827 0           my $q = Rethinkdb::Query->new(
828             _parent => $self,
829             _type => $self->_termType->upcase,
830             );
831              
832 0           return $q;
833             }
834              
835             sub downcase {
836 0     0 1   my $self = shift;
837              
838 0           my $q = Rethinkdb::Query->new(
839             _parent => $self,
840             _type => $self->_termType->downcase,
841             );
842              
843 0           return $q;
844             }
845              
846             # MATH AND LOGIC
847              
848              
849             sub add {
850 0     0 1   my $self = shift;
851 0           my ($args) = @_;
852              
853 0           my $q = Rethinkdb::Query->new(
854             _parent => $self,
855             _type => $self->_termType->add,
856             args => [$args],
857             );
858              
859 0           return $q;
860             }
861              
862             sub sub {
863 0     0 1   my $self = shift;
864 0           my ($args) = @_;
865              
866 0           my $q = Rethinkdb::Query->new(
867             _parent => $self,
868             _type => $self->_termType->sub,
869             args => $args,
870             );
871              
872 0           return $q;
873             }
874              
875             sub mul {
876 0     0 1   my $self = shift;
877 0           my ($args) = @_;
878              
879 0           my $q = Rethinkdb::Query->new(
880             _parent => $self,
881             _type => $self->_termType->mul,
882             args => $args,
883             );
884              
885 0           return $q;
886             }
887              
888             sub div {
889 0     0 1   my $self = shift;
890 0           my ($args) = @_;
891              
892 0           my $q = Rethinkdb::Query->new(
893             _parent => $self,
894             _type => $self->_termType->div,
895             args => $args,
896             );
897              
898 0           return $q;
899             }
900              
901             sub mod {
902 0     0 1   my $self = shift;
903 0           my ($args) = @_;
904              
905 0           my $q = Rethinkdb::Query->new(
906             _parent => $self,
907             _type => $self->_termType->mod,
908             args => $args,
909             );
910              
911 0           return $q;
912             }
913              
914             sub and {
915 0     0 1   my $self = shift;
916 0           my ($args) = @_;
917              
918 0           my $q = Rethinkdb::Query->new(
919             _parent => $self,
920             _type => $self->_termType->and,
921             args => $args,
922             );
923              
924 0           return $q;
925             }
926              
927             sub or {
928 0     0 1   my $self = shift;
929 0           my ($args) = @_;
930              
931 0           my $q = Rethinkdb::Query->new(
932             _parent => $self,
933             _type => $self->_termType->or,
934             args => $args,
935             );
936              
937 0           return $q;
938             }
939              
940             sub eq {
941 0     0 1   my $self = shift;
942 0           my ($args) = @_;
943              
944 0           my $q = Rethinkdb::Query->new(
945             _parent => $self,
946             _type => $self->_termType->eq,
947             args => $args,
948             );
949              
950 0           return $q;
951             }
952              
953             sub ne {
954 0     0 1   my $self = shift;
955 0           my ($args) = @_;
956              
957 0           my $q = Rethinkdb::Query->new(
958             _parent => $self,
959             _type => $self->_termType->ne,
960             args => $args,
961             );
962              
963 0           return $q;
964             }
965              
966             sub gt {
967 0     0 1   my $self = shift;
968 0           my ($args) = @_;
969              
970 0           my $q = Rethinkdb::Query->new(
971             _parent => $self,
972             _type => $self->_termType->gt,
973             args => $args,
974             );
975              
976 0           return $q;
977             }
978              
979             sub ge {
980 0     0 1   my $self = shift;
981 0           my ($args) = @_;
982              
983 0           my $q = Rethinkdb::Query->new(
984             _parent => $self,
985             _type => $self->_termType->ge,
986             args => $args,
987             );
988              
989 0           return $q;
990             }
991              
992             sub lt {
993 0     0 1   my $self = shift;
994 0           my ($args) = @_;
995              
996 0           my $q = Rethinkdb::Query->new(
997             _parent => $self,
998             _type => $self->_termType->lt,
999             args => $args,
1000             );
1001              
1002 0           return $q;
1003             }
1004              
1005             sub le {
1006 0     0 1   my $self = shift;
1007 0           my ($args) = @_;
1008              
1009 0           my $q = Rethinkdb::Query->new(
1010             _parent => $self,
1011             _type => $self->_termType->le,
1012             args => $args,
1013             );
1014              
1015 0           return $q;
1016             }
1017              
1018             sub not {
1019 0     0 1   my $self = shift;
1020              
1021 0           my $q
1022             = Rethinkdb::Query->new( _parent => $self, _type => $self->_termType->not,
1023             );
1024              
1025 0           return $q;
1026             }
1027              
1028             # DATES AND TIMES
1029              
1030             sub in_timezone {
1031 0     0 1   my $self = shift;
1032 0           my $args = shift;
1033              
1034 0           my $q = Rethinkdb::Query->new(
1035             _parent => $self,
1036             _type => $self->_termType->in_timezone,
1037             args => $args,
1038             );
1039              
1040 0           return $q;
1041             }
1042              
1043             sub timezone {
1044 0     0 1   my $self = shift;
1045              
1046 0           my $q = Rethinkdb::Query->new(
1047             _parent => $self,
1048             _type => $self->_termType->timezone,
1049             );
1050              
1051 0           return $q;
1052             }
1053              
1054             sub during {
1055 0     0 1   my $self = shift;
1056 0           my $start = shift;
1057 0           my $end = shift;
1058 0           my $optargs = shift;
1059              
1060 0           my $q = Rethinkdb::Query->new(
1061             _parent => $self,
1062             _type => $self->_termType->during,
1063             args => [ $start, $end ],
1064             optargs => $optargs,
1065             );
1066              
1067 0           return $q;
1068             }
1069              
1070             sub date {
1071 0     0 1   my $self = shift;
1072              
1073 0           my $q = Rethinkdb::Query->new(
1074             _parent => $self,
1075             _type => $self->_termType->date,
1076             );
1077              
1078 0           return $q;
1079             }
1080              
1081             sub time_of_day {
1082 0     0 1   my $self = shift;
1083              
1084 0           my $q = Rethinkdb::Query->new(
1085             _parent => $self,
1086             _type => $self->_termType->time_of_day,
1087             );
1088              
1089 0           return $q;
1090             }
1091              
1092             sub year {
1093 0     0 1   my $self = shift;
1094              
1095 0           my $q = Rethinkdb::Query->new(
1096             _parent => $self,
1097             _type => $self->_termType->year,
1098             );
1099              
1100 0           return $q;
1101             }
1102              
1103             sub month {
1104 0     0 1   my $self = shift;
1105              
1106 0           my $q = Rethinkdb::Query->new(
1107             _parent => $self,
1108             _type => $self->_termType->month,
1109             );
1110              
1111 0           return $q;
1112             }
1113              
1114             sub day {
1115 0     0 1   my $self = shift;
1116              
1117 0           my $q
1118             = Rethinkdb::Query->new( _parent => $self, _type => $self->_termType->day,
1119             );
1120              
1121 0           return $q;
1122             }
1123              
1124             sub day_of_week {
1125 0     0 1   my $self = shift;
1126              
1127 0           my $q = Rethinkdb::Query->new(
1128             _parent => $self,
1129             _type => $self->_termType->day_of_week,
1130             );
1131              
1132 0           return $q;
1133             }
1134              
1135             sub day_of_year {
1136 0     0 1   my $self = shift;
1137              
1138 0           my $q = Rethinkdb::Query->new(
1139             _parent => $self,
1140             _type => $self->_termType->day_of_year,
1141             );
1142              
1143 0           return $q;
1144             }
1145              
1146             sub hours {
1147 0     0 1   my $self = shift;
1148              
1149 0           my $q = Rethinkdb::Query->new(
1150             _parent => $self,
1151             _type => $self->_termType->hours,
1152             );
1153              
1154 0           return $q;
1155             }
1156              
1157             sub minutes {
1158 0     0 1   my $self = shift;
1159              
1160 0           my $q = Rethinkdb::Query->new(
1161             _parent => $self,
1162             _type => $self->_termType->minutes,
1163             );
1164              
1165 0           return $q;
1166             }
1167              
1168             sub seconds {
1169 0     0 1   my $self = shift;
1170              
1171 0           my $q = Rethinkdb::Query->new(
1172             _parent => $self,
1173             _type => $self->_termType->seconds,
1174             );
1175              
1176 0           return $q;
1177             }
1178              
1179             sub to_iso8601 {
1180 0     0 1   my $self = shift;
1181              
1182 0           my $q = Rethinkdb::Query->new(
1183             _parent => $self,
1184             _type => $self->_termType->to_iso8601,
1185             );
1186              
1187 0           return $q;
1188             }
1189              
1190             sub to_epoch_time {
1191 0     0 1   my $self = shift;
1192              
1193 0           my $q = Rethinkdb::Query->new(
1194             _parent => $self,
1195             _type => $self->_termType->to_epoch_time,
1196             );
1197              
1198 0           return $q;
1199             }
1200              
1201             # CONTROL STRUCTURES
1202              
1203             # TODO: figure out why the arguments have to be reversed here
1204             sub do {
1205 0     0 1   my $self = shift;
1206 0           my ($args) = @_;
1207              
1208 0           my $q = Rethinkdb::Query->new(
1209             _rdb => $self->_rdb,
1210             _type => $self->_termType->funcall,
1211             args => [ $args, $self ],
1212             );
1213              
1214 0           return $q;
1215             }
1216              
1217             sub for_each {
1218 0     0 1   my $self = shift;
1219 0           my $args = shift;
1220              
1221 0           my $q = Rethinkdb::Query->new(
1222             _parent => $self,
1223             _type => $self->_termType->for_each,
1224             args => $args,
1225             );
1226              
1227 0           return $q;
1228             }
1229              
1230             sub default {
1231 0     0 1   my $self = shift;
1232 0           my $args = shift;
1233              
1234 0 0         if ( !defined $args ) {
1235 0           $args = Rethinkdb::Query::Datum->new( { data => undef } );
1236             }
1237              
1238 0           my $q = Rethinkdb::Query->new(
1239             _parent => $self,
1240             _type => $self->_termType->default,
1241             args => $args,
1242             );
1243              
1244 0           return $q;
1245             }
1246              
1247             sub coerce_to {
1248 0     0 1   my $self = shift;
1249 0           my $args = shift;
1250              
1251 0           my $q = Rethinkdb::Query->new(
1252             _parent => $self,
1253             _type => $self->_termType->coerce_to,
1254             args => $args,
1255             );
1256              
1257 0           return $q;
1258             }
1259              
1260             sub type_of {
1261 0     0 1   my $self = shift;
1262              
1263 0           my $q = Rethinkdb::Query->new(
1264             _parent => $self,
1265             _type => $self->_termType->type_of,
1266             );
1267              
1268 0           return $q;
1269             }
1270              
1271             sub info {
1272 0     0 1   my $self = shift;
1273              
1274 0           my $q = Rethinkdb::Query->new(
1275             _parent => $self,
1276             _type => $self->_termType->info,
1277             );
1278              
1279 0           return $q;
1280             }
1281              
1282             sub fill {
1283 0     0 1   my $self = shift;
1284              
1285 0           my $q = Rethinkdb::Query->new(
1286             _parent => $self,
1287             _type => $self->_termType->fill,
1288             );
1289              
1290 0           return $q;
1291             }
1292              
1293             sub to_geojson {
1294 0     0 1   my $self = shift;
1295              
1296 0           my $q = Rethinkdb::Query->new(
1297             _parent => $self,
1298             _type => $self->_termType->to_geojson,
1299             );
1300              
1301 0           return $q;
1302             }
1303              
1304             sub includes {
1305 0     0 1   my $self = shift;
1306 0           my $args = shift;
1307              
1308 0           my $q = Rethinkdb::Query->new(
1309             _parent => $self,
1310             _type => $self->_termType->includes,
1311             args => $args,
1312             );
1313              
1314 0           return $q;
1315             }
1316              
1317             sub intersects {
1318 0     0 1   my $self = shift;
1319 0           my $args = shift;
1320              
1321 0           my $q = Rethinkdb::Query->new(
1322             _parent => $self,
1323             _type => $self->_termType->intersects,
1324             args => $args,
1325             );
1326              
1327 0           return $q;
1328             }
1329              
1330             sub polygon_sub {
1331 0     0 1   my $self = shift;
1332 0           my $args = shift;
1333              
1334 0           my $q = Rethinkdb::Query->new(
1335             _parent => $self,
1336             _type => $self->_termType->polygon_sub,
1337             args => $args,
1338             );
1339              
1340 0           return $q;
1341             }
1342              
1343             sub round {
1344 0     0 1   my $self = shift;
1345 0           my $args = shift;
1346              
1347 0           my $q = Rethinkdb::Query->new(
1348             _parent => $self,
1349             _type => $self->_termType->round,
1350             args => $args
1351             );
1352              
1353 0           return $q;
1354             }
1355              
1356             sub ceil {
1357 0     0 1   my $self = shift;
1358 0           my $args = shift;
1359              
1360 0           my $q = Rethinkdb::Query->new(
1361             _parent => $self,
1362             _type => $self->_termType->ceil,
1363             args => $args
1364             );
1365              
1366 0           return $q;
1367             }
1368              
1369             sub floor {
1370 0     0 1   my $self = shift;
1371 0           my $args = shift;
1372              
1373 0           my $q = Rethinkdb::Query->new(
1374             _parent => $self,
1375             _type => $self->_termType->floor,
1376             args => $args
1377             );
1378              
1379 0           return $q;
1380             }
1381              
1382             1;
1383              
1384             =encoding utf8
1385              
1386             =head1 NAME
1387              
1388             Rethinkdb::Query - RethinkDB Query
1389              
1390             =head1 SYNOPSIS
1391              
1392             =head1 DESCRIPTION
1393              
1394             L is a type of query.
1395              
1396             =head1 ATTRIBUTES
1397              
1398             L implements the following attributes.
1399              
1400             =head2 args
1401              
1402             my $query = r->table('marvel')->get(1);
1403             say $query->args;
1404              
1405             The arguments for this instance of a query.
1406              
1407             =head2 optargs
1408              
1409             my $query = r->table('marvel')->get_all(1, { index => 'rank' });
1410             say $query->optargs;
1411              
1412             The optional arguments for this instance of a query.
1413              
1414             =head1 METHODS
1415              
1416             L implements the following methods.
1417              
1418             =head2 new
1419              
1420             This is a specialized constructor that enables chaining the queries together
1421             in a rational way. This constructor should never be called directly by
1422             consumers of this library.
1423              
1424             =head2 run
1425              
1426             r->table('marvel')->run;
1427              
1428             Run a query on a connection.
1429              
1430             The callback will get either an error, a single JSON result, or a cursor,
1431             depending on the query.
1432              
1433             =head2 update
1434              
1435             r->table('posts')->get(1)->update({status => 'published'})->run;
1436              
1437             Update JSON documents in a table. Accepts a JSON document, a ReQL expression,
1438             or a combination of the two.
1439              
1440             =head2 replace
1441              
1442             r->table('posts')->get(1)->replace({
1443             id => 1,
1444             title => 'Lorem ipsum',
1445             content => 'Aleas jacta est',
1446             status => 'draft'
1447             })->run;
1448              
1449             Replace documents in a table. Accepts a JSON document or a ReQL expression, and
1450             replaces the original document with the new one. The new document must have the
1451             same primary key as the original document.
1452              
1453             =head2 delete
1454              
1455             r->table('comments')->
1456             get('7eab9e63-73f1-4f33-8ce4-95cbea626f59')->delete->run;
1457              
1458             Delete one or more documents from a table.
1459              
1460             =head2 filter
1461              
1462             r->table('users')->filter({'age' => 30})->run;
1463              
1464             Get all the documents for which the given predicate is true.
1465              
1466             L can be called on a sequence, selection, or a field containing an
1467             array of elements. The return type is the same as the type on which the
1468             function was called on.
1469              
1470             The body of every filter is wrapped in an implicit C<< default(r->false) >>,
1471             which means that if a non-existence errors is thrown (when you try to access a
1472             field that does not exist in a document), RethinkDB will just ignore the
1473             document. The C value can be changed by passing the named argument
1474             C. Setting this optional argument to C<< r->error >> will cause any
1475             non-existence errors to return a C.
1476              
1477             =head2 inner_join
1478              
1479             r->table('marvel')->inner_join(r->table('dc'), sub($$) {
1480             my ($marvel, $dc) = @_;
1481             return marvel->attr('strength')->lt($dc->attr('strength'));
1482             })->run;
1483              
1484             Returns the inner product of two sequences (e.g. a table, a filter result)
1485             filtered by the predicate. The query compares each row of the left sequence
1486             with each row of the right sequence to find all pairs of rows which satisfy
1487             the predicate. When the predicate is satisfied, each matched pair of rows of
1488             both sequences are combined into a result row.
1489              
1490             =head2 outer_join
1491              
1492             r->table('marvel')->outer_join(r->table('dc'), sub ($$) {
1493             my ($marvel, $dc) = @_;
1494             return $marvel->attr('strength')->lt($dc->attr('strength'));
1495             })->run;
1496              
1497             Computes a left outer join by retaining each row in the left table even if no
1498             match was found in the right table.
1499              
1500             =head2 eq_join
1501              
1502             r->table('players')->eq_join('gameId', r->table('games'))->run;
1503              
1504             Join tables using a field on the left-hand sequence matching primary keys or
1505             secondary indexes on the right-hand table. L is more efficient than
1506             other ReQL join types, and operates much faster. Documents in the result set
1507             consist of pairs of left-hand and right-hand documents, matched when the
1508             field on the left-hand side exists and is non-null and an entry with that
1509             field's value exists in the specified index on the right-hand side.
1510              
1511             =head2 zip
1512              
1513             r->table('marvel')->eq_join('main_dc_collaborator',
1514             r->table('dc'))->zip()->run;
1515              
1516             Used to zip up the result of a join by merging the right fields into
1517             left fields of each member of the sequence.
1518              
1519             =head2 map
1520              
1521             r->table('marvel')->map(sub {
1522             my $hero = shift;
1523             return $hero->attr('combatPower')->add(
1524             $hero->('compassionPower')->mul(2)
1525             );
1526             })->run;
1527              
1528             Transform each element of the sequence by applying the given mapping function.
1529              
1530             =head2 with_fields
1531              
1532             r->table('users')->with_fields('id', 'username', 'posts')->run;
1533              
1534             Plucks one or more attributes from a sequence of objects, filtering out any
1535             objects in the sequence that do not have the specified fields. Functionally,
1536             this is identical to L followed by L on a sequence.
1537              
1538             =head2 concat_map
1539              
1540             r->table('marvel')->concatMap(sub {
1541             my $hero = shift;
1542             return $hero->attr('defeatedMonsters');
1543             })->run;
1544              
1545             Concatenate one or more elements into a single sequence using a mapping
1546             function.
1547              
1548             =head2 order_by
1549              
1550             r->table('posts')->order_by({index => 'date'})->run;
1551             r->table('posts')->order_by({index => r->desc('date')})->run;
1552              
1553             Sort the sequence by document values of the given key(s). To specify the
1554             ordering, wrap the attribute with either Lasc >>|Rethinkdb/asc> or
1555             Ldesc >>|Rethinkdb/desc> (defaults to ascending).
1556              
1557             Sorting without an index requires the server to hold the sequence in memory,
1558             and is limited to 100,000 documents. Sorting with an index can be done on
1559             arbitrarily large tables, or after a L command
1560             using the same index.
1561              
1562             =head2 skip
1563              
1564             r->table('marvel')->order_by('successMetric')->skip(10)->run;
1565              
1566             Skip a number of elements from the head of the sequence.
1567              
1568             =head2 limit
1569              
1570             r->table('marvel')->order_by('belovedness')->limit(10)->run;
1571              
1572             End the sequence after the given number of elements.
1573              
1574             =head2 slice
1575              
1576             r->table('players')->order_by({index => 'age'})->slice(3, 6)->run;
1577              
1578             Return the elements of a sequence within the specified range.
1579              
1580             =head2 nth
1581              
1582             r->expr([1,2,3])->nth(1)->run;
1583              
1584             Get the nth element of a sequence.
1585              
1586             =head2 offsets_of
1587              
1588             r->expr(['a','b','c'])->offsets_of('c')->run;
1589              
1590             Get the indexes of an element in a sequence. If the argument is a predicate,
1591             get the indexes of all elements matching it.
1592              
1593             =head2 is_empty
1594              
1595             r->table('marvel')->is_empty->run;
1596              
1597             Test if a sequence is empty.
1598              
1599             =head2 union
1600              
1601             r->table('marvel')->union(r->table('dc'))->run;
1602              
1603             Concatenate two sequences.
1604              
1605             =head2 sample
1606              
1607             r->table('marvel')->sample(3)->run;
1608              
1609             Select a given number of elements from a sequence with uniform random
1610             distribution. Selection is done without replacement.
1611              
1612             =head2 group
1613              
1614             r->table('games')->group('player')->max('points')->run;
1615              
1616             Takes a stream and partitions it into multiple groups based on the fields or
1617             functions provided. Commands chained after L will be called on each of
1618             these grouped sub-streams, producing grouped data.
1619              
1620             =head2 ungroup
1621              
1622             r->table('games')
1623             ->group('player')->max('points')->attr('points')
1624             ->ungroup()->order_by(r->desc('reduction'))->run;
1625              
1626             Takes a grouped stream or grouped data and turns it into an array of objects
1627             representing the groups. Any commands chained after L will operate on
1628             this array, rather than operating on each group individually. This is useful
1629             if you want to e.g. order the groups by the value of their reduction.
1630              
1631             =head2 reduce
1632              
1633             r->table('posts')->map(sub { return 1; })->reduce(sub($$) {
1634             my ($left, $right) = @_;
1635             return $left->add($right);
1636             })->run;
1637              
1638             Produce a single value from a sequence through repeated application of a
1639             reduction function.
1640              
1641             =head2 count
1642              
1643             r->table('marvel')->count->add(r->table('dc')->count->run
1644              
1645             Count the number of elements in the sequence. With a single argument, count the
1646             number of elements equal to it. If the argument is a function, it is equivalent
1647             to calling filter before count.
1648              
1649             =head2 sum
1650              
1651             r->expr([3, 5, 7])->sum->run;
1652              
1653             Sums all the elements of a sequence. If called with a field name, sums all the
1654             values of that field in the sequence, skipping elements of the sequence that
1655             lack that field. If called with a function, calls that function on every
1656             element of the sequence and sums the results, skipping elements of the sequence
1657             where that function returns C or a non-existence error.
1658              
1659             =head2 avg
1660              
1661             r->expr([3, 5, 7])->avg->run;
1662              
1663             Averages all the elements of a sequence. If called with a field name, averages
1664             all the values of that field in the sequence, skipping elements of the sequence
1665             that lack that field. If called with a function, calls that function on every
1666             element of the sequence and averages the results, skipping elements of the
1667             sequence where that function returns C or a non-existence error.
1668              
1669             =head2 min
1670              
1671             r->expr([3, 5, 7])->min->run;
1672              
1673             Finds the minimum of a sequence. If called with a field name, finds the element
1674             of that sequence with the smallest value in that field. If called with a
1675             function, calls that function on every element of the sequence and returns the
1676             element which produced the smallest value, ignoring any elements where the
1677             function returns C or produces a non-existence error.
1678              
1679             =head2 max
1680              
1681             r->expr([3, 5, 7])->max->run;
1682              
1683             Finds the maximum of a sequence. If called with a field name, finds the element
1684             of that sequence with the largest value in that field. If called with a
1685             function, calls that function on every element of the sequence and returns the
1686             element which produced the largest value, ignoring any elements where the
1687             function returns null or produces a non-existence error.
1688              
1689             =head2 distinct
1690              
1691             r->table('marvel')->concat_map(sub {
1692             my $hero = shift;
1693             return $hero->attr('villainList')
1694             })->distinct->run;
1695              
1696             Remove duplicate elements from the sequence.
1697              
1698             =head2 contains
1699              
1700             r->table('marvel')->get('ironman')->
1701             attr('opponents')->contains('superman')->run;
1702              
1703             Returns whether or not a sequence contains all the specified values, or if
1704             functions are provided instead, returns whether or not a sequence contains
1705             values matching all the specified functions.
1706              
1707             =head2 pluck
1708              
1709             r->table('marvel')->get('IronMan')->
1710             pluck('reactorState', 'reactorPower')->run;
1711              
1712             Plucks out one or more attributes from either an object or a sequence of
1713             objects (projection).
1714              
1715             =head2 without
1716              
1717             r->table('marvel')->get('IronMan')->without('personalVictoriesList')->run;
1718              
1719             The opposite of pluck; takes an object or a sequence of objects, and returns
1720             them with the specified paths removed.
1721              
1722             =head2 merge
1723              
1724             r->table('marvel')->get('IronMan')->merge(
1725             r->table('loadouts')->get('alienInvasionKit')
1726             )->run;
1727              
1728             Merge two objects together to construct a new object with properties from both.
1729             Gives preference to attributes from other when there is a conflict.
1730              
1731             =head2 append
1732              
1733             r->table('marvel')->get('IronMan')->
1734             attr('equipment')->append('newBoots')->run;
1735              
1736             Append a value to an array.
1737              
1738             =head2 prepend
1739              
1740             r->table('marvel')->get('IronMan')->
1741             attr('equipment')->prepend('newBoots')->run;
1742              
1743             Prepend a value to an array.
1744              
1745             =head2 difference
1746              
1747             r->table('marvel')->get('IronMan')->
1748             attr('equipment')->difference(['Boots'])->run;
1749              
1750             Remove the elements of one array from another array.
1751              
1752             =head2 set_insert
1753              
1754             r->table('marvel')->get('IronMan')->
1755             attr('equipment')->set_insert('newBoots')->run;
1756              
1757             Add a value to an array and return it as a set (an array with distinct values).
1758              
1759             =head2 set_union
1760              
1761             r->table('marvel')->get('IronMan')->
1762             attr('equipment')->set_union(['newBoots', 'arc_reactor'])->run;
1763              
1764             Add a several values to an array and return it as a set (an array with distinct
1765             values).
1766              
1767             =head2 set_intersection
1768              
1769             r->table('marvel')->get('IronMan')->attr('equipment')->
1770             set_intersection(['newBoots', 'arc_reactor'])->run;
1771              
1772             Intersect two arrays returning values that occur in both of them as a set (an
1773             array with distinct values).
1774              
1775             =head2 set_difference
1776              
1777             r->table('marvel')->get('IronMan')->attr('equipment')->
1778             set_difference(['newBoots', 'arc_reactor'])->run;
1779              
1780             Remove the elements of one array from another and return them as a set (an
1781             array with distinct values).
1782              
1783             =head2 get_field
1784              
1785             r->table('marvel')->get('IronMan')->get_field('firstAppearance')->run;
1786              
1787             Get a single field from an object. If called on a sequence, gets that field
1788             from every object in the sequence, skipping objects that lack it.
1789              
1790             =head2 bracket
1791              
1792             r->table('marvel')->get('IronMan')->bracket('firstAppearance')->run;
1793             r->expr([10, 20, 30, 40, 50])->bracket(3)->run;
1794              
1795             Get a single field from an object or a single element from a sequence.
1796              
1797             =head2 attr
1798              
1799             r->table('marvel')->get('IronMan')->attr('firstAppearance')->run;
1800             r->expr([10, 20, 30, 40, 50])->attr(3)->run;
1801              
1802             Get a single field from an object or a single element from a sequence.
1803              
1804             DEPERCATED: This method has been renamed to L, but L will
1805             remain for a number of releases for backwards compatibility.
1806              
1807             =head2 has_fields
1808              
1809             r->table('players')->has_fields('games_won')->run;
1810              
1811             Test if an object has one or more fields. An object has a field if it has that
1812             key and the key has a non-null value. For instance, the object
1813             C<< {'a' => 1, 'b' => 2, 'c' => null} >> has the fields C and C.
1814              
1815             =head2 insert_at
1816              
1817             r->expr(['Iron Man', 'Spider-Man'])->insert_at(1, 'Hulk')->run;
1818              
1819             Insert a value in to an array at a given index. Returns the modified array.
1820              
1821             =head2 splice_at
1822              
1823             r->expr(['Iron Man', 'Spider-Man'])->splice_at(1, ['Hulk', 'Thor'])->run;
1824              
1825             Insert several values in to an array at a given index. Returns the modified
1826             array.
1827              
1828             =head2 delete_at
1829              
1830             r->expr(['a','b','c','d','e','f'])->delete_at(1)->run;
1831              
1832             Remove one or more elements from an array at a given index. Returns the
1833             modified array.
1834              
1835             =head2 change_at
1836              
1837             r->expr(['Iron Man', 'Bruce', 'Spider-Man'])->change_at(1, 'Hulk')->run;
1838              
1839             Change a value in an array at a given index. Returns the modified array.
1840              
1841             =head2 keys
1842              
1843             r->table('marvel')->get('ironman')->keys->run;
1844              
1845             Return an array containing all of the object's keys.
1846              
1847             =head2 match
1848              
1849             r->table('users')->filter(sub {
1850             my $doc = shift;
1851             return $doc->attr('name')->match('^A')
1852             })->run;
1853              
1854             Matches against a regular expression. If there is a match, returns an object
1855             with the fields:
1856              
1857             =head2 split
1858              
1859             r->expr('foo bar bax')->split->run;
1860             r->expr('foo,bar,bax')->split(",")->run;
1861             r->expr('foo,bar,bax')->split(",", 1)->run;
1862              
1863             Splits a string into substrings. Splits on whitespace when called with no
1864             arguments. When called with a separator, splits on that separator. When called
1865             with a separator and a maximum number of splits, splits on that separator at
1866             most C times. (Can be called with C as the separator if you
1867             want to split on whitespace while still specifying C.)
1868              
1869             Mimics the behavior of Python's C in edge cases, except for
1870             splitting on the empty string, which instead produces an array of
1871             single-character strings.
1872              
1873             =head2 upcase
1874              
1875             r->expr('Sentence about LaTeX.')->upcase->run;
1876              
1877             Uppercases a string.
1878              
1879             =head2 downcase
1880              
1881             r->expr('Sentence about LaTeX.')->downcase->run;
1882              
1883             Lowercases a string.
1884              
1885             =head2 add
1886              
1887             r->expr(2)->add(2)->run;
1888              
1889             Sum two numbers, concatenate two strings, or concatenate 2 arrays.
1890              
1891             =head2 sub
1892              
1893             r->expr(2)->sub(2)->run;
1894              
1895             Subtract two numbers.
1896              
1897             =head2 mul
1898              
1899             r->expr(2)->mul(2)->run;
1900              
1901             Multiply two numbers, or make a periodic array.
1902              
1903             =head2 div
1904              
1905             r->expr(2)->div(2)->run;
1906              
1907             Divide two numbers.
1908              
1909             =head2 mod
1910              
1911             r->expr(2)->mod(2)->run;
1912              
1913             Find the remainder when dividing two numbers.
1914              
1915             =head2 and
1916              
1917             r->expr(r->true)->and(r->false)->run;
1918              
1919             Compute the logical C of two or more values.
1920              
1921             =head2 or
1922              
1923             r->expr(r->true)->or(r->false)->run;
1924              
1925             Compute the logical C of two or more values.
1926              
1927             =head2 eq
1928              
1929             r->expr(2)->eq(2)->run;
1930              
1931             Test if two values are equal.
1932              
1933             =head2 ne
1934              
1935             r->expr(2)->ne(2)->run;
1936              
1937             Test if two values are not equal.
1938              
1939             =head2 gt
1940              
1941             r->expr(2)->gt(2)->run;
1942              
1943             Test if the first value is greater than other.
1944              
1945             =head2 ge
1946              
1947             r->expr(2)->ge(2)->run;
1948              
1949             Test if the first value is greater than or equal to other.
1950              
1951             =head2 lt
1952              
1953             r->expr(2)->lt(2)->run;
1954              
1955             Test if the first value is less than other.
1956              
1957             =head2 le
1958              
1959             r->expr(2)->le(2)->run;
1960              
1961             Test if the first value is less than or equal to other.
1962              
1963             =head2 not
1964              
1965             r->expr(r->true)->not->run;
1966              
1967             Compute the logical inverse (not) of an expression.
1968              
1969             =head2 in_timezone
1970              
1971             r->now->in_timezone('-08:00')->hours->run;
1972              
1973             Return a new time object with a different timezone. While the time stays the
1974             same, the results returned by methods such as L will change since they
1975             take the timezone into account. The timezone argument has to be of the ISO 8601
1976             format.
1977              
1978             =head2 timezone
1979              
1980             r->table('users')->filter(sub {
1981             my $user = shift;
1982             return $user->attr('subscriptionDate')->timezone->eql('-07:00');
1983             })->run;
1984              
1985             Return the timezone of the time object.
1986              
1987             =head2 during
1988              
1989             r->table('posts')->filter(
1990             r->row->attr('date')->during(
1991             r->time(2013, 12, 1, 'Z'),
1992             r->time(2013, 12, 10, 'Z')
1993             )
1994             )->run;
1995              
1996             Return if a time is between two other times (by default, inclusive for the
1997             start, exclusive for the end).
1998              
1999             =head2 date
2000              
2001             r->table('users')->filter(sub {
2002             my $user = shift;
2003             return user->attr('birthdate')->date->eql(r->now->date);
2004             })->run;
2005              
2006             Return a new time object only based on the day, month and year (ie. the same
2007             day at 00:00).
2008              
2009             =head2 time_of_day
2010              
2011             r->table('posts')->filter(
2012             r->row->attr('date')->time_of_day->le(12*60*60)
2013             )->run;
2014              
2015             Return the number of seconds elapsed since the beginning of the day stored in
2016             the time object.
2017              
2018             =head2 year
2019              
2020             r->table('users')->filter(sub {
2021             my $user = shift;
2022             return user->attr('birthdate')->year->eql(1986);
2023             })->run;
2024              
2025             Return the year of a time object.
2026              
2027             =head2 month
2028              
2029             r->table('users')->filter(
2030             r->row->attr('birthdate')->month->eql(11)
2031             )->run;
2032              
2033             Return the month of a time object as a number between 1 and 12. For your
2034             convenience, the terms Ljanuary >>|Rethinkdb/january>,
2035             Lfebruary >>|Rethinkdb/february> etc. are defined and map to the
2036             appropriate integer.
2037              
2038             =head2 day
2039              
2040             r->table('users')->filter(
2041             r->row->attr('birthdate')->day->eql(24)
2042             )->run;
2043              
2044             Return the day of a time object as a number between 1 and 31.
2045              
2046             =head2 day_of_week
2047              
2048             r->now->day_of_week->run;
2049              
2050             Return the day of week of a time object as a number between 1 and 7 (following
2051             ISO 8601 standard). For your convenience, the terms r.monday, r.tuesday etc.
2052             are defined and map to the appropriate integer.
2053              
2054             =head2 day_of_year
2055              
2056             r->now->day_of_year->run;
2057              
2058             Return the day of the year of a time object as a number between 1 and 366
2059             (following ISO 8601 standard).
2060              
2061             =head2 hours
2062              
2063             r->table('posts')->filter(sub {
2064             my $post = shift;
2065             return $post->attr('date')->hours->lt(4);
2066             })->run;
2067              
2068             Return the hour in a time object as a number between 0 and 23.
2069              
2070             =head2 minutes
2071              
2072             r->table('posts')->filter(sub {
2073             my $post = shift;
2074             return $post->attr('date')->minutes->lt(10);
2075             })->run;
2076              
2077             Return the minute in a time object as a number between 0 and 59.
2078              
2079             =head2 seconds
2080              
2081             r->table('posts')->filter(sub {
2082             my $post = shift;
2083             return $post->attr('date')->seconds->lt(30);
2084             })->run;
2085              
2086             Return the seconds in a time object as a number between 0 and 59.999 (double
2087             precision).
2088              
2089             =head2 to_iso8601
2090              
2091             r->now->to_iso8601->run;
2092              
2093             Convert a time object to its ISO 8601 format.
2094              
2095             =head2 to_epoch_time
2096              
2097             r->now->to_epoch_time->run;
2098              
2099             Convert a time object to its epoch time.
2100              
2101             =head2 do
2102              
2103             r->table('players')->get('86be93eb-a112-48f5-a829-15b2cb49de1d')->do(sub {
2104             my $player = shift;
2105             return $player->attr('gross_score')->sub($player->attr('course_handicap'));
2106             })->run
2107              
2108             Evaluate an expression and pass its values as arguments to a function or to an
2109             expression.
2110              
2111             =head2 for_each
2112              
2113             r->table('marvel')->for_each(sub {
2114             my $hero = shift;
2115             r->table('villains')->get($hero->attr('villainDefeated'))->delete;
2116             })->run;
2117              
2118             Loop over a sequence, evaluating the given write query for each element.
2119              
2120             =head2 default
2121              
2122             r->table('posts')->map(sub {
2123             my $post = shift;
2124             return {
2125             title => $post->attr('title'),
2126             author => $post->attr('author')->default('Anonymous')
2127             };
2128             })->run
2129              
2130             Handle non-existence errors. Tries to evaluate and return its first argument.
2131             If an error related to the absence of a value is thrown in the process, or if
2132             its first argument returns C, returns its second argument.
2133             (Alternatively, the second argument may be a function which will be called with
2134             either the text of the non-existence error or C.)
2135              
2136             =head2 coerce_to
2137              
2138             r->table('posts')->map(sub {
2139             my $post = shift;
2140             return $post->merge({
2141             'comments' => r->table('comments')->get_all(
2142             $post->attr('id'), { index => 'post_id' })->coerce_to('array')
2143             });
2144             )->run
2145              
2146             Convert a value of one type into another.
2147              
2148             =head2 type_of
2149              
2150             r->expr('foo')->type_of->run;
2151              
2152             Gets the type of a value.
2153              
2154             =head2 info
2155              
2156             r->table('marvel')->info->run;
2157              
2158             Get information about a ReQL value.
2159              
2160             =head2 fill
2161              
2162             r->table('geo')->insert(
2163             {
2164             'id' => 201,
2165             'rectangle' => r->line(
2166             [ -122.423246, 37.779388 ],
2167             [ -122.423246, 37.329898 ],
2168             [ -121.886420, 37.329898 ],
2169             [ -121.886420, 37.779388 ]
2170             )
2171             }
2172             )->run;
2173              
2174             r->table('geo')->get(201)
2175             ->update( { 'rectangle' => r->row->bracket('rectangle')->fill },
2176             { non_atomic => r->true } )->run;
2177              
2178              
2179             Convert a C object into a C object. If the last point does not
2180             specify the same coordinates as the first point, C will close the
2181             polygon by connecting them.
2182              
2183             =head2 includes
2184              
2185             r->circle( r->point( -117.220406, 32.719464 ), 2000 )
2186             ->includes( r->point( -117.206201, 32.725186 ) )->run($conn);
2187              
2188             Tests whether a geometry object is completely contained within another. When
2189             applied to a sequence of geometry objects, L acts as a L,
2190             returning a sequence of objects from the sequence that include the argument.
2191              
2192             =head2 intersects
2193              
2194             r->circle( r->point( -117.220406, 32.719464 ), 2000 )
2195             ->intersects( r->point( -117.206201, 32.725186 ) )->run($conn);
2196              
2197             Tests whether two geometry objects intersect with one another. When applied
2198             to a sequence of geometry objects, L acts as a L,
2199             returning a sequence of objects from the sequence that intersect with the
2200             argument.
2201              
2202             =head2 polygon_sub
2203              
2204             r->polygon(
2205             [ -122.4, 37.7 ],
2206             [ -122.4, 37.3 ],
2207             [ -121.8, 37.3 ],
2208             [ -121.8, 37.7 ]
2209             )->polygon_sub(
2210             r->polygon(
2211             [ -122.3, 37.4 ],
2212             [ -122.3, 37.6 ],
2213             [ -122.0, 37.6 ],
2214             [ -122.0, 37.4 ]
2215             )
2216             )->run($conn);
2217              
2218             Use C to "punch out" a hole in C. C must be
2219             completely contained within C and must have no holes itself (it must
2220             not be the output of L itself).
2221              
2222             =head2 to_geojson
2223              
2224             r->table('geo')->get('sfo')->bracket('location')->to_geojson->run;
2225              
2226             Convert a ReQL geometry object to a L object.
2227              
2228             =head2 round
2229              
2230             r->expr(-12.567)->round->run($conn);
2231              
2232             Rounds the given value to the nearest whole integer. For example, values of
2233             1.0 up to but not including 1.5 will return 1.0, similar to L; values
2234             of 1.5 up to 2.0 will return 2.0, similar to L.
2235              
2236             =head2 ceil
2237              
2238             r->expr(-12.567)->ceil->run($conn);
2239              
2240             Rounds the given value up, returning the smallest integer value greater than
2241             or equal to the given value (the value's ceiling).
2242              
2243             =head2 floor
2244              
2245             r->expr(-12.567)->floor->run($conn);
2246              
2247             Rounds the given value down, returning the largest integer value less than or
2248             equal to the given value (the value's floor).
2249              
2250             =head1 SEE ALSO
2251              
2252             L, L
2253              
2254             =cut