Skip to content

Commit 16ac6f4

Browse files
author
Daniel Mewes
committed
Added conn->server, values(), r.uuid(str)
1 parent 3b2cdbd commit 16ac6f4

File tree

13 files changed

+113
-3
lines changed

13 files changed

+113
-3
lines changed

pb4php/compile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
$rdbProtocolParser->parse(
77
__DIR__ . '/ql2.proto',
88
'r\ProtocolBuffer', // namespace
9-
__DIR__ . '/../src/ProtocolBuffer' //destination dir
9+
__DIR__ . '/../rdb/ProtocolBuffer' //destination dir
1010
);

pb4php/ql2.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ message Response {
112112
// more of the sequence. Keep sending [CONTINUE]
113113
// queries until you get back [SUCCESS_SEQUENCE].
114114
WAIT_COMPLETE = 4; // A [NOREPLY_WAIT] query completed.
115+
SERVER_INFO = 5; // The data for a [SERVER_INFO] request. This is
116+
// the same as `SUCCESS_ATOM` except that there will
117+
// never be profiling data.
115118

116119
// These response types indicate failure.
117120
CLIENT_ERROR = 16; // Means the client is buggy. An example is if the
@@ -331,6 +334,8 @@ message Term {
331334
// | Sequence, STRING -> Sequence
332335
// Return an array containing the keys of the object.
333336
KEYS = 94; // OBJECT -> ARRAY
337+
// Return an array containing the values of the object.
338+
VALUES = 186; // OBJECT -> ARRAY
334339
// Creates an object
335340
OBJECT = 143; // STRING, DATUM, ... -> OBJECT
336341
// Check whether an object contains all the specified fields,
@@ -730,6 +735,7 @@ message Term {
730735
// * A [STOP] query with the same token as a [START] query that you want to stop.
731736
// * A [NOREPLY_WAIT] query with a unique per-connection token. The server answers
732737
// with a [WAIT_COMPLETE] [Response].
738+
// * A [SERVER_INFO] query. The server answers with a [SERVER_INFO] [Response].
733739
message Query {
734740
enum QueryType {
735741
START = 1; // Start a new query.
@@ -738,6 +744,7 @@ message Query {
738744
STOP = 3; // Stop a query partway through executing.
739745
NOREPLY_WAIT = 4;
740746
// Wait for noreply operations to finish.
747+
SERVER_INFO = 5; // Get server information.
741748
}
742749
optional QueryType type = 1;
743750
// A [Term] is how we represent the operations we want a query to perform.

rdb/Connection.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,30 @@ public function noreplyWait()
166166
}
167167
}
168168

169+
public function server()
170+
{
171+
if (!$this->isOpen()) {
172+
throw new RqlDriverError("Not connected.");
173+
}
174+
175+
// Generate a token for the request
176+
$token = $this->generateToken();
177+
178+
// Send the request
179+
$jsonQuery = array(QueryQueryType::PB_SERVER_INFO);
180+
$this->sendQuery($token, $jsonQuery);
181+
182+
// Await the response
183+
$response = $this->receiveResponse($token);
184+
185+
if ($response['t'] != ResponseResponseType::PB_SERVER_INFO) {
186+
throw new RqlDriverError("Unexpected response type to server info query.");
187+
}
188+
189+
$toNativeOptions = array();
190+
return $this->createDatumFromResponse($response)->toNative($toNativeOptions);
191+
}
192+
169193
public function run(Query $query, $options = array(), &$profile = '')
170194
{
171195
if (isset($options) && !is_array($options)) {

rdb/ProtocolBuffer/QueryQueryType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class QueryQueryType
66
{
77
const PB_CONTINUE = 2;
88
const PB_NOREPLY_WAIT = 4;
9+
const PB_SERVER_INFO = 5;
910
const PB_START = 1;
1011
const PB_STOP = 3;
1112
}

rdb/ProtocolBuffer/ResponseResponseType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class ResponseResponseType
77
const PB_CLIENT_ERROR = 16;
88
const PB_COMPILE_ERROR = 17;
99
const PB_RUNTIME_ERROR = 18;
10+
const PB_SERVER_INFO = 5;
1011
const PB_SUCCESS_ATOM = 1;
1112
const PB_SUCCESS_PARTIAL = 3;
1213
const PB_SUCCESS_SEQUENCE = 2;

rdb/ProtocolBuffer/TermTermType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class TermTermType
172172
const PB_UPCASE = 141;
173173
const PB_UPDATE = 53;
174174
const PB_UUID = 169;
175+
const PB_VALUES = 186;
175176
const PB_VAR = 10;
176177
const PB_WAIT = 177;
177178
const PB_WEDNESDAY = 109;

rdb/Queries/Manipulation/Values.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace r\Queries\Manipulation;
4+
5+
use r\ValuedQuery\ValuedQuery;
6+
use r\ProtocolBuffer\TermTermType;
7+
8+
class Values extends ValuedQuery
9+
{
10+
public function __construct(ValuedQuery $sequence)
11+
{
12+
$this->setPositionalArg(0, $sequence);
13+
}
14+
15+
protected function getTermType()
16+
{
17+
return TermTermType::PB_VALUES;
18+
}
19+
}

rdb/Queries/Misc/Uuid.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77

88
class Uuid extends ValuedQuery
99
{
10+
public function __construct($str = null)
11+
{
12+
if (isset($str))
13+
{
14+
$this->setPositionalArg(0, $this->nativeToDatum($str));
15+
}
16+
}
17+
1018
protected function getTermType()
1119
{
1220
return TermTermType::PB_UUID;

rdb/ValuedQuery/ValuedQuery.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
use r\Queries\Manipulation\HasFields;
5454
use r\Queries\Manipulation\InsertAt;
5555
use r\Queries\Manipulation\Keys;
56+
use r\Queries\Manipulation\Values;
5657
use r\Queries\Manipulation\Merge;
5758
use r\Queries\Manipulation\Pluck;
5859
use r\Queries\Manipulation\Prepend;
@@ -307,6 +308,10 @@ public function keys()
307308
{
308309
return new Keys($this);
309310
}
311+
public function values()
312+
{
313+
return new Values($this);
314+
}
310315
public function add($other)
311316
{
312317
return new Add($this, $other);

rdb/global.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,9 @@ function distance($g1, $g2, $opts = null)
408408
return new Distance($g1, $g2, $opts);
409409
}
410410

411-
function uuid()
411+
function uuid($str = null)
412412
{
413-
return new Uuid();
413+
return new Uuid($str);
414414
}
415415

416416
function minval()

0 commit comments

Comments
 (0)