diff --git a/examples/01-example.php b/examples/01-example.php index 79be7a8..0c03279 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,7 +36,7 @@ ->setIsPk(true) ->setIndexType(\Reindexer\Enum\IndexType::HASH) ->setFieldType('int') - ->setJsonPath('id') + ->setJsonPaths(['id']) ->setIsDense(true) ; $response = $namespaceService->create($namespaceName, [$indexId]); diff --git a/examples/03-example.php b/examples/03-example.php new file mode 100644 index 0000000..4610e59 --- /dev/null +++ b/examples/03-example.php @@ -0,0 +1,44 @@ + 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) { +} diff --git a/src/Reindexer/Entities/Index.php b/src/Reindexer/Entities/Index.php index 6bff724..11d55d4 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 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; } 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);