diff --git a/docs/api/woqlclient.md b/docs/api/woqlclient.md index add28300..ff477157 100644 --- a/docs/api/woqlclient.md +++ b/docs/api/woqlclient.md @@ -748,8 +748,10 @@ const response1 = await client.addDocument(json, {"graph_type": "schema"}, ``` ## queryDocument -##### woqlClient.queryDocument(query, [params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ Promise -Retrieves all documents that match a given document template +##### ~~woqlClient.queryDocument(query, [params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ Promise~~ +***Deprecated*** + +Use [#getDocument](#getDocument) instead. **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. @@ -808,7 +810,7 @@ console.log(response); ``` ## getDocument -##### woqlClient.getDocument([params], [dbId], [branch], [lastDataVersion], [getDataVersion]) ⇒ Promise +##### woqlClient.getDocument([params], [dbId], [branch], [lastDataVersion], [getDataVersion], [query]) ⇒ Promise **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. @@ -819,6 +821,7 @@ and *dataVersion* object if ***getDataVersion*** parameter is true, or an Error | [branch] | string | the database branch | | [lastDataVersion] | string | the last data version tracking id. | | [getDataVersion] | boolean | If true the function will return object having result and dataVersion. | +| [query] | object | If a query object is provided, the function will use it to query the database. | **Example** ```javascript diff --git a/lib/woqlClient.js b/lib/woqlClient.js index c7ee3b34..8f9788b5 100644 --- a/lib/woqlClient.js +++ b/lib/woqlClient.js @@ -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 @@ -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 @@ -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); } @@ -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); };