Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rdb multiple args #140

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
{
"name": "danielmewes/php-rql",
"name": "geekimo/php-rql",
"type": "library",
"description": "A PHP client driver for the RethinkDB query language (ReQL)",
"keywords": ["rethinkdb","driver","database","reql"],
"homepage": "http://danielmewes.github.io/php-rql/",
"homepage": "https://github.com/Geekimo/php-rql/",
"license": "Apache-2.0",
"authors": [
{
"name": "Daniel Mewes",
"email": "[email protected]",
"homepage": "http://dmewes.com",
"role": "Developer"
},
{
"name": "Morgan Abraham",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
Expand Down
1 change: 0 additions & 1 deletion rdb/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ public function run(Query $query, $options = array(), &$profile = '')
} else {
return $this->createCursorFromResponse($response, $token, $response['n'], $toNativeOptions);
}

}

public function continueQuery($token)
Expand Down
1 change: 0 additions & 1 deletion rdb/DatumConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ public function canEncodeAsJson($v)
}

return false;

}

public function wrapImplicitVar(Query $q)
Expand Down
9 changes: 5 additions & 4 deletions rdb/Queries/Aggregations/Contains.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

class Contains extends ValuedQuery
{
public function __construct(ValuedQuery $sequence, $value)
public function __construct(ValuedQuery $sequence, array $values)
{
$value = $this->nativeToDatumOrFunction($value);

$this->setPositionalArg(0, $sequence);
$this->setPositionalArg(1, $value);

foreach ($values as $k => $value) {
$this->setPositionalArg($k+1, $this->nativeToDatumOrFunction($value));
}
}

protected function getTermType()
Expand Down
26 changes: 20 additions & 6 deletions rdb/Queries/Control/Branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,34 @@

namespace r\Queries\Control;

use r\Exceptions\RqlException;
use r\Query;
use r\ValuedQuery\ValuedQuery;
use r\ProtocolBuffer\TermTermType;

class Branch extends ValuedQuery
{
public function __construct(Query $test, $trueBranch, $falseBranch)
public function __construct(array $branches)
{
$trueBranch = $this->nativeToDatumOrFunction($trueBranch, false);
$falseBranch = $this->nativeToDatumOrFunction($falseBranch, false);
if (count($branches) % 2 == 1) {
// poping 'false' branch from other branches
$falseBranch = $this->nativeToDatumOrFunction(array_pop($branches), false);

$this->setPositionalArg(0, $test);
$this->setPositionalArg(1, $trueBranch);
$this->setPositionalArg(2, $falseBranch);
// for each remaning branch, if the index is odd, this is a branch, so we convert, otherwise, we directly position the argument
foreach ($branches as $i => $branch) {
if($i % 2 == 1) {
// branch, so we convert
$branch = $this->nativeToDatumOrFunction($branch, false);
}

$this->setPositionalArg($i, $branch);
}

// pushing the 'false' branch at the end of positional args
$this->setPositionalArg(count($branches), $falseBranch);
} else {
throw new RqlException(__METHOD__ . ' must have at least 3 parameters, or an odd parameter count.');
}
}

protected function getTermType()
Expand Down
2 changes: 1 addition & 1 deletion rdb/Queries/Math/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class Add extends BinaryOp
{
public function __construct($value, $other)
{
parent::__construct(TermTermType::PB_ADD, $value, $other);
parent::__construct(TermTermType::PB_ADD, array($value, $other));
}
}
7 changes: 4 additions & 3 deletions rdb/Queries/Math/BinaryOp.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

class BinaryOp extends ValuedQuery
{
public function __construct($termType, $value, $other)
public function __construct($termType, array $exprs)
{
$this->termType = $termType;

$this->setPositionalArg(0, $this->nativeToDatum($value));
$this->setPositionalArg(1, $this->nativeToDatum($other));
foreach ($exprs as $k => $expr) {
$this->setPositionalArg($k, $this->nativeToDatum($expr));
}
}

protected function getTermType()
Expand Down
2 changes: 1 addition & 1 deletion rdb/Queries/Math/Div.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class Div extends BinaryOp
{
public function __construct($value, $other)
{
parent::__construct(TermTermType::PB_DIV, $value, $other);
parent::__construct(TermTermType::PB_DIV, array($value, $other));
}
}
2 changes: 1 addition & 1 deletion rdb/Queries/Math/Eq.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class Eq extends BinaryOp
{
public function __construct($value, $other)
{
parent::__construct(TermTermType::PB_EQ, $value, $other);
parent::__construct(TermTermType::PB_EQ, array($value, $other));
}
}
2 changes: 1 addition & 1 deletion rdb/Queries/Math/Ge.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class Ge extends BinaryOp
{
public function __construct($value, $other)
{
parent::__construct(TermTermType::PB_GE, $value, $other);
parent::__construct(TermTermType::PB_GE, array($value, $other));
}
}
2 changes: 1 addition & 1 deletion rdb/Queries/Math/Gt.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class Gt extends BinaryOp
{
public function __construct($value, $other)
{
parent::__construct(TermTermType::PB_GT, $value, $other);
parent::__construct(TermTermType::PB_GT, array($value, $other));
}
}
2 changes: 1 addition & 1 deletion rdb/Queries/Math/Le.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class Le extends BinaryOp
{
public function __construct($value, $other)
{
parent::__construct(TermTermType::PB_LE, $value, $other);
parent::__construct(TermTermType::PB_LE, array($value, $other));
}
}
2 changes: 1 addition & 1 deletion rdb/Queries/Math/Lt.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class Lt extends BinaryOp
{
public function __construct($value, $other)
{
parent::__construct(TermTermType::PB_LT, $value, $other);
parent::__construct(TermTermType::PB_LT, array($value, $other));
}
}
2 changes: 1 addition & 1 deletion rdb/Queries/Math/Mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class Mod extends BinaryOp
{
public function __construct($value, $other)
{
parent::__construct(TermTermType::PB_MOD, $value, $other);
parent::__construct(TermTermType::PB_MOD, array($value, $other));
}
}
2 changes: 1 addition & 1 deletion rdb/Queries/Math/Mul.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class Mul extends BinaryOp
{
public function __construct($value, $other)
{
parent::__construct(TermTermType::PB_MUL, $value, $other);
parent::__construct(TermTermType::PB_MUL, array($value, $other));
}
}
2 changes: 1 addition & 1 deletion rdb/Queries/Math/Ne.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class Ne extends BinaryOp
{
public function __construct($value, $other)
{
parent::__construct(TermTermType::PB_NE, $value, $other);
parent::__construct(TermTermType::PB_NE, array($value, $other));
}
}
4 changes: 2 additions & 2 deletions rdb/Queries/Math/RAnd.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class RAnd extends BinaryOp
{
public function __construct($value, $other)
public function __construct(array $exprs)
{
parent::__construct(TermTermType::PB_AND, $value, $other);
parent::__construct(TermTermType::PB_AND, $exprs);
}
}
4 changes: 2 additions & 2 deletions rdb/Queries/Math/ROr.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class ROr extends BinaryOp
{
public function __construct($value, $other)
public function __construct(array $exprs)
{
parent::__construct(TermTermType::PB_OR, $value, $other);
parent::__construct(TermTermType::PB_OR, $exprs);
}
}
2 changes: 1 addition & 1 deletion rdb/Queries/Math/Sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class Sub extends BinaryOp
{
public function __construct($value, $other)
{
parent::__construct(TermTermType::PB_SUB, $value, $other);
parent::__construct(TermTermType::PB_SUB, array($value, $other));
}
}
20 changes: 14 additions & 6 deletions rdb/ValuedQuery/ValuedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ public function max($attributeOrOpts = null)
}
// Note: The API docs suggest that as of 1.6, contains can accept multiple values.
// We do not support that for the time being.
public function contains($value)
public function contains()
{
return new Contains($this, $value);
return new Contains($this, func_get_args());
}
public function pluck($attributes)
{
Expand Down Expand Up @@ -337,13 +337,21 @@ public function mod($other)
{
return new Mod($this, $other);
}
public function rAnd($other)
public function rAnd()
{
return new RAnd($this, $other);
$exprs = func_get_args();

array_unshift($exprs, $this);

return new RAnd($exprs);
}
public function rOr($other)
public function rOr()
{
return new ROr($this, $other);
$exprs = func_get_args();

array_unshift($exprs, $this);

return new ROr($exprs);
}
public function eq($other)
{
Expand Down
12 changes: 6 additions & 6 deletions rdb/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ function args($args)
return new Args($args);
}

function branch(Query $test, $trueBranch, $falseBranch)
function branch()
{
return new Branch($test, $trueBranch, $falseBranch);
return new Branch(func_get_args());
}

function row($attribute = null)
Expand Down Expand Up @@ -238,13 +238,13 @@ function mod($expr1, $expr2)
return new Mod($expr1, $expr2);
}

function rAnd($expr1, $expr2)
function rAnd()
{
return new RAnd($expr1, $expr2);
return new RAnd(func_get_args());
}
function rOr($expr1, $expr2)
function rOr()
{
return new ROr($expr1, $expr2);
return new ROr(func_get_args());
}

function eq($expr1, $expr2)
Expand Down