line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Rethinkdb::Query::Database; |
2
|
15
|
|
|
15
|
|
52
|
use Rethinkdb::Base 'Rethinkdb::Query'; |
|
15
|
|
|
|
|
17
|
|
|
15
|
|
|
|
|
68
|
|
3
|
|
|
|
|
|
|
|
4
|
15
|
|
|
15
|
|
75
|
use Scalar::Util 'weaken'; |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
9269
|
|
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 grant { |
110
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
111
|
0
|
|
|
|
|
|
my $user = shift; |
112
|
0
|
|
|
|
|
|
my $perms = shift; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
115
|
|
|
|
|
|
|
_rdb => $self->_rdb, |
116
|
|
|
|
|
|
|
_type => $self->_termType->grant, |
117
|
|
|
|
|
|
|
args => [ $user, $perms ] |
118
|
|
|
|
|
|
|
); |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
return $q; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub config { |
124
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
127
|
|
|
|
|
|
|
_parent => $self, |
128
|
|
|
|
|
|
|
_type => $self->_termType->config, |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
return $q; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub rebalance { |
135
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
138
|
|
|
|
|
|
|
_parent => $self, |
139
|
|
|
|
|
|
|
_type => $self->_termType->rebalance, |
140
|
|
|
|
|
|
|
); |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
return $q; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub reconfigure { |
146
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
147
|
0
|
|
|
|
|
|
my $args = shift; |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
150
|
|
|
|
|
|
|
_parent => $self, |
151
|
|
|
|
|
|
|
_type => $self->_termType->reconfigure, |
152
|
|
|
|
|
|
|
optargs => $args |
153
|
|
|
|
|
|
|
); |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
return $q; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub wait { |
159
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
my $q = Rethinkdb::Query->new( |
162
|
|
|
|
|
|
|
_parent => $self, |
163
|
|
|
|
|
|
|
_type => $self->_termType->wait, |
164
|
|
|
|
|
|
|
); |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
return $q; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=encoding utf8 |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 NAME |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Rethinkdb::Query::Database - RethinkDB Query Database |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 SYNOPSIS |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 DESCRIPTION |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
L is a type of query that represents a database. |
182
|
|
|
|
|
|
|
This classes contains methods to interact with a database or the underlying |
183
|
|
|
|
|
|
|
tables. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
L implements the following attributes. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 name |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
my $db = r->db('better'); |
192
|
|
|
|
|
|
|
say $db->name; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
The name of the database. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 METHODS |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 create |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
r->db('test')->create('superheroes')->run; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Create a database. A RethinkDB database is a collection of tables, similar to |
203
|
|
|
|
|
|
|
relational databases. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
If successful, the operation returns an object: C<< {created => 1} >>. If a |
206
|
|
|
|
|
|
|
database with the same name already exists the operation returns an |
207
|
|
|
|
|
|
|
C. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
B: that you can only use alphanumeric characters and underscores for the |
210
|
|
|
|
|
|
|
database name. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 drop |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
r->db('comics')->drop('superheroes')->run; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Drop a database. The database, all its tables, and corresponding data will be |
217
|
|
|
|
|
|
|
deleted. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
If successful, the operation returns the object C<< {dropped => 1} >>. If the |
220
|
|
|
|
|
|
|
specified database doesn't exist a C will be returned. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head2 list |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
r->db('sillyStuff')->list->run; |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
List all database names in the system. The result is a list of strings. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head2 table |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
r->db('newStuff')->table('weapons')->run; |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Select all documents in a table from this database. This command can be chained |
233
|
|
|
|
|
|
|
with other commands to do further processing on the data. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head2 table_create |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
r->db('test')->table_create('dc_universe')->run; |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Create a table. A RethinkDB table is a collection of JSON documents. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
If successful, the operation returns an object: C<< {created => 1} >>. If a |
242
|
|
|
|
|
|
|
table with the same name already exists, the operation returns a |
243
|
|
|
|
|
|
|
C. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
B that you can only use alphanumeric characters and underscores for the |
246
|
|
|
|
|
|
|
table name. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head2 table_drop |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
r->db('test')->table_drop('dc_universe')->run; |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Drop a table. The table and all its data will be deleted. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
If successful, the operation returns an object: C<< {dropped => 1} >>. If the |
255
|
|
|
|
|
|
|
specified table doesn't exist a C is returned. |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head2 table_list |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
r->db('test')->table_list->run; |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
List all table names in a database. The result is a list of strings. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head2 grant |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
r->db('test')->grant( 'username', { read => r->true, write => r->false } ) |
266
|
|
|
|
|
|
|
->run; |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
Grant or deny access permissions for a user account on a database. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head2 config |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
r->db('test')->config->run; |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Query (read and/or update) the configurations for individual databases. |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=head2 rebalance |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
r->db('test')->rebalance->run; |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
Rebalances the shards of all tables in the database. |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head2 reconfigure |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
r->db('test')->reconfigure({ shards => 2, replicas => 1 })->run; |
285
|
|
|
|
|
|
|
r->db('test')->reconfigure( |
286
|
|
|
|
|
|
|
{ |
287
|
|
|
|
|
|
|
shards => 2, |
288
|
|
|
|
|
|
|
replicas => { wooster => 1, wayne => 1 }, |
289
|
|
|
|
|
|
|
primary_replica_tag => 'wooster' |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
)->run; |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
Reconfigure all table's sharding and replication. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head2 wait |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
r->db('test')->wait->run; |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
Wait for all the tables in a database to be ready. A table may be |
300
|
|
|
|
|
|
|
temporarily unavailable after creation, rebalancing or reconfiguring. |
301
|
|
|
|
|
|
|
The L command blocks until the given database is fully up to date. |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=cut |