line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Rethinkdb::Query::Database; |
2
|
15
|
|
|
15
|
|
52
|
use Rethinkdb::Base 'Rethinkdb::Query'; |
|
15
|
|
|
|
|
19
|
|
|
15
|
|
|
|
|
80
|
|
3
|
|
|
|
|
|
|
|
4
|
15
|
|
|
15
|
|
81
|
use Scalar::Util 'weaken'; |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
8999
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has [qw{ _rdb name }]; |
7
|
|
|
|
|
|
|
has '_type' => sub { return Rethinkdb::Protocol->new->term->termType->db; }; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub create { |
10
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
11
|
0
|
|
0
|
|
|
|
my $name = shift || $self->name; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
14
|
|
|
|
|
|
|
_rdb => $self->_rdb, |
15
|
|
|
|
|
|
|
_type => $self->_termType->db_create, |
16
|
|
|
|
|
|
|
args => $name, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
weaken $q->{_rdb}; |
20
|
0
|
|
|
|
|
|
return $q; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub drop { |
24
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
25
|
0
|
|
0
|
|
|
|
my $name = shift || $self->name; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
28
|
|
|
|
|
|
|
_rdb => $self->_rdb, |
29
|
|
|
|
|
|
|
_type => $self->_termType->db_drop, |
30
|
|
|
|
|
|
|
args => $name, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
weaken $q->{_rdb}; |
34
|
0
|
|
|
|
|
|
return $q; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub list { |
38
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
41
|
|
|
|
|
|
|
_rdb => $self->_rdb, |
42
|
|
|
|
|
|
|
_type => $self->_termType->db_list, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
weaken $q->{_rdb}; |
46
|
0
|
|
|
|
|
|
return $q; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub table_create { |
50
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
51
|
0
|
|
|
|
|
|
my $args = shift; |
52
|
0
|
0
|
|
|
|
|
my $optargs = ref $_[0] ? $_[0] : {@_}; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
55
|
|
|
|
|
|
|
_parent => $self, |
56
|
|
|
|
|
|
|
_type => $self->_termType->table_create, |
57
|
|
|
|
|
|
|
args => $args, |
58
|
|
|
|
|
|
|
optargs => $optargs, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $q; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub table_drop { |
65
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
66
|
0
|
|
|
|
|
|
my $args = shift; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
69
|
|
|
|
|
|
|
_parent => $self, |
70
|
|
|
|
|
|
|
_type => $self->_termType->table_drop, |
71
|
|
|
|
|
|
|
args => $args, |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return $q; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub table_list { |
78
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
81
|
|
|
|
|
|
|
_parent => $self, |
82
|
|
|
|
|
|
|
_type => $self->_termType->table_list, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $q; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub table { |
89
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
90
|
0
|
|
|
|
|
|
my $name = shift; |
91
|
0
|
|
|
|
|
|
my $outdated = shift; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $optargs = {}; |
94
|
0
|
0
|
|
|
|
|
if ($outdated) { |
95
|
0
|
|
|
|
|
|
$optargs = { use_outdated => 1 }; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $t = Rethinkdb::Query::Table->new( |
99
|
|
|
|
|
|
|
_parent => $self, |
100
|
|
|
|
|
|
|
_type => $self->_termType->table, |
101
|
|
|
|
|
|
|
name => $name, |
102
|
|
|
|
|
|
|
args => $name, |
103
|
|
|
|
|
|
|
optargs => $optargs, |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
return $t; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub config { |
110
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
113
|
|
|
|
|
|
|
_parent => $self, |
114
|
|
|
|
|
|
|
_type => $self->_termType->config, |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
return $q; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub rebalance { |
121
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
124
|
|
|
|
|
|
|
_parent => $self, |
125
|
|
|
|
|
|
|
_type => $self->_termType->rebalance, |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return $q; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub reconfigure { |
132
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
133
|
0
|
|
|
|
|
|
my $args = shift; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
136
|
|
|
|
|
|
|
_parent => $self, |
137
|
|
|
|
|
|
|
_type => $self->_termType->reconfigure, |
138
|
|
|
|
|
|
|
optargs => $args |
139
|
|
|
|
|
|
|
); |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
return $q; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub wait { |
145
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
148
|
|
|
|
|
|
|
_parent => $self, |
149
|
|
|
|
|
|
|
_type => $self->_termType->wait, |
150
|
|
|
|
|
|
|
); |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return $q; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=encoding utf8 |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 NAME |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Rethinkdb::Query::Database - RethinkDB Query Database |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 SYNOPSIS |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 DESCRIPTION |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L is a type of query that represents a database. |
168
|
|
|
|
|
|
|
This classes contains methods to interact with a database or the underlying |
169
|
|
|
|
|
|
|
tables. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
L implements the following attributes. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 name |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $db = r->db('better'); |
178
|
|
|
|
|
|
|
say $db->name; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
The name of the database. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 METHODS |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 create |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
r->db('test')->create('superheroes')->run; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Create a database. A RethinkDB database is a collection of tables, similar to |
189
|
|
|
|
|
|
|
relational databases. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
If successful, the operation returns an object: C<< {created => 1} >>. If a |
192
|
|
|
|
|
|
|
database with the same name already exists the operation returns an |
193
|
|
|
|
|
|
|
C. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
B: that you can only use alphanumeric characters and underscores for the |
196
|
|
|
|
|
|
|
database name. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 drop |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
r->db('comics')->drop('superheroes')->run; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Drop a database. The database, all its tables, and corresponding data will be |
203
|
|
|
|
|
|
|
deleted. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
If successful, the operation returns the object C<< {dropped => 1} >>. If the |
206
|
|
|
|
|
|
|
specified database doesn't exist a C will be returned. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 list |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
r->db('sillyStuff')->list->run; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
List all database names in the system. The result is a list of strings. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 table |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
r->db('newStuff')->table('weapons')->run; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Select all documents in a table from this database. This command can be chained |
219
|
|
|
|
|
|
|
with other commands to do further processing on the data. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 table_create |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
r->db('test')->table_create('dc_universe')->run; |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Create a table. A RethinkDB table is a collection of JSON documents. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
If successful, the operation returns an object: C<< {created => 1} >>. If a |
228
|
|
|
|
|
|
|
table with the same name already exists, the operation returns a |
229
|
|
|
|
|
|
|
C. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
B that you can only use alphanumeric characters and underscores for the |
232
|
|
|
|
|
|
|
table name. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head2 table_drop |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
r->db('test')->table_drop('dc_universe')->run; |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Drop a table. The table and all its data will be deleted. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
If successful, the operation returns an object: C<< {dropped => 1} >>. If the |
241
|
|
|
|
|
|
|
specified table doesn't exist a C is returned. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head2 table_list |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
r->db('test')->table_list->run; |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
List all table names in a database. The result is a list of strings. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head2 config |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
r->db('test')->config->run; |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Query (read and/or update) the configurations for individual databases. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head2 rebalance |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
r->db('test')->rebalance->run; |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
Rebalances the shards of all tables in the database. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head2 reconfigure |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
r->db('test')->reconfigure({ shards => 2, replicas => 1 })->run; |
264
|
|
|
|
|
|
|
r->db('test')->reconfigure( |
265
|
|
|
|
|
|
|
{ |
266
|
|
|
|
|
|
|
shards => 2, |
267
|
|
|
|
|
|
|
replicas => { wooster => 1, wayne => 1 }, |
268
|
|
|
|
|
|
|
primary_replica_tag => 'wooster' |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
)->run; |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
Reconfigure all table's sharding and replication. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head2 wait |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
r->db('test')->wait->run; |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
Wait for all the tables in a database to be ready. A table may be |
279
|
|
|
|
|
|
|
temporarily unavailable after creation, rebalancing or reconfiguring. |
280
|
|
|
|
|
|
|
The L command blocks until the given database is fully up to date. |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=cut |