This repository has been archived by the owner on Feb 5, 2020. It is now read-only.
forked from danielmewes/php-rql
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remaining features for 2.3.0 release.
- Loading branch information
1 parent
dd2bbf4
commit 393a49a
Showing
14 changed files
with
177 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace r\Queries\Aggregations; | ||
|
||
use r\ValuedQuery\ValuedQuery; | ||
use r\ProtocolBuffer\TermTermType; | ||
|
||
class Fold extends ValuedQuery | ||
{ | ||
public function __construct(ValuedQuery $sequence, $base, $fun, $opts = null) | ||
{ | ||
$this->setPositionalArg(0, $sequence); | ||
$this->setPositionalArg(1, $this->nativeToDatum($base)); | ||
$this->setPositionalArg(2, $this->nativeToFunction($fun)); | ||
|
||
if (isset($opts)) { | ||
foreach ($opts as $opt => $val) { | ||
$this->setOptionalArg($opt, $this->nativeToDatumOrFunction($val)); | ||
} | ||
} | ||
} | ||
|
||
protected function getTermType() | ||
{ | ||
return TermTermType::PB_FOLD; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace r\Queries\Control; | ||
|
||
use r\ValuedQuery\ValuedQuery; | ||
use r\ProtocolBuffer\TermTermType; | ||
|
||
class Args extends ValuedQuery | ||
{ | ||
public function __construct($args) | ||
{ | ||
$this->setPositionalArg(0, $this->nativeToDatum($args)); | ||
} | ||
|
||
protected function getTermType() | ||
{ | ||
return TermTermType::PB_ARGS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
namespace r; | ||
|
||
define('PHP_RQL_VERSION', '2.2.0'); | ||
define('PHP_RQL_VERSION', '2.3.0'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace r\Tests\Functional; | ||
|
||
use r\Tests\TestCase; | ||
|
||
class FoldTest extends TestCase | ||
{ | ||
public function testFoldReduction() | ||
{ | ||
$this->assertEquals( | ||
15.0, | ||
\r\expr(array(1, 2, 3, 4)) | ||
->fold(5, function ($acc, $v) { | ||
return $acc->add($v); | ||
}) | ||
->run($this->conn) | ||
); | ||
} | ||
|
||
public function testFoldEmit() | ||
{ | ||
$this->assertEquals( | ||
array(5, 6, 8, 11, 15), | ||
\r\expr(array(1, 2, 3, 4)) | ||
->fold(5, function ($acc, $v) { | ||
return $acc->add($v); | ||
}, | ||
array( | ||
'emit' => function($o, $c, $n) { return array($o); }, | ||
'final_emit' => function($a) { return array($a); } | ||
)) | ||
->run($this->conn) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace r\Tests\Functional; | ||
|
||
use r\Tests\TestCase; | ||
|
||
class InsertTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
$this->conn = $this->getConnection(); | ||
$this->data = $this->useDataset('Heroes'); | ||
$this->data->populate(); | ||
$this->opts = array(); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
$this->data->truncate(); | ||
} | ||
|
||
public function testCustomConflict() | ||
{ | ||
$res = $this->db()->table('marvel')->insert( | ||
array( | ||
'superhero' => 'Iron Man', | ||
), | ||
array( | ||
'conflict' => function($x, $k, $o) { return \r\expr(null); } | ||
) | ||
)->run($this->conn, $this->opts); | ||
|
||
$this->assertObStatus(array('deleted' => 1), $res); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters