-
Notifications
You must be signed in to change notification settings - Fork 68
Add method bulkGet #91
base: master
Are you sure you want to change the base?
Changes from all commits
8ce1f13
d7d8c6d
e4918e8
41957d6
4e5a854
1e9e97c
79233f4
295ca0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -807,6 +807,33 @@ public function ensureFullCommit() | |||||
throw HTTPException::fromResponse($path, $response); | ||||||
} | ||||||
|
||||||
return $response->body; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Bulk get. | ||||||
* | ||||||
* @param array<int, array<string, string>> $docs | ||||||
* | ||||||
* @throws HTTPException | ||||||
* | ||||||
* @return array | ||||||
*/ | ||||||
public function bulkGet(array $docs = []) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a return type declaration here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this return type is too complex for method documentation. We can add a link to method's official documentation http://docs.couchdb.org/en/2.2.0/api/database/bulk-api.html#db-bulk-get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it return other PHP types than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was suggesting this
Suggested change
|
||||||
{ | ||||||
$path = '/'.$this->databaseName.'/_bulk_get'; | ||||||
|
||||||
$response = $this->httpClient->request( | ||||||
'POST', | ||||||
'/'.$this->databaseName.'/_bulk_get', | ||||||
json_encode(['docs' => $docs]) | ||||||
); | ||||||
|
||||||
if ($response->status != 200) { | ||||||
throw HTTPException::fromResponse($path, $response); | ||||||
} | ||||||
|
||||||
|
||||||
return $response->body; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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(): void | ||||||
{ | ||||||
$client = $this->couchClient; | ||||||
|
||||||
|
||||||
$docs = []; | ||||||
$expectedRows = []; | ||||||
foreach (range(1, 3) as $i) { | ||||||
list($id, $rev) = $client->postDocument(['foo' => 'bar'.$i]); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The composer constraint is currently |
||||||
$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); | ||||||
} | ||||||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The body of the response is an array? What type are the elements in the array exactly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As described on www.com.behttps://docs.couchdb.org/en/stable/api/database/bulk-api.html#db-bulk-get
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your link is broken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.couchdb.org/en/stable/api/database/bulk-api.html#db-bulk-get
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok so it should also be
correct?