Skip to content

Commit e3f166d

Browse files
committed
Add index operations
1 parent ae141fd commit e3f166d

File tree

12 files changed

+427
-39
lines changed

12 files changed

+427
-39
lines changed

docs/roadmap.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
| tableCreate ||| |
3535
| tableDrop ||| |
3636
| tableList ||| |
37-
| indexCreate || | |
38-
| indexDrop || | |
39-
| indexList || | |
40-
| indexRename || | |
37+
| indexCreate || | |
38+
| indexDrop || | |
39+
| indexList || | |
40+
| indexRename || | |
4141
| indexStatus ||| |
4242
| indexWait ||| |
4343
| | | | |

src/Query/Operation/GetAll.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class GetAll extends AbstractOperation
2323
/**
2424
* @param RethinkInterface $rethink
2525
* @param MessageInterface $message
26-
* @param QueryInterface $query
27-
* @param array $keys
26+
* @param QueryInterface $query
27+
* @param array $keys
2828
*/
2929
public function __construct(
3030
RethinkInterface $rethink,
@@ -34,8 +34,8 @@ public function __construct(
3434
) {
3535
parent::__construct($rethink, $message);
3636

37-
$this->query = $query;
38-
$this->keys = $keys;
37+
$this->query = $query;
38+
$this->keys = $keys;
3939
$this->rethink = $rethink;
4040
$this->message = $message;
4141
}
@@ -47,13 +47,9 @@ public function toArray(): array
4747
{
4848
return [
4949
TermType::GET_ALL,
50-
[
51-
$this->query->toArray(),
52-
[
53-
TermType::MAKE_ARRAY,
54-
$this->keys,
55-
],
56-
],
50+
array_merge([$this->query->toArray()],
51+
array_values($this->keys)
52+
),
5753
];
5854
}
5955
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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\AbstractQuery;
8+
use TBolier\RethinkQL\Query\QueryInterface;
9+
use TBolier\RethinkQL\RethinkInterface;
10+
use TBolier\RethinkQL\Types\Term\TermType;
11+
12+
class IndexCreate extends AbstractQuery
13+
{
14+
/**
15+
* @var string
16+
*/
17+
private $name;
18+
19+
/**
20+
* @var QueryInterface
21+
*/
22+
private $query;
23+
24+
/**
25+
* @param RethinkInterface $rethink
26+
* @param MessageInterface $message
27+
* @param QueryInterface $query
28+
* @param string $name
29+
*/
30+
public function __construct(
31+
RethinkInterface $rethink,
32+
MessageInterface $message,
33+
QueryInterface $query,
34+
string $name
35+
) {
36+
parent::__construct($rethink, $message);
37+
38+
$this->query = $query;
39+
$this->rethink = $rethink;
40+
$this->message = $message;
41+
$this->name = $name;
42+
}
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
public function toArray(): array
48+
{
49+
return [
50+
TermType::INDEX_CREATE,
51+
[
52+
$this->query->toArray(),
53+
[
54+
TermType::DATUM,
55+
$this->name,
56+
],
57+
],
58+
];
59+
}
60+
}

src/Query/Operation/IndexDrop.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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\AbstractQuery;
8+
use TBolier\RethinkQL\Query\QueryInterface;
9+
use TBolier\RethinkQL\RethinkInterface;
10+
use TBolier\RethinkQL\Types\Term\TermType;
11+
12+
class IndexDrop extends AbstractQuery
13+
{
14+
/**
15+
* @var string
16+
*/
17+
private $name;
18+
19+
/**
20+
* @var QueryInterface
21+
*/
22+
private $query;
23+
24+
/**
25+
* @param RethinkInterface $rethink
26+
* @param MessageInterface $message
27+
* @param QueryInterface $query
28+
* @param string $name
29+
*/
30+
public function __construct(
31+
RethinkInterface $rethink,
32+
MessageInterface $message,
33+
QueryInterface $query,
34+
string $name
35+
) {
36+
parent::__construct($rethink, $message);
37+
38+
$this->query = $query;
39+
$this->rethink = $rethink;
40+
$this->message = $message;
41+
$this->name = $name;
42+
}
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
public function toArray(): array
48+
{
49+
return [
50+
TermType::INDEX_DROP,
51+
[
52+
$this->query->toArray(),
53+
[
54+
TermType::DATUM,
55+
$this->name,
56+
],
57+
],
58+
];
59+
}
60+
}

src/Query/Operation/IndexList.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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\AbstractQuery;
8+
use TBolier\RethinkQL\Query\QueryInterface;
9+
use TBolier\RethinkQL\RethinkInterface;
10+
use TBolier\RethinkQL\Types\Term\TermType;
11+
12+
class IndexList extends AbstractQuery
13+
{
14+
/**
15+
* @var QueryInterface
16+
*/
17+
private $query;
18+
19+
/**
20+
* @param RethinkInterface $rethink
21+
* @param MessageInterface $message
22+
* @param QueryInterface $query
23+
*/
24+
public function __construct(RethinkInterface $rethink, MessageInterface $message, QueryInterface $query)
25+
{
26+
parent::__construct($rethink, $message);
27+
28+
$this->query = $query;
29+
$this->rethink = $rethink;
30+
$this->message = $message;
31+
}
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
public function toArray(): array
37+
{
38+
return [
39+
TermType::INDEX_LIST,
40+
[
41+
$this->query->toArray(),
42+
],
43+
];
44+
}
45+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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\AbstractQuery;
8+
use TBolier\RethinkQL\Query\QueryInterface;
9+
use TBolier\RethinkQL\RethinkInterface;
10+
use TBolier\RethinkQL\Types\Term\TermType;
11+
12+
class IndexRename extends AbstractQuery
13+
{
14+
/**
15+
* @var string
16+
*/
17+
private $oldValue;
18+
19+
/**
20+
* @var string
21+
*/
22+
private $newValue;
23+
24+
/**
25+
* @var QueryInterface
26+
*/
27+
private $query;
28+
29+
/**
30+
* @param RethinkInterface $rethink
31+
* @param MessageInterface $message
32+
* @param QueryInterface $query
33+
* @param string $oldValue
34+
* @param string $newValue
35+
*/
36+
public function __construct(
37+
RethinkInterface $rethink,
38+
MessageInterface $message,
39+
QueryInterface $query,
40+
string $oldValue,
41+
string $newValue
42+
) {
43+
parent::__construct($rethink, $message);
44+
45+
$this->query = $query;
46+
$this->rethink = $rethink;
47+
$this->message = $message;
48+
$this->oldValue = $oldValue;
49+
$this->newValue = $newValue;
50+
}
51+
52+
/**
53+
* @inheritdoc
54+
*/
55+
public function toArray(): array
56+
{
57+
return [
58+
TermType::INDEX_RENAME,
59+
[
60+
$this->query->toArray(),
61+
[
62+
TermType::DATUM,
63+
$this->oldValue,
64+
],
65+
[
66+
TermType::DATUM,
67+
$this->newValue,
68+
],
69+
],
70+
];
71+
}
72+
}

src/Query/Table.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
use TBolier\RethinkQL\Message\MessageInterface;
77
use TBolier\RethinkQL\Query\Operation\AbstractOperation;
88
use TBolier\RethinkQL\Query\Operation\Get;
9+
use TBolier\RethinkQL\Query\Operation\IndexCreate;
10+
use TBolier\RethinkQL\Query\Operation\IndexDrop;
11+
use TBolier\RethinkQL\Query\Operation\IndexList;
12+
use TBolier\RethinkQL\Query\Operation\IndexRename;
913
use TBolier\RethinkQL\RethinkInterface;
1014
use TBolier\RethinkQL\Types\Term\TermType;
1115

@@ -44,6 +48,41 @@ public function get($key): AbstractQuery
4448
return new Get($this->rethink, $this->message, $this, $key);
4549
}
4650

51+
/**
52+
* @inheritdoc
53+
*/
54+
public function indexCreate(string $name): AbstractQuery
55+
{
56+
return new IndexCreate($this->rethink, $this->message, $this, $name);
57+
58+
}
59+
60+
/**
61+
* @inheritdoc
62+
*/
63+
public function indexDrop(string $name): AbstractQuery
64+
{
65+
return new IndexDrop($this->rethink, $this->message, $this, $name);
66+
67+
}
68+
69+
/**
70+
* @inheritdoc
71+
*/
72+
public function indexList(): AbstractQuery
73+
{
74+
return new IndexList($this->rethink, $this->message, $this);
75+
}
76+
77+
/**
78+
* @inheritdoc
79+
*/
80+
public function indexRename(string $oldValue, string $newValue): AbstractQuery
81+
{
82+
return new IndexRename($this->rethink, $this->message, $this, $oldValue, $newValue);
83+
84+
}
85+
4786
/**
4887
* @inheritdoc
4988
*/

src/Query/TableInterface.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,28 @@ interface TableInterface extends OperationInterface
1212
* @return AbstractQuery
1313
*/
1414
public function get($key): AbstractQuery;
15+
16+
/**
17+
* @param string $name
18+
* @return AbstractQuery
19+
*/
20+
public function indexCreate(string $name): AbstractQuery;
21+
22+
/**
23+
* @param string $name
24+
* @return AbstractQuery
25+
*/
26+
public function indexDrop(string $name): AbstractQuery;
27+
28+
/**
29+
* @return AbstractQuery
30+
*/
31+
public function indexList(): AbstractQuery;
32+
33+
/**
34+
* @param string $oldValue
35+
* @param string $newValue
36+
* @return AbstractQuery
37+
*/
38+
public function indexRename(string $oldValue, string $newValue): AbstractQuery;
1539
}

test/integration/AbstractTestCase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ protected function assertObStatus($status, $data)
126126
$statuses = [
127127
'tables_created',
128128
'tables_dropped',
129+
'created',
130+
'dropped',
131+
'renamed',
129132
'unchanged',
130133
'skipped',
131134
'replaced',

0 commit comments

Comments
 (0)