From 81b20efd45ec650bf9d445d637c8022a9ee7f0ca Mon Sep 17 00:00:00 2001 From: MacBook Date: Mon, 8 Jul 2019 09:54:54 +0300 Subject: [PATCH 1/3] Rename field json_path, add example --- examples/01-example.php | 4 ++- examples/03-example.php | 45 ++++++++++++++++++++++++++++++++ src/Reindexer/Entities/Index.php | 12 ++++----- 3 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 examples/03-example.php diff --git a/examples/01-example.php b/examples/01-example.php index 79be7a8..0644dea 100644 --- a/examples/01-example.php +++ b/examples/01-example.php @@ -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'; @@ -35,12 +36,13 @@ ->setIsPk(true) ->setIndexType(\Reindexer\Enum\IndexType::HASH) ->setFieldType('int') - ->setJsonPath('id') + ->setJsonPaths(['id']) ->setIsDense(true) ; $response = $namespaceService->create($namespaceName, [$indexId]); echo sprintf('Response data: %s', $response->getResponseBody()) . PHP_EOL; } + } catch (Exception $e) { echo sprintf( 'Error %s in file %s on line %s', diff --git a/examples/03-example.php b/examples/03-example.php new file mode 100644 index 0000000..60782fe --- /dev/null +++ b/examples/03-example.php @@ -0,0 +1,45 @@ + 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) { + +} \ No newline at end of file diff --git a/src/Reindexer/Entities/Index.php b/src/Reindexer/Entities/Index.php index 6bff724..7d5c1eb 100644 --- a/src/Reindexer/Entities/Index.php +++ b/src/Reindexer/Entities/Index.php @@ -4,7 +4,7 @@ class Index extends Entity { private $name; - private $jsonPath; + private $jsonPaths; private $fieldType; private $indexType; private $isPk = true; @@ -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', @@ -37,12 +37,12 @@ public function setName(string $name) { return $this; } - public function getJsonPath(): string { - return $this->jsonPath ?? ''; + public function getJsonPath(): array { + return $this->jsonPaths ?? []; } - public function setJsonPath(string $jsonPath): self { - $this->jsonPath = $jsonPath; + public function setJsonPaths(array $jsonPaths): self { + $this->jsonPaths = $jsonPaths; return $this; } From 1730df4d2a81e1c10e02f0d967a5ef6d444b0d2b Mon Sep 17 00:00:00 2001 From: MacBook Date: Mon, 8 Jul 2019 10:03:33 +0300 Subject: [PATCH 2/3] FIx examples --- examples/01-example.php | 1 - examples/03-example.php | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/01-example.php b/examples/01-example.php index 0644dea..0c03279 100644 --- a/examples/01-example.php +++ b/examples/01-example.php @@ -42,7 +42,6 @@ $response = $namespaceService->create($namespaceName, [$indexId]); echo sprintf('Response data: %s', $response->getResponseBody()) . PHP_EOL; } - } catch (Exception $e) { echo sprintf( 'Error %s in file %s on line %s', diff --git a/examples/03-example.php b/examples/03-example.php index 60782fe..4610e59 100644 --- a/examples/03-example.php +++ b/examples/03-example.php @@ -4,8 +4,8 @@ require_once __DIR__ . '/common-part.php'; use Reindexer\Services\Database; -use Reindexer\Services\Namespaces; use Reindexer\Services\Item; +use Reindexer\Services\Namespaces; use Reindexer\Services\Query; try { @@ -34,12 +34,11 @@ $itemService->setDatabase($databaseName); $sqlService->setDatabase($databaseName); - foreach($users as $user) { + foreach ($users as $user) { $response = $itemService->add($user); } $response = $sqlService->createByHttpGet('SELECT * from shupilkin_ns'); var_dump($response->getResponseBody()); } catch (Exception $e) { - -} \ No newline at end of file +} From db4b1c7e258c06a249078273f3b3e446cf29c7f0 Mon Sep 17 00:00:00 2001 From: MacBook Date: Mon, 8 Jul 2019 10:15:10 +0300 Subject: [PATCH 3/3] Fix errors in tests --- src/Reindexer/Entities/Index.php | 2 +- tests/Reindexer/Entities/IndexTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Reindexer/Entities/Index.php b/src/Reindexer/Entities/Index.php index 7d5c1eb..11d55d4 100644 --- a/src/Reindexer/Entities/Index.php +++ b/src/Reindexer/Entities/Index.php @@ -37,7 +37,7 @@ public function setName(string $name) { return $this; } - public function getJsonPath(): array { + public function getJsonPaths(): array { return $this->jsonPaths ?? []; } diff --git a/tests/Reindexer/Entities/IndexTest.php b/tests/Reindexer/Entities/IndexTest.php index 87b8344..3c5af26 100644 --- a/tests/Reindexer/Entities/IndexTest.php +++ b/tests/Reindexer/Entities/IndexTest.php @@ -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);