Skip to content

Commit

Permalink
Merge pull request #30 from njlg/rethinkdb-v234
Browse files Browse the repository at this point in the history
Rethinkdb v2.3.4
  • Loading branch information
njlg authored Jul 1, 2016
2 parents a14c1c6 + 417aa38 commit 90b28c8
Show file tree
Hide file tree
Showing 13 changed files with 491 additions and 59 deletions.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.12 2016-04-29
- Fix for Issue #22
- Fixing some bad tests
- Tested with RethinkDB v2.3.1

0.11 2015-09-17
- RethinkDB 2.1.0-1 compatibility
- Geospatial functionality
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ See http://njlg.info/perl-rethinkdb/

## Notes

* This version is compatible with RethinkDB 2.1.3
* This version is compatible with RethinkDB 2.3.4
* No authentication support yet
* This is still in beta stage
* For examples see the tests in `t/*.t` or see the documentation (link above)

Expand Down
44 changes: 28 additions & 16 deletions external/ql2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ message VersionDummy { // We need to wrap it like this for some
V0_2 = 0x723081e1; // Authorization key during handshake
V0_3 = 0x5f75e83e; // Authorization key and protocol during handshake
V0_4 = 0x400c2d20; // Queries execute in parallel
V1_0 = 0x34c2bdc3; // Users and permissions
}

