Skip to content

Commit

Permalink
Implement composite keys support (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa authored and rybakit committed Nov 30, 2016
1 parent b75643b commit 63515cc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Request/DeleteRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class DeleteRequest implements Request
private $indexId;
private $key;

public function __construct($spaceId, $indexId, array $key)
public function __construct($spaceId, $indexId, $key)
{
$this->spaceId = $spaceId;
$this->indexId = $indexId;
$this->key = $key;
$this->key = (array) $key;
}

public function getType()
Expand Down
4 changes: 2 additions & 2 deletions src/Request/SelectRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class SelectRequest implements Request
private $limit;
private $iterator;

public function __construct($spaceId, $indexId, array $key, $offset, $limit, $iterator)
public function __construct($spaceId, $indexId, $key, $offset, $limit, $iterator)
{
$this->spaceId = $spaceId;
$this->indexId = $indexId;
$this->key = $key;
$this->key = (array) $key;
$this->offset = $offset;
$this->limit = $limit;
$this->iterator = $iterator;
Expand Down
4 changes: 2 additions & 2 deletions src/Request/UpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct($spaceId, $indexId, $key, array $operations)
{
$this->spaceId = $spaceId;
$this->indexId = $indexId;
$this->key = $key;
$this->key = (array) $key;
$this->operations = $operations;
}

Expand All @@ -29,7 +29,7 @@ public function getBody()
return [
IProto::SPACE_ID => $this->spaceId,
IProto::INDEX_ID => $this->indexId,
IProto::KEY => [$this->key],
IProto::KEY => $this->key,
IProto::TUPLE => $this->operations,
];
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Integration/SpaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,18 @@ public function testFlushIndexes()

$this->assertSame(4, Utils::getTotalSelectCalls() - $total);
}

public function testCompositeKeys()
{
$space = self::$client->getSpace('space_composite');
$this->assertSame(1, $space->select([2016, 10])->getData()[0][2]);
$this->assertSame(0, $space->select([2016, 11])->getData()[0][2]);

$space->update([2016, 10], [['=', 2, 0]]);
$this->assertSame(0, $space->select([2016, 10])->getData()[0][2]);

$space->delete([2016, 11]);
$this->assertCount(0, $space->select([2016, 11])->getData());
$this->assertCount(1, $space->select([2016])->getData());
}
}
5 changes: 5 additions & 0 deletions tests/Integration/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ function create_fixtures()
for i = 1, 100 do
space:replace{i, i * 2 % 5, 'tuple_' .. i}
end

space = create_space('space_composite')
space:create_index('primary', {type = 'tree', unique = true, parts = {1, 'num', 2, 'num'}})
space:insert{2016, 10, 1}
space:insert{2016, 11, 0}
end

function func_foo()
Expand Down

0 comments on commit 63515cc

Please sign in to comment.