Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add document:upsert #56

Merged
merged 6 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions doc/2/controllers/document/upsert/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Applies partial changes to a document. If the document doesn't already exist, a
String index,
String collection,
String id,
Map<String, dynamic> body, {
Map<String, dynamic> changes, {
bool waitForRefresh = false,
int retryOnConflict,
bool source,
Expand All @@ -29,22 +29,15 @@ Applies partial changes to a document. If the document doesn't already exist, a
| `index` | <pre>String</pre> | Index name |
| `collection` | <pre>String</pre> | Collection name |
| `id` | <pre>String</pre> | Document ID |
| `body` | <pre>Map<String, dynamic></pre> | Partial content of the document to update and fields to add to the document if it gets created |

### Body properties


| Argument | Type<br/>(default) | Description |
| ----------------- | ------------------------------- | ---------------------------------------------------------------------------------- |
| `changes` | <pre>Map<String, dynamic></pre> | partial changes to apply to the document |
| `defaults` | <pre>Map<String, dynamic></pre><br/>(`{}`) | (optional) fields to add to the document if it gets created |
| `changes` | <pre>Map<String, dynamic></pre> | Partial content of the document to update |

### Options

Additional query options

| Options | Type<br/>(default) | Description |
| ----------------- | ------------------------------- | ---------------------------------------------------------------------------------- |
| `defaults` | <pre>Map<String, dynamic></pre><br/>(`{}`) | (optional) fields to add to the document if it gets created |
| `waitForRefresh` | <pre>bool</pre><br/>(`""`) | If set to `true`, waits for the change to be reflected for `search` (up to 1s) |
| `retryOnConflict` | <pre>int</pre><br/>(`10`) | The number of times the database layer should retry in case of version conflict |
| `source` | <pre>bool</pre><br/>(`false`)| If true, returns the updated document inside the response
Expand Down
15 changes: 9 additions & 6 deletions lib/src/controllers/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class DocumentController extends KuzzleController {
///
/// Optional
///
/// **[refresh]**: if set to wait_for, Kuzzle will not respond
/// **[waitForRefresh]**: if set to wait_for, Kuzzle will not respond
/// until the update is indexed \\\
/// **[retryOnConflict]**: conflicts may occur if the same document gets updated multiple times within a short timespan, in a database cluster. You can set the retryOnConflict optional argument (with a retry count), to tell Kuzzle to retry the failing updates the specified amount of times before rejecting the request with an error. \\\
/// **[source]**: if set to true Kuzzle will return the updated document body in the response \\\
Expand Down Expand Up @@ -419,22 +419,24 @@ class DocumentController extends KuzzleController {
///
/// **[index]**: index name \\\
/// **[collection]**: collection name \\\
/// **[uid]**: unique identifier of the document to update \\\
/// **[body]**: Partial changes to apply to the document
/// **[id]**: unique identifier of the document to update \\\
/// **[changes]**: Partial changes to apply to the document
/// and Fields to add to the document if it gets created (optional)
Yoann-Abbes marked this conversation as resolved.
Show resolved Hide resolved

///
/// Optional
///
/// **[refresh]**: if set to wait_for, Kuzzle will not respond
/// **[defaults]**: Fields to add to the document if it gets created
/// **[waitForRefresh]**: if set to wait_for, Kuzzle will not respond
/// until the update is indexed \\\
/// **[retryOnConflict]**: conflicts may occur if the same document gets updated multiple times within a short timespan, in a database cluster. You can set the retryOnConflict optional argument (with a retry count), to tell Kuzzle to retry the failing updates the specified amount of times before rejecting the request with an error. \\\
/// **[source]**: if set to true Kuzzle will return the updated document body in the response \\\
Future<Map<String, dynamic>> upsert(
String index,
String collection,
String id,
Map<String, dynamic> body, {
Map<String, dynamic> changes, {
Map<String, dynamic> defaults,
bool waitForRefresh = false,
int retryOnConflict,
bool source,
Expand All @@ -445,7 +447,8 @@ class DocumentController extends KuzzleController {
index: index,
collection: collection,
uid: id,
body: body,
body: changes,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The body contains both changes and defaults

defaults: defaults,
waitForRefresh: waitForRefresh,
source: source,
retryOnConflict: retryOnConflict,
Expand Down
8 changes: 7 additions & 1 deletion lib/src/kuzzle/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class KuzzleRequest {
this.scope,
this.state,
this.source,
this.defaults,
this.userId,
this.users,
this.verb,
Expand Down Expand Up @@ -67,6 +68,7 @@ class KuzzleRequest {
users = request.users;
verb = request.verb;
source = request.source;
defaults = request.defaults;
includeKuzzleMeta = request.includeKuzzleMeta;
}

Expand Down Expand Up @@ -105,6 +107,7 @@ class KuzzleRequest {
users = data['users'] as String;
verb = data['verb'] as String;
source = data['source'] as bool;
defaults = data['defaults'] as Map<String, dynamic>;
includeKuzzleMeta = data['includeKuzzleMeta'] as bool;
}

Expand Down Expand Up @@ -200,7 +203,9 @@ class KuzzleRequest {
if (source != null) {
map['source'] = source;
}

if (defaults != null) {
map['defaults'] = defaults;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to understand what this is suppose to do but defaults is part of the body and it looks like you put it in the arguments

}
if (includeKuzzleMeta != null) {
map['includeKuzzleMeta'] = includeKuzzleMeta;
}
Expand Down Expand Up @@ -235,6 +240,7 @@ class KuzzleRequest {
int retryOnConflict;
bool reset;
bool source;
Map<String, dynamic> defaults;
String scope;
String state;
String userId;
Expand Down