Skip to content

Commit 1870caf

Browse files
deprecated query document (#187)
* - deprecated query document - refactored getDocument to have query as well Signed-off-by: NeelParihar <neel@terminusdb.com> * Apply docs changes * added docs for getDocument query Signed-off-by: NeelParihar <neel@terminusdb.com> * Apply docs changes Co-authored-by: Neelterminusdb <Neelterminusdb@users.noreply.github.com>
1 parent 0a262c2 commit 1870caf

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

docs/api/woqlclient.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,10 @@ const response1 = await client.addDocument(json, {"graph_type": "schema"},
748748
```
749749
750750
## queryDocument
751-
##### woqlClient.queryDocument(query, [params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
752-
Retrieves all documents that match a given document template
751+
##### ~~woqlClient.queryDocument(query, [params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>~~
752+
***Deprecated***
753+
754+
Use [#getDocument](#getDocument) instead.
753755
754756
**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
755757
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
@@ -808,7 +810,7 @@ console.log(response);
808810
```
809811
810812
## getDocument
811-
##### woqlClient.getDocument([params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ <code>Promise</code>
813+
##### woqlClient.getDocument([params], [dbId], [branch], [lastDataVersion], [getDataVersion], [query]) ⇒ <code>Promise</code>
812814
**Returns**: <code>Promise</code> - A promise that returns the call response object or object having *result*
813815
and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
814816
@@ -819,6 +821,7 @@ and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error
819821
| [branch] | <code>string</code> | the database branch |
820822
| [lastDataVersion] | <code>string</code> | the last data version tracking id. |
821823
| [getDataVersion] | <code>boolean</code> | If true the function will return object having result and dataVersion. |
824+
| [query] | <code>object</code> | If a query object is provided, the function will use it to query the database. |
822825
823826
**Example**
824827
```javascript

lib/woqlClient.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,9 @@ WOQLClient.prototype.addDocument = function (json, params, dbId, message = 'add
10121012
};
10131013

10141014
/**
1015+
* Use {@link #getDocument} instead.
1016+
* @deprecated
1017+
*
10151018
* Retrieves all documents that match a given document template
10161019
* @param {object} query - the query template
10171020
* @param {typedef.DocParamsGet} [params] - the get parameters
@@ -1092,6 +1095,8 @@ WOQLClient.prototype.queryDocument = function (query, params, dbId, branch, last
10921095
* @param {string} [lastDataVersion] the last data version tracking id.
10931096
* @param {boolean} [getDataVersion] If true the function will return object having result
10941097
* and dataVersion.
1098+
* @param {object} [query] If a query object is provided, the function will use it to
1099+
* query the database.
10951100
* @returns {Promise} A promise that returns the call response object or object having *result*
10961101
* and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error if rejected.
10971102
* @example
@@ -1128,7 +1133,7 @@ WOQLClient.prototype.queryDocument = function (query, params, dbId, branch, last
11281133
* )
11291134
*/
11301135
// document interface
1131-
WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersion = '', getDataVersion = false) {
1136+
WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersion = '', getDataVersion = false, query = undefined) {
11321137
if (dbId) {
11331138
this.db(dbId);
11341139
}
@@ -1138,6 +1143,16 @@ WOQLClient.prototype.getDocument = function (params, dbId, branch, lastDataVersi
11381143
if (typeof lastDataVersion === 'string' && lastDataVersion !== '') {
11391144
this.customHeaders({ 'TerminusDB-Data-Version': lastDataVersion });
11401145
}
1146+
1147+
if (query) {
1148+
return this.dispatch(
1149+
CONST.QUERY_DOCUMENT,
1150+
this.connectionConfig.documentURL(params),
1151+
query,
1152+
getDataVersion,
1153+
);
1154+
}
1155+
11411156
return this.dispatch(CONST.GET, this.connectionConfig.documentURL(params), {}, getDataVersion);
11421157
};
11431158

0 commit comments

Comments
 (0)