// The protocol to use after the handshake, specified in V0_3
Expand All @@ -64,14 +65,15 @@ message VersionDummy { // We need to wrap it like this for some
// * A [STOP] query with the same token as a [START] query that you want to stop.
// * A [NOREPLY_WAIT] query with a unique per-connection token. The server answers
// with a [WAIT_COMPLETE] [Response].
// * A [SERVER_INFO] query. The server answers with a [SERVER_INFO] [Response].
message Query {
enum QueryType {
START = 1; // Start a new query.
CONTINUE = 2; // Continue a query that returned [SUCCESS_PARTIAL]
// (see [Response]).
STOP = 3; // Stop a query partway through executing.
NOREPLY_WAIT = 4;
// Wait for noreply operations to finish.
START = 1; // Start a new query.
CONTINUE = 2; // Continue a query that returned [SUCCESS_PARTIAL]
// (see [Response]).
STOP = 3; // Stop a query partway through executing.
NOREPLY_WAIT = 4; // Wait for noreply operations to finish.
SERVER_INFO = 5; // Get server information.
}
optional QueryType type = 1;
// A [Term] is how we represent the operations we want a query to perform.
Expand All @@ -97,8 +99,8 @@ message Query {
// A backtrace frame (see `backtrace` in Response below)
message Frame {
enum FrameType {
POS = 1; // Error occured in a positional argument.
OPT = 2; // Error occured in an optional argument.
POS = 1; // Error occurred in a positional argument.
OPT = 2; // Error occurred in an optional argument.
}
optional FrameType type = 1;
optional int64 pos = 2; // The index of the positional argument.
Expand All @@ -120,6 +122,9 @@ message Response {
// more of the sequence. Keep sending [CONTINUE]
// queries until you get back [SUCCESS_SEQUENCE].
WAIT_COMPLETE = 4; // A [NOREPLY_WAIT] query completed.
SERVER_INFO = 5; // The data for a [SERVER_INFO] request. This is
// the same as `SUCCESS_ATOM` except that there will
// never be profiling data.

// These response types indicate failure.
CLIENT_ERROR = 16; // Means the client is buggy. An example is if the
Expand All @@ -145,6 +150,7 @@ message Response {
OP_FAILED = 4100000;
OP_INDETERMINATE = 4200000;
USER = 5000000;
PERMISSION_ERROR = 6000000;
}
optional ErrorType error_type = 7;

Expand Down Expand Up @@ -174,14 +180,15 @@ message Response {

optional int64 token = 2; // Indicates what [Query] this response corresponds to.

// [response] contains 1 RQL datum if [type] is [SUCCESS_ATOM], or many RQL
// data if [type] is [SUCCESS_SEQUENCE] or [SUCCESS_PARTIAL]. It contains 1
// [response] contains 1 RQL datum if [type] is [SUCCESS_ATOM] or
// [SERVER_INFO]. [response] contains many RQL data if [type] is
// [SUCCESS_SEQUENCE] or [SUCCESS_PARTIAL]. [response] contains 1
// error message (of type [R_STR]) in all other cases.
repeated Datum response = 3;

// If [type] is [CLIENT_ERROR], [TYPE_ERROR], or [RUNTIME_ERROR], then a
// backtrace will be provided. The backtrace says where in the query the
// error occured. Ideally this information will be presented to the user as
// error occurred. Ideally this information will be presented to the user as
// a pretty-printed version of their query with the erroneous section
// underlined. A backtrace is a series of 0 or more [Frame]s, each of which
// specifies either the index of a positional argument or the name of an
Expand Down Expand Up @@ -227,8 +234,6 @@ message Datum {
optional Datum val = 2;
}
repeated AssocPair r_object = 6;

extensions 10000 to 20000;
}

// A [Term] is either a piece of data (see **Datum** above), or an operator and
Expand Down Expand Up @@ -383,6 +388,8 @@ message Term {
// | Sequence, STRING -> Sequence
// Return an array containing the keys of the object.
KEYS = 94; // OBJECT -> ARRAY
// Return an array containing the values of the object.
VALUES = 186; // OBJECT -> ARRAY
// Creates an object
OBJECT = 143; // STRING, DATUM, ... -> OBJECT
// Check whether an object contains all the specified fields,
Expand Down Expand Up @@ -413,6 +420,8 @@ message Term {
// The arity of the function should be
// Sequence..., Function(sizeof...(Sequence)) -> Sequence

FOLD = 187; // Sequence, Datum, Function(2), {Function(3), Function(1)

// Filter a sequence with either a function or a shortcut
// object (see API docs for details). The body of FILTER is
// wrapped in an implicit `.default(false)`, and you can
Expand Down Expand Up @@ -545,6 +554,11 @@ message Term {
// written to disk.
SYNC = 138; // Table -> OBJECT

// Set global, database, or table-specific permissions
GRANT = 188; // -> OBJECT
// Database -> OBJECT
// Table -> OBJECT

// * Secondary indexes OPs
// Creates a new secondary index with a particular name and definition.
INDEX_CREATE = 75; // Table, STRING, Function(1), {multi:BOOL} -> OBJECT
Expand All @@ -554,7 +568,7 @@ message Term {
INDEX_LIST = 77; // Table -> ARRAY
// Gets information about whether or not a set of indexes are ready to
// be accessed. Returns a list of objects that look like this:
// {index:STRING, ready:BOOL[, blocks_processed:NUMBER, blocks_total:NUMBER]}
// {index:STRING, ready:BOOL[, progress:NUMBER]}
INDEX_STATUS = 139; // Table, STRING... -> ARRAY
// Blocks until a set of indexes are ready to be accessed. Returns the
// same values INDEX_STATUS.
Expand Down Expand Up @@ -779,8 +793,6 @@ message Term {
repeated AssocPair optargs = 4; // Holds the optional arguments of the query.
// (Note that the order of the optional arguments doesn't matter; think of a
// Hash.)

extensions 10000 to 20000;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
51 changes: 48 additions & 3 deletions lib/Rethinkdb.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ sub connect {
return $io->connect;
}

sub server {
my $self = shift;

return $self->io->server;
}

# DATABASES

sub db_create {
Expand Down Expand Up @@ -110,9 +116,9 @@ sub db {
my $name = shift;

my $db = Rethinkdb::Query::Database->new(
_rdb => $self,
name => $name,
args => $name,
_rdb => $self,
name => $name,
args => $name,
);

weaken $db->{_rdb};
Expand Down Expand Up @@ -811,6 +817,20 @@ sub floor {
return $q;
}

sub grant {
my $self = shift;
my $user = shift;
my $perms = shift;

my $q = Rethinkdb::Query->new(
_rdb => $self,
_type => $self->term->termType->grant,
args => [ $user, $perms ]
);

return $q;
}

sub true { return Rethinkdb::_True->new; }
sub false { return Rethinkdb::_False->new; }

Expand Down Expand Up @@ -912,6 +932,25 @@ connection will be set via C<io> in the new instance.
Create a new connection to a RethinkDB shard. Creating a connection tries to
contact the RethinkDB shard immediately and will fail if the connection fails.
=head2 server
r->server->run;
Return information about the server being used by the default connection.
The server command returns either two or three fields:
=over
=item C<id>: the UUID of the server the client is connected to.
=item C<proxy>: a boolean indicating whether the server is a L<RethinkDB proxy node!http://rethinkdb.com/docs/sharding-and-replication/#running-a-proxy-node>.
=item C<name>: the server name. If proxy is C<r->true>, this field will not be
returned.
=back
=head2 db_create
r->db_create('test')->run;
Expand Down Expand Up @@ -1406,6 +1445,12 @@ or equal to the given value (the value's ceiling).
Rounds the given value down, returning the largest integer value less than or
equal to the given value (the value's floor).
=head2 grant
r->grant('username', {read => r->true, write => r->false })->run;
Grant or deny access permissions for a user account globally.
=head2 true
r->true->run;
Expand Down
52 changes: 44 additions & 8 deletions lib/Rethinkdb/IO.pm
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ sub noreply_wait {
);
}

sub server {
my $self = shift;

return $self->_send(
{
type => $self->_protocol->query->queryType->server_info,
token => Rethinkdb::Util::_token(),
}
);
}

sub _start {
my $self = shift;
my ( $query, $args, $callback ) = @_;
Expand All @@ -125,7 +136,7 @@ sub _start {
}

# add our database
if(!$args->{db}) {
if ( !$args->{db} ) {
$args->{db} = $self->default_db;
}

Expand Down Expand Up @@ -159,10 +170,12 @@ sub _simple_encode_hash {
}

if ( $json->{db} ) {
$json->{db} = Rethinkdb::IO->_encode_recurse(Rethinkdb::Query::Database->new(
name => $json->{db},
args => $json->{db},
)->_build);
$json->{db} = Rethinkdb::IO->_encode_recurse(
Rethinkdb::Query::Database->new(
name => $json->{db},
args => $json->{db},
)->_build
);
}

return $json;
Expand Down Expand Up @@ -346,6 +359,9 @@ sub _send {
$self->_handle->recv( $length, 4 );
$length = unpack 'L<', $length;

# if we couldn't unpack a length, say it is zero
$length ||= 0;

my $_data;
do {
$self->_handle->recv( $_data, 4096 );
Expand All @@ -356,8 +372,8 @@ sub _send {
my $res_data = $self->_decode($data);
$res_data->{token} = $token;

# handle partial and feed responses
if ( $res_data->{t} == 3 or $res_data->{t} == 5 ) {
# handle partial response
if ( $res_data->{t} == 3 ) {
if ( $self->_callbacks->{$token} ) {
my $res = Rethinkdb::Response->_init( $res_data, $args );

Expand All @@ -383,7 +399,7 @@ sub _send {
say {*STDERR} Dumper $res_data;
}

# fetch the rest of the data if stream/partial/feed
# fetch the rest of the data if partial
my $more = $self->_send(
{
type => $self->_protocol->query->queryType->continue,
Expand Down Expand Up @@ -544,6 +560,26 @@ use this connection.
The C<noreply_wait> method will tell the database to wait until all "no reply"
have executed before responding.
=head2 server
my $conn = r->connect;
$conn->server;
Return information about the server being used by this connection.
The server command returns either two or three fields:
=over
=item C<id>: the UUID of the server the client is connected to.
=item C<proxy>: a boolean indicating whether the server is a L<RethinkDB proxy node!http://rethinkdb.com/docs/sharding-and-replication/#running-a-proxy-node>.
=item C<name>: the server name. If proxy is C<r->true>, this field will not be
returned.
=back
=head1 SEE ALSO
L<Rethinkdb>, L<http://rethinkdb.com>
Expand Down
7 changes: 7 additions & 0 deletions lib/Rethinkdb/Protocol.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ has 'v0_1' => 0x3f61ba36;
has 'v0_2' => 0x723081e1;
has 'v0_3' => 0x5f75e83e;
has 'v0_4' => 0x400c2d20;
has 'v1_0' => 0x34c2bdc3;

package Rethinkdb::Protocol::Protocol;
use Rethinkdb::Base -base;
Expand All @@ -39,6 +40,7 @@ has 'start' => 1;
has 'continue' => 2;
has 'stop' => 3;
has 'noreply_wait' => 4;
has 'server_info' => 5;

package Rethinkdb::Protocol::Frame;
use Rethinkdb::Base -base;
Expand All @@ -64,6 +66,7 @@ has 'success_atom' => 1;
has 'success_sequence' => 2;
has 'success_partial' => 3;
has 'wait_complete' => 4;
has 'server_info' => 5;
has 'client_error' => 16;
has 'compile_error' => 17;
has 'runtime_error' => 18;
Expand All @@ -77,6 +80,7 @@ has 'non_existence' => 3100000;
has 'op_failed' => 4100000;
has 'op_indeterminate' => 4200000;
has 'user' => 5000000;
has 'permission_error' => 6000000;

package Rethinkdb::Protocol::ResponseNote;
use Rethinkdb::Base -base;
Expand Down Expand Up @@ -148,6 +152,7 @@ has 'offsets_of' => 87;
has 'contains' => 93;
has 'get_field' => 31;
has 'keys' => 94;
has 'values' => 186;
has 'object' => 143;
has 'has_fields' => 32;
has 'with_fields' => 96;
Expand All @@ -158,6 +163,7 @@ has 'between_deprecated' => 36;
has 'between' => 182;
has 'reduce' => 37;
has 'map' => 38;
has 'fold' => 187;
has 'filter' => 39;
has 'concat_map' => 40;
has 'order_by' => 41;
Expand Down Expand Up @@ -194,6 +200,7 @@ has 'wait' => 177;
has 'reconfigure' => 176;
has 'rebalance' => 179;
has 'sync' => 138;
has 'grant' => 188;
has 'index_create' => 75;
has 'index_drop' => 76;
has 'index_list' => 77;
Expand Down
Loading

0 comments on commit 90b28c8

Please sign in to comment.