Add offset to limit() function
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
681d41a496
commit
dbc83d596c
2 changed files with 13 additions and 3 deletions
|
|
@ -9,13 +9,14 @@ class Limit extends Base
|
||||||
*/
|
*/
|
||||||
private $limit;
|
private $limit;
|
||||||
|
|
||||||
public function __construct(int $limit)
|
public function __construct(int $limit, int $offset = 0)
|
||||||
{
|
{
|
||||||
$this->limit = $limit;
|
$this->limit = $limit;
|
||||||
|
$this->offset = $offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return '|> limit(n:' . (string)$this->limit . ') ';
|
return '|> limit(n: ' . (string)$this->limit . ', offset: ' . (string)$this->offset . ') ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,16 @@ final class LimitFunctionTest extends TestCase
|
||||||
{
|
{
|
||||||
$expression = new Limit(1);
|
$expression = new Limit(1);
|
||||||
|
|
||||||
$query = '|> limit(n:1) ';
|
$query = '|> limit(n: 1, offset: 0) ';
|
||||||
|
|
||||||
|
$this->assertEquals($query, $expression->__toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLimitWithOffset()
|
||||||
|
{
|
||||||
|
$expression = new Limit(10, 2);
|
||||||
|
|
||||||
|
$query = '|> limit(n: 10, offset: 2) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals($query, $expression->__toString());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue