Skip to content

Commit

Permalink
Merge pull request #4 from Smolevich/replace-json-path-on-new-name
Browse files Browse the repository at this point in the history
Rename field json_path, add example
  • Loading branch information
Smolevich authored Jul 8, 2019
2 parents f23b658 + db4b1c7 commit d2b03e6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
3 changes: 2 additions & 1 deletion examples/01-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$configData = file_get_contents(__DIR__ . '/config.json');
$config = json_decode($configData, true);
$configuration = new Configuration($config);

$api = $configuration->getApi();
$databaseName = $argv[1] ?? 'test';
$namespaceName = $argv[2] ?? 'namespace';
Expand All @@ -35,7 +36,7 @@
->setIsPk(true)
->setIndexType(\Reindexer\Enum\IndexType::HASH)
->setFieldType('int')
->setJsonPath('id')
->setJsonPaths(['id'])
->setIsDense(true)
;
$response = $namespaceService->create($namespaceName, [$indexId]);
Expand Down
44 changes: 44 additions & 0 deletions examples/03-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/common-part.php';

use Reindexer\Services\Database;
use Reindexer\Services\Item;
use Reindexer\Services\Namespaces;
use Reindexer\Services\Query;

try {
$users = [
[
'id' => 1, 'name' => 'John Doe'
],
[
'id' => 2, 'name' => 'Tom Soyer'
],
[
'id' => 3, 'name' => 'James Bond'
]
];
$configData = file_get_contents(__DIR__ . '/config.json');
$config = json_decode($configData, true);
$configuration = new Configuration($config);

$api = $configuration->getApi();
$databaseName = $argv[1] ?? 'test';
$namespaceName = $argv[2] ?? 'namespace';

$itemService = new Item($api);
$sqlService = new Query($api);
$itemService->setNamespace($namespaceName);
$itemService->setDatabase($databaseName);
$sqlService->setDatabase($databaseName);

foreach ($users as $user) {
$response = $itemService->add($user);
}

$response = $sqlService->createByHttpGet('SELECT * from shupilkin_ns');
var_dump($response->getResponseBody());
} catch (Exception $e) {
}
12 changes: 6 additions & 6 deletions src/Reindexer/Entities/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Index extends Entity {
private $name;
private $jsonPath;
private $jsonPaths;
private $fieldType;
private $indexType;
private $isPk = true;
Expand All @@ -16,7 +16,7 @@ class Index extends Entity {

protected $mapJsonFields = [
'name' => 'name',
'jsonPath' => 'json_path',
'jsonPaths' => 'json_paths',
'fieldType' => 'field_type',
'indexType' => 'index_type',
'isPk' => 'is_pk',
Expand All @@ -37,12 +37,12 @@ public function setName(string $name) {
return $this;
}

public function getJsonPath(): string {
return $this->jsonPath ?? '';
public function getJsonPaths(): array {
return $this->jsonPaths ?? [];
}

public function setJsonPath(string $jsonPath): self {
$this->jsonPath = $jsonPath;
public function setJsonPaths(array $jsonPaths): self {
$this->jsonPaths = $jsonPaths;

return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Reindexer/Entities/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function testGetAndSetCollateMode() {
}

public function testGetAndSetJsonPath() {
$this->index->setJsonPath('json_path');
$this->assertEquals('json_path', $this->index->getJsonPath());
$this->index->setJsonPaths(['json_path']);
$this->assertEquals(['json_path'], $this->index->getJsonPaths());
}
public function testGetSetFieldType() {
$this->index->setFieldType(FieldType::DOUBLE);
Expand Down

0 comments on commit d2b03e6

Please sign in to comment.