Skip to content

Commit 7c1f118

Browse files
committed
Add getAll operation
1 parent cb2fe48 commit 7c1f118

File tree

13 files changed

+143
-16
lines changed

13 files changed

+143
-16
lines changed

docs/roadmap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
| db ||| |
5353
| table ||| |
5454
| get ||| |
55-
| getAll | || |
55+
| getAll | || |
5656
| between ||| |
5757
| filter ||| |
5858
| Joins ||| |

src/Query/Operation/AbstractOperation.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ public function filter(array $predicate): OperationInterface
3232
return new Filter($this->rethink, $this->message, $this, $predicate);
3333
}
3434

35+
/**
36+
* @inheritdoc
37+
*/
38+
public function getAll(...$keys): OperationInterface
39+
{
40+
return new GetAll($this->rethink, $this->message, $this, $keys);
41+
}
42+
3543
/**
3644
* @inheritdoc
3745
*/

src/Query/Operation/Filter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Filter extends AbstractOperation
1414
* @var array
1515
*/
1616
private $predicate;
17+
1718
/**
1819
* @var QueryInterface
1920
*/

src/Query/Operation/Get.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class Get extends AbstractQuery
1313
{
1414
/**
15-
* @var string
15+
* @var string|int
1616
*/
1717
private $key;
1818

src/Query/Operation/GetAll.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace TBolier\RethinkQL\Query\Operation;
5+
6+
use TBolier\RethinkQL\Message\MessageInterface;
7+
use TBolier\RethinkQL\Query\QueryInterface;
8+
use TBolier\RethinkQL\RethinkInterface;
9+
use TBolier\RethinkQL\Types\Term\TermType;
10+
11+
class GetAll extends AbstractOperation
12+
{
13+
/**
14+
* @var array
15+
*/
16+
private $keys;
17+
18+
/**
19+
* @var QueryInterface
20+
*/
21+
private $query;
22+
23+
/**
24+
* @param RethinkInterface $rethink
25+
* @param MessageInterface $message
26+
* @param QueryInterface $query
27+
* @param array $keys
28+
*/
29+
public function __construct(
30+
RethinkInterface $rethink,
31+
MessageInterface $message,
32+
QueryInterface $query,
33+
array $keys
34+
) {
35+
parent::__construct($rethink, $message);
36+
37+
$this->query = $query;
38+
$this->keys = $keys;
39+
$this->rethink = $rethink;
40+
$this->message = $message;
41+
}
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
public function toArray(): array
47+
{
48+
return [
49+
TermType::GET_ALL,
50+
[
51+
$this->query->toArray(),
52+
[
53+
TermType::MAKE_ARRAY,
54+
$this->keys,
55+
],
56+
],
57+
];
58+
}
59+
}

src/Query/Operation/OperationInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public function delete(): QueryInterface;
2525
*/
2626
public function filter(array $predicate): OperationInterface;
2727

28+
/**
29+
* @param array $keys
30+
* @return OperationInterface
31+
*/
32+
public function getAll(...$keys): OperationInterface;
33+
2834
/**
2935
* @param array $elements
3036
* @return QueryInterface

src/Query/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function __construct(string $name, RethinkInterface $rethink, MessageInte
3939
/**
4040
* @inheritdoc
4141
*/
42-
public function get($value): AbstractQuery
42+
public function get($key): AbstractQuery
4343
{
44-
return new Get($this->rethink, $this->message, $this, $value);
44+
return new Get($this->rethink, $this->message, $this, $key);
4545
}
4646

4747
/**

src/Query/TableInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
interface TableInterface extends OperationInterface
99
{
1010
/**
11-
* @param string|int $value
11+
* @param string|int $key
1212
* @return AbstractQuery
1313
*/
14-
public function get($value): AbstractQuery;
14+
public function get($key): AbstractQuery;
1515
}

src/Types/Term/TermType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ class TermType
104104
public const INDEX_RENAME = 156;
105105
public const FUNCALL = 64;
106106
public const BRANCH = 65;
107-
public const OR = 66;
108-
public const AND = 67;
107+
public const OR = 66;
108+
public const AND = 67;
109109
public const FOR_EACH = 68;
110110
public const FUNC = 69;
111111
public const ASC = 73;

test/integration/Query/AbstractTableTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ public function tearDown()
3030

3131

3232
/**
33-
* @param int $documentId
33+
* @param int|string $id
3434
* @return ResponseInterface
3535
*/
36-
protected function insertDocument(int $documentId): ResponseInterface
36+
protected function insertDocument($id): ResponseInterface
3737
{
3838
$res = $this->r()
3939
->table('tabletest')
4040
->insert([
41-
'id' => $documentId,
42-
'title' => 'Test document '.$documentId,
41+
'id' => $id,
42+
'title' => 'Test document '.$id,
4343
'description' => 'A document description.',
4444
])
4545
->run();

0 commit comments

Comments
 (0)