Skip to content

Commit

Permalink
Merge pull request #30 from Smolevich/29-issue-add-put-method
Browse files Browse the repository at this point in the history
29 issue add put method
  • Loading branch information
Smolevich authored Dec 23, 2022
2 parents 0d53e5a + e839778 commit 90cc84d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Reindexer/Services/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Reindexer\BaseService;

class Query extends BaseService {
public $database;
public string $database;

public function getDatabase(): string {
return $this->database ?? '';
Expand All @@ -26,6 +26,17 @@ public function createByHttpGet(string $query) {
);
}

public function createByHttpPut(mixed $query) {
$uri = sprintf('/api/%s/db/%s/query', $this->version, $this->getDatabase());

return $this->client->request(
'PUT',
$uri,
json_encode($query),
$this->defaultHeaders
);
}

public function createSqlQueryByHttpPost(string $query) {
$uri = sprintf('/api/%s/db/%s/sqlquery', $this->version, $this->getDatabase());

Expand Down
28 changes: 28 additions & 0 deletions tests/Feature/Reindexer/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,33 @@ public function testQuery() {
->getDecodedResponseBody(true);

$this->assertEquals(3, count($response['items']));

$response = $this->queryService
->createByHttpPut([
'namespace' => $this->namespaceName,
'type' => 'update',
'filters' => [
[
'field' => 'user_nickname',
'cond' => 'EQ',
'value' => 'LMonoceros',
]
],
'update_fields' => [
[
'name' => 'user_nickname',
'type' => 'value',
'values' => ['LMonoceros new']
]
]
])
->getDecodedResponseBody(true);

$this->assertEquals(2, $response['updated']);

$response = $this->queryService
->createByHttpGet("SELECT * FROM {$this->namespaceName} WHERE user_nickname = 'LMonoceros'")
->getDecodedResponseBody(true);
$this->assertEquals(0, count($response['items']));
}
}

0 comments on commit 90cc84d

Please sign in to comment.