Add offset to limit() function

Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
davidarendsen 2022-12-16 12:36:01 +00:00
commit dbc83d596c
2 changed files with 13 additions and 3 deletions

View file

@ -9,13 +9,14 @@ class Limit extends Base
*/
private $limit;
public function __construct(int $limit)
public function __construct(int $limit, int $offset = 0)
{
$this->limit = $limit;
$this->offset = $offset;
}
public function __toString()
{
return '|> limit(n:' . (string)$this->limit . ') ';
return '|> limit(n: ' . (string)$this->limit . ', offset: ' . (string)$this->offset . ') ';
}
}

View file

@ -13,7 +13,16 @@ final class LimitFunctionTest extends TestCase
{
$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());
}