Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 6 additions & 3 deletions docs/api/woqlclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,10 @@ const response1 = await client.addDocument(json, {"graph_type": "schema"},
```

## queryDocument
##### woqlClient.queryDocument(query, [params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
Retrieves all documents that match a given document template
##### ~~woqlClient.queryDocument(query, [params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>~~
***Deprecated***

Use [#getDocument](#getDocument) instead.

**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
Expand Down Expand Up @@ -808,7 +810,7 @@ console.log(response);
```

## getDocument
##### woqlClient.getDocument([params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
##### woqlClient.getDocument([params], [dbId], [branch], [lastDataVersion], [getDataVersion], [query]) ⇒ <code>Promise</code>
**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.

Expand All @@ -819,6 +821,7 @@ and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error
| [branch] | <code>string</code> | the database branch |
| [lastDataVersion] | <code>string</code> | the last data version tracking id. |
| [getDataVersion] | <code>boolean</code> | If true the function will return object having result and dataVersion. |
| [query] | <code>object</code> | If a query object is provided, the function will use it to query the database. |

**Example**
```javascript
Expand Down
17 changes: 16 additions & 1 deletion lib/woqlClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,9 @@ WOQLClient.prototype.addDocument = function (json, params, dbId, message = 'add
};

/**
* Use {@link #getDocument} instead.
* @deprecated
*
* Retrieves all documents that match a given document template
* @param {object} query - the query template
* @param {typedef.DocParamsGet} [params] - the get parameters
Expand Down Expand Up @@ -1092,6 +1095,8 @@ WOQLClient.prototype.queryDocument = function (query, params, dbId, branch, last
* @param {string} [lastDataVersion] the last data version tracking id.
* @param {boolean} [getDataVersion] If true the function will return object having result
* and dataVersion.
* @param {object} [query] If a query object is provided, the function will use it to
* query the database.
* @returns {Promise} A promise that returns the call response object or object having *result*
* and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
* @example
Expand Down Expand Up @@ -1128,7 +1133,7 @@ WOQLClient.prototype.queryDocument = function (query, params, dbId, branch, last
* )
*/
// document interface
WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersion = '', getDataVersion = false) {
WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersion = '', getDataVersion = false, query = undefined) {
if (dbId) {
this.db(dbId);
}
Expand All @@ -1138,6 +1143,16 @@ WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersi
if (typeof lastDataVersion === 'string' && lastDataVersion !== '') {
this.customHeaders({ 'TerminusDB-Data-Version': lastDataVersion });
}

if (query) {
return this.dispatch(
CONST.QUERY_DOCUMENT,
this.connectionConfig.documentURL(params),
query,
getDataVersion,
);
}

return this.dispatch(CONST.GET, this.connectionConfig.documentURL(params), {}, getDataVersion);
};

Expand Down