Skip to content

Commit c7578ca

Browse files
committed
Move Aggregations into AggregationInterface
1 parent ff1129b commit c7578ca

File tree

6 files changed

+59
-34
lines changed

6 files changed

+59
-34
lines changed

src/Query/Aggregation/AggregationInterface.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@
33

44
namespace TBolier\RethinkQL\Query\Aggregation;
55

6+
use TBolier\RethinkQL\Query\QueryInterface;
67
use TBolier\RethinkQL\Response\ResponseInterface;
78

89
interface AggregationInterface
910
{
11+
/**
12+
* @param int $n
13+
* @return AggregationInterface
14+
*/
15+
public function limit($n): AggregationInterface;
16+
17+
/**
18+
* @param mixed|QueryInterface $key
19+
* @return AggregationInterface
20+
*/
21+
public function orderBy($key): AggregationInterface;
22+
1023
/**
1124
* @return Iterable|ResponseInterface
1225
*/

src/Query/Operation/AbstractOperation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
namespace TBolier\RethinkQL\Query\Operation;
55

6-
use TBolier\RethinkQL\Query\AbstractQuery;
6+
use TBolier\RethinkQL\Query\Aggregation\AbstractAggregation;
77
use TBolier\RethinkQL\Query\QueryInterface;
88

9-
abstract class AbstractOperation extends AbstractQuery implements OperationInterface
9+
abstract class AbstractOperation extends AbstractAggregation implements OperationInterface
1010
{
1111
/**
1212
* @inheritdoc

src/Query/Table.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
namespace TBolier\RethinkQL\Query;
55

66
use TBolier\RethinkQL\Message\MessageInterface;
7-
use TBolier\RethinkQL\Query\Aggregation\Limit;
8-
use TBolier\RethinkQL\Query\Aggregation\OrderBy;
9-
use TBolier\RethinkQL\Query\Aggregation\AggregationInterface;
107
use TBolier\RethinkQL\Query\Operation\AbstractOperation;
118
use TBolier\RethinkQL\Query\Operation\Get;
129
use TBolier\RethinkQL\RethinkInterface;
@@ -47,22 +44,6 @@ public function get($value): AbstractQuery
4744
return new Get($this->rethink, $this->message, $this, $value);
4845
}
4946

50-
/**
51-
* @inheritdoc
52-
*/
53-
public function limit($value): AggregationInterface
54-
{
55-
return new Limit($this->rethink, $this->message, $this, $value);
56-
}
57-
58-
/**
59-
* @inheritdoc
60-
*/
61-
public function orderBy($key): AggregationInterface
62-
{
63-
return new OrderBy($this->rethink, $this->message, $this, $key);
64-
}
65-
6647
/**
6748
* @inheritdoc
6849
*/

src/Query/TableInterface.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace TBolier\RethinkQL\Query;
55

6-
use TBolier\RethinkQL\Query\Aggregation\AggregationInterface;
76
use TBolier\RethinkQL\Query\Operation\OperationInterface;
87

98
interface TableInterface extends OperationInterface
@@ -13,16 +12,4 @@ interface TableInterface extends OperationInterface
1312
* @return AbstractQuery
1413
*/
1514
public function get($value): AbstractQuery;
16-
17-
/**
18-
* @param int $n
19-
* @return AggregationInterface
20-
*/
21-
public function limit($n): AggregationInterface;
22-
23-
/**
24-
* @param mixed|QueryInterface $key
25-
* @return AggregationInterface
26-
*/
27-
public function orderBy($key): AggregationInterface;
2815
}

test/integration/Aggregation/LimitTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,26 @@ public function testLimit(): void
2828

2929
$this->assertCount(2, $cursor);
3030
}
31+
32+
/**
33+
* @return void
34+
* @throws \Exception
35+
*/
36+
public function testFilterAndLimit(): void
37+
{
38+
$this->insertDocument(1);
39+
$this->insertDocument(2);
40+
$this->insertDocument(3);
41+
$this->insertDocument(4);
42+
$this->insertDocument(5);
43+
44+
/** @var Cursor $cursor */
45+
$cursor = $this->r()
46+
->table('tabletest')
47+
->filter(['description' => 'A document description.'])
48+
->limit(2)
49+
->run();
50+
51+
$this->assertCount(2, $cursor);
52+
}
3153
}

test/integration/Aggregation/OrderByTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,26 @@ public function testOrderByAsc(): void
4949

5050
$this->assertArraySubset(['id' => 1], $res->getData()[0]);
5151
}
52+
53+
/**
54+
* @return void
55+
* @throws \Exception
56+
*/
57+
public function testFilerAndOrderByAsc(): void
58+
{
59+
$this->insertDocument(5);
60+
$this->insertDocument(4);
61+
$this->insertDocument(3);
62+
$this->insertDocument(2);
63+
$this->insertDocument(1);
64+
65+
/** @var ResponseInterface $res */
66+
$res = $this->r()
67+
->table('tabletest')
68+
->filter(['description' => 'A document description.'])
69+
->orderBy($this->r()->asc('id'))
70+
->run();
71+
72+
$this->assertArraySubset(['id' => 1], $res->getData()[0]);
73+
}
5274
}

0 commit comments

Comments
 (0)