From 8ce1f13c1b5a1fe2de1d9c26121e04e27112729c Mon Sep 17 00:00:00 2001 From: Sidney Correia Date: Mon, 27 Jan 2020 06:09:45 -0300 Subject: [PATCH 1/8] add method bulkGet references _bulk_get --- lib/Doctrine/CouchDB/CouchDBClient.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/Doctrine/CouchDB/CouchDBClient.php b/lib/Doctrine/CouchDB/CouchDBClient.php index 17b094f..c1123fe 100644 --- a/lib/Doctrine/CouchDB/CouchDBClient.php +++ b/lib/Doctrine/CouchDB/CouchDBClient.php @@ -807,6 +807,29 @@ public function ensureFullCommit() throw HTTPException::fromResponse($path, $response); } + return $response->body; + } + + /** + * Get changes. + * + * @param array $params + * + * @throws HTTPException + * + * @return array + */ + public function bulkGet(array $docs = []) + { + $path = '/'.$this->databaseName.'/_bulk_get'; + + $response = $this->httpClient->request('POST', $path, json_encode(['docs' => $docs])); + + if ($response->status != 200) { + throw HTTPException::fromResponse($path, $response); + } + + return $response->body; } } From d7d8c6d2edc1f02c3f9bd225e356133f1ce10f69 Mon Sep 17 00:00:00 2001 From: Sidney Correia Date: Mon, 27 Jan 2020 06:31:43 -0300 Subject: [PATCH 2/8] Description bulkGet method --- lib/Doctrine/CouchDB/CouchDBClient.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/CouchDB/CouchDBClient.php b/lib/Doctrine/CouchDB/CouchDBClient.php index c1123fe..f4a172a 100644 --- a/lib/Doctrine/CouchDB/CouchDBClient.php +++ b/lib/Doctrine/CouchDB/CouchDBClient.php @@ -811,9 +811,9 @@ public function ensureFullCommit() } /** - * Get changes. + * Bulk get. * - * @param array $params + * @param array $docs * * @throws HTTPException * From e4918e8a8081e0f34ed26ac3cd6a63f301f3e9af Mon Sep 17 00:00:00 2001 From: Sidney Correia Date: Tue, 28 Jan 2020 01:40:45 -0300 Subject: [PATCH 3/8] Code formatting suggestion accepted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Grégoire Paris --- lib/Doctrine/CouchDB/CouchDBClient.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/CouchDB/CouchDBClient.php b/lib/Doctrine/CouchDB/CouchDBClient.php index f4a172a..d62382d 100644 --- a/lib/Doctrine/CouchDB/CouchDBClient.php +++ b/lib/Doctrine/CouchDB/CouchDBClient.php @@ -823,7 +823,11 @@ public function bulkGet(array $docs = []) { $path = '/'.$this->databaseName.'/_bulk_get'; - $response = $this->httpClient->request('POST', $path, json_encode(['docs' => $docs])); + $response = $this->httpClient->request( + 'POST', + '/'.$this->databaseName.'/_bulk_get', + json_encode(['docs' => $docs]) + ); if ($response->status != 200) { throw HTTPException::fromResponse($path, $response); From 41957d69d289853c999ca39e77c3485454885493 Mon Sep 17 00:00:00 2001 From: Sidney Correia Date: Tue, 28 Jan 2020 02:05:46 -0300 Subject: [PATCH 4/8] Mudando nome do projeto --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9eb79eb..7df6d59 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "doctrine/couchdb", + "name": "sidneycorreia/couchdb", "type": "library", "description": "CouchDB Client", "keywords": ["persistence", "couchdb"], From 4e5a85476e8e001accfcacd54b9a268dff86a816 Mon Sep 17 00:00:00 2001 From: Sidney Correia Date: Tue, 28 Jan 2020 02:33:19 -0300 Subject: [PATCH 5/8] Mudando nome do projeto --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7df6d59..9eb79eb 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "sidneycorreia/couchdb", + "name": "doctrine/couchdb", "type": "library", "description": "CouchDB Client", "keywords": ["persistence", "couchdb"], From 1e9e97cc97f041dae7f70f0c322154a5fe90d937 Mon Sep 17 00:00:00 2001 From: Sidney Correia Date: Tue, 28 Jan 2020 04:07:41 -0300 Subject: [PATCH 6/8] Add testBulkGet and fix testFindDocuments --- .../CouchDB/Functional/CouchDBClientTest.php | 62 +++++++++++++++++-- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php b/tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php index 1dd7db6..e2bc302 100644 --- a/tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php +++ b/tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php @@ -393,20 +393,21 @@ public function testFindDocuments() } $response = $client->findDocuments($ids); - - $this->assertEquals(['total_rows' => 3, 'rows' => $expectedRows], $response->body); + // print_r(['total_rows' => 3, 'offset' => null, 'rows' => $expectedRows]); + // print_r($response->body); + $this->assertEquals(['total_rows' => 3, 'offset' => null, 'rows' => $expectedRows], $response->body); $response = $client->findDocuments($ids, 0); - $this->assertEquals(['total_rows' => 3, 'rows' => $expectedRows], $response->body); + $this->assertEquals(['total_rows' => 3, 'offset' => null, 'rows' => $expectedRows], $response->body); $response = $client->findDocuments($ids, 1); - $this->assertEquals(['total_rows' => 3, 'rows' => [$expectedRows[0]]], $response->body); + $this->assertEquals(['total_rows' => 3, 'offset' => null, 'rows' => [$expectedRows[0]]], $response->body); $response = $client->findDocuments($ids, 0, 2); - $this->assertEquals(['total_rows' => 3, 'rows' => [$expectedRows[2]]], $response->body); + $this->assertEquals(['total_rows' => 3, 'offset' => null, 'rows' => [$expectedRows[2]]], $response->body); $response = $client->findDocuments($ids, 1, 1); - $this->assertEquals(['total_rows' => 3, 'rows' => [$expectedRows[1]]], $response->body); + $this->assertEquals(['total_rows' => 3, 'offset' => null, 'rows' => [$expectedRows[1]]], $response->body); } public function testAllDocs() @@ -683,4 +684,53 @@ public function testEncodeQueryParamsCorrectly() $this->assertEquals(0, $result->getTotalRows()); } + + + public function testBulkGet() + { + $client = $this->couchClient; + + + $docs = []; + $expectedRows = []; + foreach (range(1, 3) as $i) { + list($id, $rev) = $client->postDocument(['foo' => 'bar'.$i]); + $docs[] = [ + 'id' => $id, + 'rev' => $rev + ]; + + $ids[] = $id; + + $expectedRows[] = [ + 'id' => $id, + 'docs' => [ + ['ok' => [ + '_id' => $id, + '_rev' => $rev, + 'foo' => 'bar'.$i, + ]] + ] + ]; + } + + + $bulkGet = $client->bulkGet($docs); + $this->assertEquals(['results' => $expectedRows], $bulkGet); + + $bulkGetNonexistent = $client->bulkGet([['id' => 'nonexistent-id']]); + $expectedRowsWhenNonexistent[] = [ + 'id' => 'nonexistent-id', + 'docs' => [ + ['error' => [ + 'id' => 'nonexistent-id', + 'rev' => 'undefined', + 'error' => 'not_found', + 'reason' => 'missing', + ]] + ] + ]; + + $this->assertEquals(['results' => $expectedRowsWhenNonexistent], $bulkGetNonexistent); + } } From 79233f40c84ba6b068f9c6c5ec1497f48a1e0585 Mon Sep 17 00:00:00 2001 From: Sidney Correia Date: Tue, 28 Jan 2020 04:27:05 -0300 Subject: [PATCH 7/8] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Grégoire Paris --- lib/Doctrine/CouchDB/CouchDBClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/CouchDB/CouchDBClient.php b/lib/Doctrine/CouchDB/CouchDBClient.php index d62382d..933ca00 100644 --- a/lib/Doctrine/CouchDB/CouchDBClient.php +++ b/lib/Doctrine/CouchDB/CouchDBClient.php @@ -813,7 +813,7 @@ public function ensureFullCommit() /** * Bulk get. * - * @param array $docs + * @param array> $docs * * @throws HTTPException * From 295ca0a45990816c78a8232625a3f0069792bbac Mon Sep 17 00:00:00 2001 From: Sidney Correia Date: Tue, 28 Jan 2020 09:14:41 -0300 Subject: [PATCH 8/8] Update tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Grégoire Paris --- tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php b/tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php index e2bc302..5322c7a 100644 --- a/tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php +++ b/tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php @@ -686,7 +686,7 @@ public function testEncodeQueryParamsCorrectly() } - public function testBulkGet() + public function testBulkGet(): void { $client = $this->couchClient;