Skip to content

Commit

Permalink
Fix replaceByExample/updateByExample
Browse files Browse the repository at this point in the history
  • Loading branch information
pluma committed Sep 25, 2020
1 parent 2d4f47d commit 4d7e5ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -22,6 +22,12 @@ This driver uses semantic versioning:

- Fixed empty query results containing `[undefined]` ([#687](https://github.com/arangodb/arangojs/issues/683))

- Fixed `updateByExample` and `replaceByExample` new value parameter name

Note that these methods are still deprecated. Previously the `newValue`
parameter was incorrectly called `newData`, which prevented the methods from
working at all.

## [7.0.1] - 2020-08-21

This is a maintenance release because the initial v7 release did not include
Expand Down
26 changes: 13 additions & 13 deletions src/collection.ts
Expand Up @@ -2175,7 +2175,7 @@ export interface DocumentCollection<T extends object = any>
* Replaces all documents in the collection matching the given example.
*
* @param example - An object representing an example for the documents.
* @param newData - Document data to replace the matching documents with.
* @param newValue - Document data to replace the matching documents with.
* @param options - Options for replacing the documents.
*
* @deprecated Simple Queries have been deprecated in ArangoDB 3.4 and can be
Expand All @@ -2185,16 +2185,16 @@ export interface DocumentCollection<T extends object = any>
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* const newData = { flavor: "chocolate" };
* const newValue = { flavor: "chocolate" };
* // const { replaced } = await collection.replaceByExample(
* // { flavor: "strawberry" },
* // newData
* // newValue
* // );
* const cursor = await db.query(aql`
* RETURN LENGTH(
* FOR doc IN ${collection}
* FILTER doc.flavor == "strawberry"
* REPLACE doc WITH ${newData} IN ${collection}
* REPLACE doc WITH ${newValue} IN ${collection}
* RETURN 1
* )
* `);
Expand All @@ -2203,15 +2203,15 @@ export interface DocumentCollection<T extends object = any>
*/
replaceByExample(
example: Partial<DocumentData<T>>,
newData: DocumentData<T>,
newValue: DocumentData<T>,
options?: SimpleQueryReplaceByExampleOptions
): Promise<ArangoResponseMetadata & SimpleQueryReplaceByExampleResult>;

/**
* Updates all documents in the collection matching the given example.
*
* @param example - An object representing an example for the documents.
* @param newData - Document data to update the matching documents with.
* @param newValue - Document data to update the matching documents with.
* @param options - Options for updating the documents.
*
* @deprecated Simple Queries have been deprecated in ArangoDB 3.4 and can be
Expand All @@ -2224,13 +2224,13 @@ export interface DocumentCollection<T extends object = any>
* const newData = { color: "red" };
* // const { updated } = await collection.updateByExample(
* // { flavor: "strawberry" },
* // newData
* // newValue
* // );
* const cursor = await db.query(aql`
* RETURN LENGTH(
* FOR doc IN ${collection}
* FILTER doc.flavor == "strawberry"
* UPDATE doc WITH ${newData} IN ${collection}
* UPDATE doc WITH ${newValue} IN ${collection}
* RETURN 1
* )
* `);
Expand All @@ -2239,7 +2239,7 @@ export interface DocumentCollection<T extends object = any>
*/
updateByExample(
example: Partial<DocumentData<T>>,
newData: Patch<DocumentData<T>>,
newValue: Patch<DocumentData<T>>,
options?: SimpleQueryUpdateByExampleOptions
): Promise<ArangoResponseMetadata & SimpleQueryUpdateByExampleResult>;

Expand Down Expand Up @@ -3756,7 +3756,7 @@ export class Collection<T extends object = any>

replaceByExample(
example: Partial<DocumentData<T>>,
newData: DocumentData<T>,
newValue: DocumentData<T>,
options?: SimpleQueryReplaceByExampleOptions
) {
return this._db.request(
Expand All @@ -3766,7 +3766,7 @@ export class Collection<T extends object = any>
body: {
...options,
example,
newData,
newValue,
collection: this._name,
},
},
Expand All @@ -3776,7 +3776,7 @@ export class Collection<T extends object = any>

updateByExample(
example: Partial<DocumentData<T>>,
newData: Patch<DocumentData<T>>,
newValue: Patch<DocumentData<T>>,
options?: SimpleQueryUpdateByExampleOptions
) {
return this._db.request(
Expand All @@ -3786,7 +3786,7 @@ export class Collection<T extends object = any>
body: {
...options,
example,
newData,
newValue,
collection: this._name,
},
},
Expand Down

0 comments on commit 4d7e5ef

Please sign in to comment.